Tables: OCCURS arrays
| OCCURS | |
| Subscripts | |
| SEARCH |
OCCURS
OCCURS declares a table: one data item repeated a fixed number of times. The OCCURS clause sits on the repeating item, not on the group:
01 WS-TEMPS.
05 WS-TEMP OCCURS 7 TIMES PIC S9(3).
Subscripts
Use a subscript in parentheses to read or write one entry. Subscripts are 1-based, unlike C arrays, and the compiler checks them against the table size at run time:
MOVE 72 TO WS-TEMP(1).
MOVE WS-TEMP(3) TO WS-HIGH.
DISPLAY "Day 3: " WS-TEMP(3).
SEARCH
SEARCH scans a table for the first match. It uses a subscript you set with SET, and AT END runs when nothing matched:
SET WS-I TO 1.
SEARCH WS-TEMP
AT END DISPLAY "Not found"
WHEN WS-TEMP(WS-I) = 72
DISPLAY "Found at " WS-I
END-SEARCH.
Next: INDEXED BY and OCCURS DEPENDING ON
Article author: Arthur Isaev