Data Division & Level Numbers
INITIALIZE sets fields according to their category: numeric to zero, alphanumeric to spaces (FILLER is skipped by default).
7.1 Sections of the DATA DIVISION
FILE SECTION FD/SD entries and record layouts for files
Record area exists while the program is loaded; content valid after a successful READ WORKING-STORAGE SECTION Program variables, constants, tables
Allocated once; keeps values between CALLs (until CANCEL) LOCAL-STORAGE SECTION
Variables re-allocated and re-initialized on every CALL Per invocation (needed for recursion, thread safety) LINKAGE SECTION
Describes data owned by the caller (parameters), or storage addressed by pointers No storage of its own REPORT SECTION Report Writer descriptions (Chapter 24) SCREEN SECTION
Screen layouts for terminal I/O (GnuCOBOL, Micro Focus; not IBM z/OS)
7.2 Level numbers
Record (top-level item). In Area A Subordinate items forming a hierarchy. Commonly 05, 10, 15 to leave room for insertion
RENAMES — an alternative grouping of existing items Independent elementary item (cannot be subdivided; legacy style — prefer 01)
Condition name — a named value or set of values of its parent item
7.3 Group and elementary items
An elementary item has a PIC; a group item has subordinates and no PIC.
A group item is always treated as alphanumeric (MOVE SPACES TO CUST-ADDRESS blanks all three fields).
FILLER (or omitting the name entirely, COBOL 2002) reserves unnamed bytes.
Qualified names resolve duplicates: CUST-CITY OF CUST-ADDRESS OF CUSTOMER-RECORD (or IN).
01 CUSTOMER-RECORD.
05 CUST-ID PIC 9(6).
05 CUST-NAME.
10 CUST-FIRST-NAME PIC X(15).
10 CUST-LAST-NAME PIC X(20).
05 CUST-ADDRESS.
10 CUST-STREET PIC X(30).
10 CUST-CITY PIC X(20).
10 CUST-ZIP PIC X(10).
05 CUST-BALANCE PIC S9(7)V99 COMP-3.
05 CUST-STATUS PIC X.
88 CUST-ACTIVE VALUE "A".
88 CUST-CLOSED VALUE "C".
05 FILLER PIC X(10).7.4 Naming rules
1–30 characters (letters, digits, hyphens); must contain at least one letter; cannot start or end with a hyphen.
Must not be a reserved word (DATE, TIME, COUNT, RECORD are common traps — use WS-DATE).
Conventional prefixes: WS- working storage, LS- linkage/local storage, FD-record prefixes (CUST-), SW- switches, CT- counters, CON- constants.
7.5 INITIALIZE
INITIALIZE sets fields according to their category: numeric to zero, alphanumeric to spaces (FILLER is skipped by default).
(WITH FILLER and ALL TO VALUE are COBOL 2002 forms, supported by GnuCOBOL and IBM Enterprise COBOL.)
INITIALIZE CUSTOMER-RECORD
INITIALIZE CUSTOMER-RECORD REPLACING NUMERIC DATA BY 9
INITIALIZE CUSTOMER-RECORD WITH FILLER ALL TO VALUE