Open In App

Working Storage Section in COBOL

Cobol is a high-level language, which has its own compiler. The COBOL compiler translates the COBOL program into an object program, which is finally executed. 

To execute the COBOL program without any error, these divisions must be written in the order in which they are specified below:



1. Identification Division:

 In this division, we write the details about the program like author name, date of execution, date of writing the code, etc.

Syntax:



IDENTIFICATION DIVISION.
PROGRAM-ID. Entry
[AUTHOR. Entry].
[INSTALLATION Entry].
[DATE-WRITTEN. Entry].
[DATA-COMPILED. Entry].
[SECURITY. Entry.
[REMARKS. Entry.]

2. Environment Division:

 In this division, we write the details about the computer environment in which the program has been written and executed.

Syntax:

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. Source-computer-entry.
OBJECT-COMPUTER. Object-computer-entry.
[SPECIAL NAMES. Special-computer-entry.]
INPUT-OUTPUT SECTION.
FILE CONTROL. File-control-entry.
[I-O CONTROL. Input-output-control-entry].

3. Data Division:

In this division, we declare the variables, their data type, size, usage type, etc. which are to be used in the program. It is the most important division in the COBOL program structure.

Syntax:

DATA DIVISION.
FILE SECTION. File-section-entry.
WORKING-STORAGE SECTION. Variables.
LINKAGE SECTION.[Linkage-section-entry].
REPORT SECTION.

4. Procedure Division :  

In this division, the executable COBOL statements, i.e. the main program code is written. It must contain at least one statement. To stop the execution of the program we write STOP (in case of calling program) or EXIT (in case of called program).

Syntax:

PROCEDURE DIVISION[USING DATA-NAME1[,DATA-NAME2,...]]. 

WORKING-STORAGE SECTION.

Syntax:

DATA DIVISION.
WORKING-STORAGE SECTION.
Record-description-entries.
Variable-description-entries.

Example:




IDENTIFICATION DIVISION.
PROGRAM-ID. HELLOWORD.
ENVIRONMENT DIVISION.
DATA DIVISION.
      WORKING-STORAGE SECTION.
      77 VARIABLE1 PIC 99.
      77 VARIABLE2 PIC A.
      01 GROUPEDATA.
          02 GROUPVAR1 PIC 99.
          02 GROUPVAR2 PIC A(5).
PROCEDURE DIVISION.
DISPLAY "WELCOME To GEEKSFORGEEKS".
STOP RUN.

Output:

WELCOME To GEEKSFORGEEKS

Explanation:

In the above-given example code, we have shown the declaration of variables in the WORKING-STORAGE SECTION. VARIABLE1 and VARIABLE2 are the Elementary data with integer data type and character data type respectively and GROUPEDATA is the Grouped data with level 01 and 02. Grouped data are used to declare structures like arrays. Now observe clearly, we have written WORKING-STORAGE SECTION with a separator period, under DATA DIVISION. 

Article Tags :