The DATA DIVISION language elements used for table handling are the OCCURS clause and the INDEXED BY phrase.
For the INDEXED BY phrase description, see INDEXED BY phrase.
The OCCURS clause specifies tables whose elements can be referred to by indexing or subscripting. It also eliminates the need for separate entries for repeated data items.
Formats for the OCCURS clause include fixed-length tables and variable-length tables.
The subject of an OCCURS clause is the data-name of the data item that contains the OCCURS clause. Except for the OCCURS clause itself, data description clauses used with the subject apply to each occurrence of the item described.
Whenever the subject of an OCCURS clause or any data-item subordinate to it is referenced, it must be subscripted or indexed, with the following exceptions:
- When the subject of the OCCURS clause is used as the subject of a SEARCH statement.
- When the subject of the OCCURS clause is used as the subject of a format 2 SORT statement.
- When the subject or a subordinate data item is the object of the ASCENDING/DESCENDING KEY phrase.
- When the subordinate data item is the object of the REDEFINES clause.
- When the subordinate data item is used as the subject of a LENGTH OF special register. For details, see LENGTH OF.
When subscripted or indexed, the subject refers
to one occurrence within the table, unless the
is used in an intrinsic function.
The OCCURS clause cannot be specified in a data description entry that:
- Has a level number of 01, 66, 77, or 88.
- Describes a redefined data item. (However, a redefined item can be subordinate to an item that contains an OCCURS clause.) See REDEFINES clause.