COBOLbeginner
COBOL Program Structure
Understand the four mandatory divisions that every COBOL program is built from and what belongs in each.
Every COBOL program has four divisions, always in the same order.
Think of a COBOL program like a shipping manifest form with four locked sections in a fixed order — you can't write the cargo details before filling in the ship's registration, and you can't skip a section just because it feels redundant that day.
Key Concepts
1
IDENTIFICATION DIVISION. what the program is called
ENVIRONMENT DIVISION. which files it uses, and where
DATA DIVISION. every piece of storage it touches
PROCEDURE DIVISION. the code that runs2
IDENTIFICATION does nothing at runtime. It is still mandatory. Program name, author, comments.
3
ENVIRONMENT is the bridge to JCL. This is the part worth understanding properly:
4
SELECT CUSTOMER-FILE ASSIGN TO CUSTFILE.5
CUSTOMER-FILE is the name the program uses. CUSTFILE is a DD name. The JCL says which dataset that is:
CUSTOMER-FILECUSTFILE
6
//CUSTFILE DD DSN=PROD.CUSTOMER.MASTER,DISP=SHR7
So the program never names a dataset. The same compiled program reads test data or production data,
depending on the JCL. That is why batch systems are built this way — you change the file without
recompiling anything.
8
DATA is where the verbosity comes from, and it buys something. Nothing exists unless it is declared,
with a level number and a picture clause:
9
WORKING-STORAGE SECTION. the program's own variables
FILE SECTION. the record layout of each file
LINKAGE SECTION. parameters passed in by a caller10
A record layout describes bytes at fixed offsets. That is what lets a program read a file written by
another program thirty years ago. The layout is the contract, and both sides state it exactly.
11
PROCEDURE holds the code, organised into paragraphs:
12
PROCEDURE DIVISION.
MAIN-PARA.
PERFORM OPEN-FILES
PERFORM PROCESS-RECORDS UNTIL END-OF-FILE
PERFORM CLOSE-FILES
STOP RUN.13
The mental shift, for anyone from a modern language. A paragraph is not a function.
14
It has no parameters, no return value and no local variables. Every variable it touches is declared in the
DATA DIVISION and visible to the whole program.
15
So a paragraph is a named block you jump to, and all state is global. That explains a lot about how legacy
COBOL reads, and why working out what a paragraph affects means reading it rather than reading a signature.
16
Being able to write this skeleton from memory is a baseline expectation. The ENVIRONMENT-to-JCL link is
the piece candidates most often miss.
17
What the interviewer is probing.1. "Name the four divisions and what each is for." Probing: the foundation. Stalls: "There
are divisions." Moves up: IDENTIFICATION names the program, ENVIRONMENT maps files to the system,
DATA declares storage, PROCEDURE holds the logic.
18
2. "What is the difference between WORKING-STORAGE and LOCAL-STORAGE?" Probing: a real
distinction. Stalls: "They are the same." Moves up: WORKING-STORAGE is allocated once and keeps
its values between calls; LOCAL-STORAGE is fresh on every invocation, which matters for recursion
and CICS.
19
3. "What does the FILE SECTION record describe?" Probing: the mechanism. Stalls: "The file."
Moves up: the layout of one record in the buffer — it is not storage you own until a READ fills
it, which is why referencing it before a successful read is a bug.
20
4. "Why do shops insist on structured paragraph naming?" Probing: the maintenance angle.
Stalls: "Convention." Moves up: these programs are read far more often than written, and a
numbered, ordered naming scheme is what makes a 10,000-line program navigable.