typestar

OCCURS tables in COBOL

OCCURS turns one picture into a five-slot tide table, subscripts starting at 1.

IDENTIFICATION DIVISION.
PROGRAM-ID. OCCURS-TABLES.
DATA DIVISION.
WORKING-STORAGE SECTION.
*> OCCURS turns one picture into a table; subscripts start at 1.
01 TIDE-TABLE.
   05 TIDE-FT  PIC 9V9 OCCURS 5 TIMES.
01 SLOT      PIC 9.
01 SHOW-FT   PIC 9.9.
PROCEDURE DIVISION.
    MOVE 2.1 TO TIDE-FT(1)  MOVE 3.4 TO TIDE-FT(2)
    MOVE 4.8 TO TIDE-FT(3)  MOVE 3.9 TO TIDE-FT(4)
    MOVE 2.6 TO TIDE-FT(5)
    PERFORM VARYING SLOT FROM 1 BY 1 UNTIL SLOT > 5
        MOVE TIDE-FT(SLOT) TO SHOW-FT
        DISPLAY "Reading " SLOT ": " SHOW-FT " ft"
    END-PERFORM
    STOP RUN.

How it works

  1. PIC 9V9 OCCURS 5 TIMES declares five readings under one group.
  2. Five MOVEs fill TIDE-FT(1) through TIDE-FT(5) by subscript.
  3. PERFORM VARYING SLOT walks the table and formats each reading via 9.9.

Keywords and builtins used here

The run, in numbers

Lines
18
Characters to type
529
Tokens
98
Three-star pace
35 tpm

At the three-star pace of 35 tokens a minute, this run takes about 168 seconds.

Type this snippet

Step 1 of 3 in Tables & strings, step 19 of 27 in Language basics.

← Previous Next →