Javatpoint Logo
Javatpoint Logo

COBOL - Divisions

  • A COBOL division is a block of code. It is a collection of sections, sentences, or a block of statements.
  • The starting line of division is the division name, and the end line of division is the beginning of the next division or the end of the program.
  • Divisions are System-defined words.
  • All divisions should be in Area A.

There are four divisions in COBOL:

  • Identification Division
  • Environment Division
  • Data Division
  • Procedure Division

Identification Division

The Identification division is the beginning of the COBOL program, and this is the mandatory section in every COBOL program. This division is used by the compiler and programmer to identify the program.

In this section, we can define the other optional details. Like Author name, Date of writing the code, date of last compiled code, and other security details as per your requirements.

You must define the PROGRAM-ID (a keyword) immediately after the Identification division.

Syntax:

Example:

Output:

When you compile and execute the above program, it will display the following output:

COBOL Divisions

Environment Division

In the Environment division section of the program, we can define the input and output files. This section is optional. This division is usually used to describe the system's environment in which the program will run.

Syntax:

It consists of two sections:

1. Configuration Section

The configuration section contains the information about your system on which your program is written and executed. This section must be specified in Area A.

It consists of two paragraphs:

  • Source Computer: This will contain information about the system in which your program is compiled.
  • Object Computer: This will contain information about the system in which your program is executed.

Syntax:

Input-Output Section

This Input-Output section contains information about all the files to be used in your COBOL program.

  • File Control: This will show the external data set's information used in the program.
  • I-O control: This will show the file's information used in the program.

Syntax:

Example:

Let's see one simple example for Environment section:

Output:

COBOL Divisions

DATA DIVISION

Data division contains information about the variables and data items used in the program. It defines the variable names, their lengths, decimal locations, and the information about the storage formats.

File Section: The file section specifies the details of the records used in the file. It will show the whole record structure of the file.

Syntax:

  • Working-Storage Section: This section specifies all the temporary variables and also the file structures that are used in the program.

Syntax:

  • Local-Storage Section: Local-storage section stores similar information as the working-storage section. The only difference is that in the case of the Local-Storage Section, the variables will be allocated and initialized every time a program starts execution.
  • Linkage Section: This section describes all the data items received from an external program.

Syntax:

Example:

Let's see one simple example for Data Division:

Output:

COBOL Divisions

Procedure Division

  • The procedure division is the main section of the COBOL program. Like the main() function of C/C++ program. From the procedure, division section program will actually start the execution.
  • This section is the logical section of the program. Here all the business logic is written. Like C/C++ main() function, all COBOL programs must have a procedure division.
  • The procedure division contains executable statements, and executable statements contain variables defined in the data division. We can use the user-defined names and paragraphs in the procedure division.
  • We must specify at least one statement in this division. We cannot leave it empty.
  • The procedure division ends with EXIT PROGRAM, which is used in the called programs or STOP RUN, which is used in the calling programs.
  • The Procedure division begins in Area A.

Syntax:

Example:

Let's see the example for Procedure Division:

Output:

COBOL Divisions
Next TopicCOBOL Data Types




Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA