What you actually need to know before reading COBOL source cold - get DIVISION / PIC / COMP-3 / COPY / PERFORM straight first
The short version
- COBOL is a record-definition language before it is a logic language
- reading only
PROCEDURE DIVISIONgets you less than half of it. Look atDATA DIVISIONfirst PICis the shape of an item,USAGEis its internal representationCOMP-3is packed decimal. You see it constantly on amounts and counts88is not a separate variable — it is a condition name attached to the value of the item just above itREDEFINESlets you view the same memory in a different shape (it is not a copy)- if there is a
COPY, you cannot see the whole picture without opening the copybook - old source uses fixed format, where column position matters. Whitespace is not decoration
The four DIVISIONs
| DIVISION | what to look for |
|---|---|
| IDENTIFICATION DIVISION | program name |
| ENVIRONMENT DIVISION | files, I/O assumptions |
| DATA DIVISION | record definitions, work areas, arguments |
| PROCEDURE DIVISION | the actual processing steps |
Inside DATA DIVISION the parts that matter most are:
- FILE SECTION - record definitions for input/output files
- WORKING-STORAGE SECTION - variables, flags, counters
- LINKAGE SECTION - arguments passed in from outside (the entry point for subprograms)
How to read fixed format
In old COBOL, column position has meaning.
- columns 1-6: sequence number
- column 7: indicator (
*= comment,-= continuation,D= debug line) - columns 8-11: Area A
- columns 12-72: Area B
Tab conversion or left-aligning the file will break it. Check whether the source is fixed format or free format before anything else.
DATA DIVISION — the minimum
Level numbers
01 WS-ORDER. <- top-level record
05 WS-ORDER-ID PIC 9(8).
05 WS-AMOUNT PIC S9(7)V99 COMP-3.
05 WS-STATUS PIC X.
88 WS-OK VALUE '0'. <- condition name (true when WS-STATUS is '0')
88 WS-ERROR VALUE '9'.
77 WS-COUNT PIC 9(4). <- standalone single item
01: top of a group05–49: subordinate items77: standalone single item88: condition name (a name attached to a value of the item just above)
Do not read 88 as a separate boolean variable. It is just a name for a state of the value.
PICTURE (PIC)
| notation | meaning |
|---|---|
| X | character |
| 9 | digit |
| S | signed |
| V | decimal point (logical only — there is no . in the data) |
| X(10) | 10 characters |
| 9(5) | 5-digit number |
| S9(7)V99 | signed 7-digit integer + 2 decimal places |
V does not occupy an actual . character, so if you stare at the file as plain text the digits look misaligned.
USAGE (internal representation)
| notation | meaning | watch out for |
|---|---|---|
| DISPLAY | decimal as visible characters | on a mainframe this can mean EBCDIC |
| COMP / BINARY | binary | the visible digit count and the internal layout are different things |
| COMP-3 | packed decimal | amounts and counts. Looks like garbage if you read it as text |
DISPLAY does not automatically mean ASCII. On z/OS it is EBCDIC by default.
REDEFINES / OCCURS / COPY / FILLER
- REDEFINES: view the same area in a different shape (close to a C
union). Not a copy - OCCURS: array.
OCCURS DEPENDING ONis a variable-length table - COPY: a compile-time include. You cannot see the finished record without the copybook
- FILLER: an unnamed item. Used for reserved space or to pad record length. It still takes bytes
PROCEDURE DIVISION — the minimum
PERFORM
The basic call-and-return construct.
PERFORM UNTIL EOF
READ IN-FILE
AT END SET EOF TO TRUE
NOT AT END PERFORM PROCESS-REC
END-READ
END-PERFORM
IF / EVALUATE
IFis the basic conditionalEVALUATEis the switch/case equivalent
Watch the period .
In old code, a . is an implicit scope terminator. A single stray period changes the range of an IF or PERFORM. NEXT SENTENCE jumps to whatever comes after the next ..
READ / WRITE / CALL
READ ... AT END ...is the standard patternCALL 'SUBPGM' USING ...jumps into another program
What lives outside the COBOL
COBOL rarely stands alone.
- FILE STATUS - the result code after every I/O. Essential for diagnosing file failures
- EXEC SQL - embedded SQL. The COBOL is just a holder for host variables; the real work is on the SQL side
- EXEC CICS - CICS transaction context. You need to read the screens and COMMAREA together with the code
- JCL - on a mainframe batch, which datasets get assigned is decided outside the COBOL itself
A minimum reading order
- Walk every COPY - open the copybooks or find the post-expansion source
- Pick up the
01-level record definitions - in FILE SECTION, WORKING-STORAGE, and LINKAGE SECTION - Read PIC and USAGE - identify amounts, dates, counts, codes
- Search for READ/WRITE/CALL/EXEC SQL/EXEC CICS - locate the I/O and the external boundaries
- Follow only the first main path - trace the PERFORM chain from the top of PROCEDURE DIVISION
- Look at
88s and status items - the meaning of EOF and ok/error becomes much easier to read - Mark every REDEFINES, OCCURS DEPENDING ON, and COMP-3
- Check FILE STATUS - it cuts down misreads around I/O errors
Quick reference
| if you see this | think this first |
|---|---|
| 01 | top of a record or group |
| 88 | a named meaning for a flag or status code |
| PIC X(…) | character item |
| PIC 9(…) | numeric item — check digits and decimal position |
| COMP | binary |
| COMP-3 | packed decimal — likely an amount or count |
| REDEFINES | the same area being read a different way |
| OCCURS | array |
| OCCURS DEPENDING ON | variable length — watch what comes after it too |
| FILLER | no name, but it has length |
| COPY | you need the copybook to see the full record |
| PERFORM | skeleton of the main path |
| READ/WRITE | file I/O |
| EXEC SQL | DB work |
| EXEC CICS | transaction work |
| FILE STATUS | I/O result code |
Things that trip people up
- Treating REDEFINES as a separate variable — it is just the same area viewed differently
- Treating
88as a standalone bool — it is a name attached to the value of the item above - Reading the body and ignoring COPY — half the field definitions live outside the file
- Treating
MOVEas plain assignment — type-driven conversion and digit alignment happen during the move - Underestimating the period
.— the scope terminator easily moves - Mistaking packed decimal or EBCDIC for mojibake — it was never plain text, or it is just not ASCII
Wrap-up
COBOL is not hard because it is old. It is hard because data definitions, external files, and the execution context are tightly bound together, which makes the entry point hard to find.
- get the map from the DIVISIONs
- read DATA DIVISION first
- read item shapes through PIC and USAGE
- mark COMP-3, REDEFINES, OCCURS, 88, and COPY
- follow PERFORM, READ, WRITE, and CALL
- pin down the external boundary with FILE STATUS, EXEC SQL, and EXEC CICS
Once the scale of the map matches the territory, it reads more normally than you would expect.
Related Articles
Recent articles sharing the same tags. Deepen your understanding with closely related topics.
Pitfalls in COM, OCX, and ActiveX Development - Visual Studio Bitness, Registration, and Admin-Rights Traps
The traps that bite COM, OCX, and ActiveX work in practice: 32-bit/64-bit mismatches, regsvr32 vs Regasm, HKCU vs HKLM scope, and admin-r...
What Reg-Free COM Is - How Registration-Free COM Works, and Where It Fits or Does Not
A practical look at Reg-Free COM, framed around activation contexts and manifests. Covers the wins (XCOPY deployment, side-by-side versio...
What COM / ActiveX / OCX Are - Differences and How They Relate
A compact guide that organizes COM, ActiveX, and OCX as three layers - foundation, component, and file - and covers their relationship to...
Sorting out Windows text encodings and line endings - Shift_JIS / UTF-8 / UTF-16, mojibake, CRLF / LF, and why it gets confusing
A practical guide that breaks Windows text-file trouble down into independent pieces — bytes, encoding, BOM, and CRLF / LF — and walks th...
Pseudorandom vs True Random: How to Tell Them Apart
A practical look at pseudorandom and true random numbers across four axes - source, reproducibility, predictability, and speed - covering...
Related Topics
These topic pages place the article in a broader service and decision context.
Windows Technical Topics
Topic hub for KomuraSoft LLC's Windows development, investigation, and legacy-asset articles.
ActiveX Migration
Topic page for staged decisions around keeping, wrapping, or replacing COM / ActiveX / OCX assets.
Where This Topic Connects
This article connects naturally to the following service pages.
Windows Software Maintenance & Modernization
We support staged upgrades, feature additions, 64-bit readiness, and maintainable restructuring for existing Windows software.
Legacy Asset Reuse & Migration Support
We help plan staged migration while continuing to reuse COM / ActiveX / OCX assets, native code, and 32-bit dependencies.