The four divisions
| The four divisions | |
| IDENTIFICATION | |
| ENVIRONMENT | |
| DATA |
The four divisions
Every COBOL program is organized into up to four divisions, always in the same order. Each division collects one kind of information, and the compiler expects them in sequence.
IDENTIFICATION DIVISION.
ENVIRONMENT DIVISION.
DATA DIVISION.
PROCEDURE DIVISION.
IDENTIFICATION
IDENTIFICATION DIVISION holds the program name and optional metadata like AUTHOR and DATE-WRITTEN. PROGRAM-ID is the only required paragraph.
IDENTIFICATION DIVISION.
PROGRAM-ID. PAYROLL.
AUTHOR. ARTHUR ISAEV.
ENVIRONMENT
ENVIRONMENT DIVISION describes where the program runs: which files it uses and which special names it needs. Small utility programs often skip it entirely.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT PAYROLL-FILE ASSIGN TO "payroll.dat".
DATA
DATA DIVISION declares every variable and file record before the program uses them. WORKING-STORAGE SECTION holds the in-memory fields:
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NAME PIC X(30).
01 WS-HOURS PIC 9(3)V99.
Next: Variables and PICTURE clauses
Article author: Arthur Isaev