INDEXED BY and OCCURS DEPENDING ON
| INDEXED BY | |
| SET and indexes | |
| OCCURS DEPENDING ON |
INDEXED BY
INDEXED BY adds an index register to the table. The index holds the entry number in a form the CPU can use directly, which is faster than a subscript on large tables:
01 WS-STAFF.
05 WS-NAME OCCURS 100 TIMES
INDEXED BY WS-STAFF-IX PIC X(30).
SET and indexes
Indexes move with SET, not MOVE. SET UP and SET DOWN step by one, and you can assign an index from another index or a literal:
SET WS-STAFF-IX TO 1.
SET WS-STAFF-IX UP BY 1.
SET WS-STAFF-IX DOWN BY 2.
OCCURS DEPENDING ON
OCCURS DEPENDING ON makes the used length depend on a variable. The table reserves its maximum size, but loops and FILE records only see the used entries:
01 WS-ROW-COUNT PIC 9(2) VALUE 0.
01 WS-ROWS.
05 WS-ROW OCCURS 1 TO 50 TIMES
DEPENDING ON WS-ROW-COUNT PIC X(20).
Next: Paragraphs and sections
Article author: Arthur Isaev