typestar

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

  1. 01 LOG-ENTRY. has no picture of its own — it is the sum of its parts.
  2. Each 05 field carries its own PIC and VALUE under the group.
  3. Displaying a field uses its name; displaying LOG-ENTRY prints the whole record.

Keywords and builtins used here

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.

Type this snippet

Step 3 of 3 in Pictures, step 6 of 27 in Language basics.

← Previous Next →