Skip to content
Group Items
step 1/5

Reading — step 1 of 5

Learn

~1 min readStructured Data

COBOL records are built with level numbers. Levels 02-49 nest under their containing items. Level 01 is the outermost.

       01  PERSON.
           05  NAME           PIC X(20).
           05  ADDRESS.
               10  STREET     PIC X(30).
               10  CITY       PIC X(15).
               10  ZIP        PIC 9(5).
           05  AGE            PIC 9(3).

This is one record. Access nested fields with OF:

           MOVE "Ada" TO NAME OF PERSON.
           MOVE "NW1" TO ZIP OF ADDRESS OF PERSON.
           DISPLAY NAME OF PERSON.

The whole record can also be referred to as PERSON — its bytes laid out flat in memory.

Level 77 — standalone elementary item (not part of a group):

       77  COUNTER       PIC 9(5) VALUE 0.

Level 88 — condition name. A boolean predicate over a value:

       01  STATUS-CODE   PIC X.
           88  IS-ACTIVE  VALUE 'A'.
           88  IS-CLOSED  VALUE 'C'.
           88  IS-PENDING VALUE 'P'.

*> Then in PROCEDURE:
           IF IS-ACTIVE THEN
               DISPLAY "active"
           ELSE IF IS-CLOSED THEN
               DISPLAY "closed"
           END-IF.

88-level reads as English — that's COBOL's design goal. Set with SET:

           SET IS-ACTIVE TO TRUE.   *> sets STATUS-CODE to 'A'

Level 88 over ranges or lists:

       01  AGE             PIC 9(3).
           88  IS-MINOR     VALUE 0 THRU 17.
           88  IS-ADULT     VALUE 18 THRU 64.
           88  IS-SENIOR    VALUE 65 THRU 130.

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…