Working Storage Section in COBOL
Last Updated :
22 Sep, 2021
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.
Similar Reads
String Handling in COBOL The string is the data type, used to represent the sequence of characters, which ends with /0. String provides much functionality which makes our programming easy when it comes to groups of chars, words, sentences, or lines. String Handling:  String handling is the process or method to handle the s
7 min read
Internal Sort in COBOL Internal Sequential files are often used in big data operational processing applications, necessitating the records to be arranged in an operational ascending or descending order. This ensures quick access to the data and makes it easier to retrieve. Furthermore, sorting data in a file or combining
4 min read
Programming Construction in COBOL COBOL is a compiled, imperative, procedural programming language designed for business use. It can handle very large numbers and strings. COBOL is still in use today because it's robust, with an established code base supporting sprawling enterprise-wide programs. Learning to program in COBOL will se
5 min read
Linkage Section in COBOL The linkage Section in COBOL is used to declare the variables and it is used in calling the variable from another program. It is used in calling the variable or data from the called program by using the CALL statement. The linkage Section helps in sending the data to the calling program or receivin
4 min read
File Declaration in COBOL COBOL (Common Business-Oriented Language) is a high-level programming language that was developed in the 1950s for business applications. In COBOL, a file is a collection of records that are stored on external storage devices such as tapes or disks. A file can be input, output, or both input and out
9 min read
File Section in COBOL COBOL is a high-level programming language for business applications or business use. It was designed in 1959 by the Conference on Data Systems Language (CODASYL). It was primarily used in business, finance, and administration system for companies and governments. COBOL is still widely used in appli
6 min read