The OCCURS clause allows for the creation of tables or arrays.
Format 1
OCCURS table-size TIMES
[ {ASCENDING } KEY IS {key-name} ... ] ...
{DESCENDING}
[ INDEXED BY {index-name} ... ]
Format 2
OCCURS [ min-size TO ] max-size TIMES DEPENDING ON dep-item
[ {ASCENDING } KEY IS {key-name} ... ] ...
{DESCENDING}
[ INDEXED BY {index-name} ... ]
Syntax Rules
- table-size is a positive integer that specifies the exact number of occurrences.
- min-size is an integer that specifies the minimum number of occurrences. Its value must be greater than or equal to zero. If omitted,
it has a default value of one.
- max-size is an integer that specifies the maximum number of occurrences. Its value cannot be less than min-size; it cannot be larger than 2147483647.
- dep-item is the name of an elementary unsigned integer data item. Its value specifies the current number of occurrences.
- Index-name is an index-name. It associates an index with the table. Index-name is implicitly defined by the INDEXED phrase. It may not be defined elsewhere in the program. Each index-name must be a unique word in the program, because it cannot be qualified.
- key-name is the data-name of the entry that contains the OCCURS clause, or an entry subordinate to it. key-name may be qualified. Each key-name after the first must name a subordinate item to the entry containing the OCCURS clause. A key-name may not contain an OCCURS clause unless that key-name is the name of the subject of the current OCCURS clause.
- If a Format 2 OCCURS clause appears in a record description for a file, dep-item must appear in the same record.
- An item described by a Format 2 OCCURS clause can be followed, in the same record description, only by items subordinate to
it.
- An OCCURS clause may not appear in a data description entry that has a level-number of 66, 78, or 88. A variable occurrence
data item (one that has a Format 2 OCCURS clause) may not be subordinate to another data item that has an OCCURS clause.
- The dep-item may not occupy any character positions subordinate to the data item described by that OCCURS clause.
General Rules
- The OCCURS clause defines tables. All items subordinate to an OCCURS clause must be referenced with subscripting or indexing.
- Except for the OCCURS clause itself, all data description clauses associated with that data item apply to each occurrence
of the item.
- A Format 1 OCCURS clause defines a fixed-size table.
- A Format 2 OCCURS clause defines a table that contains a variable number of occurrences. The current number of occurrences
depends on dep-item. Only the number of occurrences is variable; the table's size is fixed (max-size). dep-item must fall in the range from min-size to max-size. Values contained in the table that are beyond the current number of occurrences (dep-item) are unpredictable.
- The size occupied by a table is the size of one of its occurrences multiplied by the maximum number of occurrences in the
table (max-size in Format 2).
- If a group item containing a subordinate data item with a Format 2 OCCURS clause is involved in an operation, the operation
uses only that part of the table specified by dep-item.
- Index names are treated in all respects as USAGE INDEX data items by the compiler.
- The KEY IS phrase indicates that the data is arranged in ascending or descending order according to the values in the data
items named by key-name. The position of each key-name in the list determines its significance. The first key-name is the most significant, the last is the least significant. The KEY IS phrase is used by the SEARCH ALL verb.