What Is the Data Division?
Every COBOL program is organized into four divisions, compiled in strict order: IDENTIFICATION DIVISION, ENVIRONMENT DIVISION, DATA DIVISION, and PROCEDURE DIVISION. The DATA DIVISION is where every variable, record layout, and file structure a program will touch must be declared up front, using level numbers and PICTURE clauses, before the PROCEDURE DIVISION contains a single executable statement. This front-loaded declaration style reflects COBOL's batch-processing origins on mainframes, where the compiler needed to know the exact storage layout and byte size of every field before generating machine code.
Cricket analogy: Before a Test match begins, the scorer's ledger is ruled up with columns for runs, balls, and extras already fixed, much like DATA DIVISION fixes every field's layout before PROCEDURE DIVISION bowls a single line of logic.
The Four Divisions and Where DATA DIVISION Fits
The IDENTIFICATION DIVISION names the program with PROGRAM-ID, the ENVIRONMENT DIVISION describes the machine and file assignments with SELECT ... ASSIGN TO, and only after those does DATA DIVISION appear, followed finally by PROCEDURE DIVISION containing the actual logic. Skipping or misordering a division causes a compile error, because the compiler processes source top to bottom and expects each division's reserved header exactly once in this sequence. This rigid four-part skeleton is one of the first things every COBOL programmer memorizes, since generated templates and legacy copybooks all assume it.
Cricket analogy: A Test match day has a fixed sequence of toss, anthems, then first innings, and skipping the toss to start batting would be as invalid as PROCEDURE DIVISION appearing before DATA DIVISION.
FILE SECTION and WORKING-STORAGE SECTION
Within DATA DIVISION, the FILE SECTION describes the record layout of every file named in an FD (File Description) entry, matching field-for-field the physical layout of records on disk or tape, while the WORKING-STORAGE SECTION declares program variables, counters, flags, and constants that exist only in memory for the life of the run unit. A single DATA DIVISION can also include a LINKAGE SECTION for parameters passed from a calling program, but FILE SECTION and WORKING-STORAGE SECTION are the two sections nearly every COBOL program uses. Each FD's 01-level record description must match the file's actual byte layout exactly, since COBOL performs no automatic type coercion when reading fixed-length records.
Cricket analogy: FILE SECTION is like an official scorecard template printed to match a specific stadium's format exactly, while WORKING-STORAGE is the scorer's personal notepad for tallying the current partnership's runs.
IDENTIFICATION DIVISION.
PROGRAM-ID. PAYROLL-DEMO.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EMPLOYEE-FILE ASSIGN TO 'EMPFILE.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD EMPLOYEE-FILE.
01 EMPLOYEE-RECORD.
05 EMP-ID PIC 9(6).
05 EMP-NAME PIC X(30).
05 EMP-SALARY PIC 9(7)V99.
WORKING-STORAGE SECTION.
01 WS-EOF-FLAG PIC X VALUE 'N'.
01 WS-RECORD-COUNT PIC 9(4) VALUE ZERO.
01 WS-TOTAL-SALARY PIC 9(9)V99 VALUE ZERO.
PROCEDURE DIVISION.
MAIN-LOGIC.
OPEN INPUT EMPLOYEE-FILE
PERFORM UNTIL WS-EOF-FLAG = 'Y'
READ EMPLOYEE-FILE
AT END MOVE 'Y' TO WS-EOF-FLAG
NOT AT END
ADD 1 TO WS-RECORD-COUNT
ADD EMP-SALARY TO WS-TOTAL-SALARY
END-READ
END-PERFORM
CLOSE EMPLOYEE-FILE
STOP RUN.Order and Syntax Rules
Every clause inside DATA DIVISION must terminate with a period, and traditional COBOL is column-sensitive: Area A (columns 8-11) holds division, section, and 01-level headers, while Area B (columns 12-72) holds subordinate entries, though free-format COBOL in modern compilers like GnuCOBOL relaxes this. Forgetting a period after a PICTURE clause is one of the most common beginner errors, since the compiler silently absorbs the next line's tokens into the same clause and reports a confusing syntax error several lines later. Section headers such as FILE SECTION and WORKING-STORAGE SECTION must also appear in a fixed order, with FILE SECTION always preceding WORKING-STORAGE SECTION when both are present.
Cricket analogy: Forgetting to call over after six legal balls in club cricket lets confusion cascade into the next over's field placements, just as a missing period after a PICTURE clause cascades into a confusing downstream error.
FILE SECTION and WORKING-STORAGE SECTION are the two most commonly used sections, but a full DATA DIVISION can also contain LOCAL-STORAGE SECTION (reentrant working storage, common in CICS programs) and LINKAGE SECTION (parameters passed via CALL ... USING).
Reordering the sections within DATA DIVISION, for example placing WORKING-STORAGE SECTION before FILE SECTION, is a compile-time error in standard COBOL. Always declare FILE SECTION first whenever the program reads or writes any files.
- DATA DIVISION is the third of COBOL's four divisions and must appear after ENVIRONMENT DIVISION and before PROCEDURE DIVISION.
- It declares every variable, record, and file layout used by the program before any logic executes.
- FILE SECTION describes record layouts tied to files declared with SELECT in ENVIRONMENT DIVISION.
- WORKING-STORAGE SECTION declares in-memory variables, flags, counters, and constants for the life of the run unit.
- LINKAGE SECTION and LOCAL-STORAGE SECTION exist for parameter passing and reentrant subprograms.
- Every clause must end with a period; a missing period causes confusing downstream compile errors.
- Section order within DATA DIVISION is fixed: FILE SECTION before WORKING-STORAGE SECTION.
Practice what you learned
1. Which division of a COBOL program immediately precedes the DATA DIVISION?
2. What is the primary purpose of the FILE SECTION within DATA DIVISION?
3. What commonly happens if a programmer forgets a period after a PICTURE clause?
4. Which section of DATA DIVISION holds variables that exist only in memory for the life of the run unit?
5. In traditional fixed-format COBOL, which column range is known as Area A, used for division and 01-level headers?
Was this page helpful?
You May Also Like
PICTURE Clauses Explained
A detailed guide to COBOL's PICTURE (PIC) clause, the syntax that defines a data item's category, size, and display format.
Working-Storage Section
How the WORKING-STORAGE SECTION declares a COBOL program's in-memory variables, initial values, flags, and constants that persist for the life of the run unit.
Level Numbers and Group Items
How COBOL uses level numbers from 01 to 49, plus the special 66, 77, and 88 levels, to build hierarchical record structures out of group and elementary items.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics