100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Data Division Basics

An introduction to the COBOL Data Division, the section of a COBOL program where every variable, file layout, and record structure is declared before any executable logic runs.

Data & VariablesBeginner8 min readJul 10, 2026
Analogies

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.

cobol
       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

Was this page helpful?

Topics covered

#Programming#COBOLStudyNotes#DataDivisionBasics#Data#Division#Four#Divisions#StudyNotes#SkillVeris#ExamPrep