COBOL divisions
Every COBOL program has four parts, always in the same order.
Also written divisions, identification division, environment division
Why it matters. When you open a program you have never seen, the divisions tell you where to look. The fields are in one place and the logic is in another.
See it
Division 1: who the program is.
Syntax
IDENTIFICATION DIVISION. PROGRAM-ID. program-name. [ENVIRONMENT DIVISION.] [DATA DIVISION.] PROCEDURE DIVISION.
Try it DIVISION
- 1
You're writing the program WELCOME from the top. Three divisions are done: IDENTIFICATION, ENVIRONMENT and DATA. The fourth holds the statements that run. Type its heading.
COBOL PROCEDURE DIVISION. - 2
Run the program NODECL. It shows the field WS-BAL, but nobody declared that field in the DATA DIVISION.
RUNCOBOL 'ZB0001.DEV.COBOL(NODECL)'
Remember
- IDENTIFICATION names the program. ENVIRONMENT describes the files and the machine.
- DATA declares every field. PROCEDURE holds the statements that run.
- The order never changes. ENVIRONMENT and DATA can be left out if the program needs no files or fields.
The usual mistake
Using a field in the PROCEDURE DIVISION that is not in the DATA DIVISION
The compiler reads the DATA DIVISION first. A name it has never seen is an error, and the program does not run.
Declare the field in the DATA DIVISION, then use it in the PROCEDURE DIVISION
On real z/OS
A real compile reports a missing name as IGYPS2121-S and still lists the rest of the program. MF/OS stops before running and prints its own MFSIM line.
Where can I practise COBOL divisions?
Right here, at ZedBank. You take a junior job at a simulated bank and use COBOL divisions in real work, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- COBOLThe programming language most business logic on the mainframe is written in. Verbose by design, and still running the world's payments.
- DATA DIVISIONThe part of a COBOL program that declares every record layout and variable it will use.
- PROCEDURE DIVISIONThe part of a COBOL program that contains the actual logic, the statements that run.
- WORKING-STORAGEThe section of a COBOL program that declares its internal variables: counters, totals, flags and work areas.
- File descriptionThe FD entry in a COBOL program that describes a file's records, connecting the program to data supplied by the JCL.