DATA DIVISION
The part of a COBOL program where every field is declared before it is used.
Also written DATA DIVISION, file section
Why it matters. COBOL does not make fields for you. If a name is not declared here, the program does not compile.
See it
Describes the records of the files the program reads or writes.
Syntax
DATA DIVISION. FILE SECTION. WORKING-STORAGE SECTION. LINKAGE SECTION.
- FILE SECTION
- The record layout of each file, under an FD.
- WORKING-STORAGE SECTION
- The program's own fields.
- LOCAL-STORAGE SECTION
- Fields set up again on every call.
- LINKAGE SECTION
- Fields passed in from the caller.
Try it DATA DIVISION
- 1
Run the program NODECL. It shows the field WS-BAL, but nothing declares it.
RUNCOBOL 'ZB0001.DEV.COBOL(NODECL)' - 2
In the WORKING-STORAGE SECTION of NODECL, declare WS-BAL: 5 digits, then 2 decimals, starting at 1200.50.
COBOL 01 WS-BAL PIC 9(5)V99 VALUE 1200.50. - 3
Run NODECL again.
RUNCOBOL 'ZB0001.DEV.COBOL(NODECL)'
Remember
- Declare a field in the DATA DIVISION before the PROCEDURE DIVISION uses it.
- A field line has a level number, a name, a picture and often a start value.
- WORKING-STORAGE is for the program's own fields. The FILE SECTION is for file records. The LINKAGE SECTION is for fields passed in by a caller.
The usual mistake
MOVE 100 TO WS-NEW (WS-NEW is not declared)
COBOL does not make a field because you used its name. The compiler stops, and the program does not run.
01 WS-NEW PIC 9(3). in the DATA DIVISION, then MOVE 100 TO WS-NEW
On real z/OS
MF/OS parses LINKAGE but passes no data into it, and LOCAL-STORAGE starts once like WORKING-STORAGE. A real program gets both.
Where can I practise DATA DIVISION?
Right here, at ZedBank. You take a junior job at a simulated bank and use DATA DIVISION in real work, with Zed beside you. There's nothing to install.
Start at ZedBankRelated
- COBOL divisionsThe four fixed sections every COBOL program is built from, always in the same order.
- WORKING-STORAGEThe section of a COBOL program that declares its internal variables: counters, totals, flags and work areas.
- PICTURE clauseThe COBOL declaration that says what kind of data a field holds and how long it is, written as PIC.
- Level numberThe two-digit number in front of a COBOL data item that shows how fields nest inside a record.
- CopybookA shared block of COBOL declarations kept in a library and included into programs, so a record layout is defined once.
- File descriptionThe FD entry in a COBOL program that describes a file's records, connecting the program to data supplied by the JCL.