Skip to content
Related Articles

Related Articles

Working Storage Section in COBOL

View Discussion
Improve Article
Save Article
  • Last Updated : 22 Sep, 2021
View Discussion
Improve Article
Save Article

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.

  • WORKING-STORAGE SECTION is declared under the DATA DIVISION in COBOL structure.
  • It must be declared with the heading WORKING-STORAGE SECTION with a separator period(.).
  • It is one of the most important sections in Cobol programming because we declare all the variables and file structures, their types, size, etc in this section.
  • The variables declared in the section can be assigned values at the time of declaration as well as during the flow of the program.
  • We use level 77 to declare elementary variables and level 01 to 49 for grouped variables.
  • In this section, we also define the record description entries which are not part of the record but are used to write records into the file.
  • The memory is allocated to all the variables and file structures declared in WORKING-STORAGE SECTION at the time of execution of the program and is deallocated as soon as the program ends.
  • The variables declared within this section can only be used inside the program and not outside the program.

Syntax:

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

Example:

Cobol




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. 

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!