Group items in COBOL
Level numbers build a record: the 01 owns the group, the 05s are its fields.
IDENTIFICATION DIVISION.
PROGRAM-ID. GROUP-ITEMS.
DATA DIVISION.
WORKING-STORAGE SECTION.
*> Levels build records: 01 owns the group, the 05s are its fields.
01 LOG-ENTRY.
05 LOG-DAY PIC X(3) VALUE "Tue".
05 LOG-WIND PIC 99 VALUE 18.
05 LOG-REMARK PIC X(14) VALUE " gusty at dusk".
PROCEDURE DIVISION.
DISPLAY "Field by field: " LOG-DAY ", wind " LOG-WIND
*> Naming the group hands over the whole record at once.
DISPLAY "Whole group: " LOG-ENTRY
STOP RUN.
How it works
01 LOG-ENTRY.has no picture of its own — it is the sum of its parts.- Each
05field carries its ownPICandVALUEunder the group. - Displaying a field uses its name; displaying
LOG-ENTRYprints the whole record.
Keywords and builtins used here
DATADISPLAYDIVISIONIDENTIFICATIONPROCEDURESECTIONSTOP
The run, in numbers
- Lines
- 14
- Characters to type
- 468
- Tokens
- 50
- Three-star pace
- 40 tpm
At the three-star pace of 40 tokens a minute, this run takes about 75 seconds.
Step 3 of 3 in Pictures, step 6 of 27 in Language basics.