Mainframe Path Start learning free
Core7 min readLesson 2 of 5

The four divisions

Every COBOL program has the same four sections in the same order. Once you know what belongs where, you can navigate any program in seconds.

The fixed order, and what lives in each
IDENTIFICATIONThe program's name. Sometimes author and dates.
ENVIRONMENTConnects file names in the program to ddnames in the JCL
DATAEvery field the program uses: files, working storage, linkage
PROCEDUREThe logic — the only executable part

ENVIRONMENT: the bridge to JCL

SELECT PAY-FILE ASSIGN TO INFILE says: the file this program calls PAY-FILE is whatever the JCL supplies on the DD statement named INFILE. That single line is the entire connection between a program and its data, and it is why you can point the same program at test data by changing one DD.

DATA DIVISION: three sections you will meet

SectionHolds
FILE SECTIONRecord layouts for files, one FD per file
WORKING-STORAGE SECTIONVariables the program owns; they persist for the whole run
LOCAL-STORAGE SECTIONVariables re-initialised on every call — used in recursive or CICS work
LINKAGE SECTIONData passed in from outside: a PARM, or arguments from a calling program

Level numbers build a hierarchy

Levels, groups and the 88 condition name
       01  CUSTOMER-RECORD.
           05  CUST-ID           PIC X(08).
           05  CUST-NAME.
               10  CUST-FIRST    PIC X(15).
               10  CUST-LAST     PIC X(20).
           05  CUST-STATUS       PIC X(01).
               88  CUST-ACTIVE              VALUE 'A'.
               88  CUST-CLOSED              VALUE 'C'.
               88  CUST-VALID               VALUE 'A' 'C' 'S'.
           05  CUST-BALANCE      PIC S9(9)V99 COMP-3.

* then in the PROCEDURE DIVISION:
           IF CUST-ACTIVE
               PERFORM 3000-PROCESS-ACTIVE
           END-IF

PROCEDURE DIVISION: paragraphs and PERFORM

Logic is organised into paragraphs, usually numbered so the numbers imply call order. PERFORM 2000-PROCESS runs that paragraph and returns. PERFORM … UNTIL is the loop. PERFORM … VARYING is the counted loop. Modern style uses scope terminators — END-IF, END-READ, END-PERFORM — rather than full stops, because a misplaced full stop is one of the classic COBOL bugs.

Common mistakes

A stray full stop inside an IF

It terminates the conditional silently. The code compiles and does the wrong thing.

Assuming WORKING-STORAGE is cleared between calls

It persists for the run. In a called subprogram, values from the previous call are still there unless you initialise them or use LOCAL-STORAGE.

Reading a group item as if it were numeric

A group with no PIC is always character data, whatever its children are. Moving it to a numeric field is how S0C7s begin.

What you will see at work

Key terms

Check your understanding.
Take this lesson's quiz and save your progress. Free.

Take the lesson quiz
← Why COBOL still, and what it is good atPICTURE clauses and how data is stored →