In this topic, we described about the Variable-length Tables with detailed example.
Specifies the number of OCCURS dynamically. The number of occurrences value specified while running the program. Variable-length tables by using the OCCURS DEPENDING ON clause.
The minimum number of occurrences. The integer-1 value must be greater than or equal to zero and must be less than the value of integer-2. If integer-1 is omitted, 1 is assumed and the keyword TO must also be omitted.
The maximum number of occurrences. Integer-2 value must be greater than integer-1 value. Only the number of repetitions of the item is variable.
Unbounded maximum number of occurrences. A table with an OCCURS clause that specifies UNBOUNDED is Unbounded table. A group that contains at least one unbounded table is Unbounded group.
The total size of an unbounded group at run time must be less than 999,999,999 bytes. For unbounded tables and groups, the effect of the SSRANGE compiler option is limited.
OCCURS DEPENDING ON
Specifies variable-length tables. All data-names used in the OCCURS clause can be qualified but not subscripted or indexed. The value of the OCCURS DEPENDING ON clause must fall within the range integer-1 through integer-2 if integer-2 is specified.
If the value of the object is outside of the range integer-1 through integer-2, the behaviour is undefined. The INDEXED BY phrase can be specified for a table that contains an OCCURS DEPENDING ON clause for the elementary items.
ASCENDING KEY AND DESCENDING KEY
Specifies the data is arranged in ascending or descending order based on the keyword specified according to the values contained in data-name. The order is determined by the rules for comparison of operands.
The ASCENDING KEY and DESCENDING KEY data items are used in OCCURS clauses for the SEARCH ALL statements and SORT statements. The total number of keys for a given table element must not exceed 12.
Data-name(s) is the name of the data item(s) on which basis the table is sorted (Either ascending or descending). Data-name must follow the table entry itself.
Data-name must not follow any other entry that contains an OCCURS clause. Data-name must not contain an OCCURS clause. Data-name must not have data items under it that contain OCCURS DEPENDING ON clauses.
Specifies the indexes that are used with a table. Indexes normally are allocated in static memory associated with the program. Indexes are in the last-used state if a program is re-entered.
Specifies an index to be created by the compiler for use by the program. These index-names are not data-names and are not identified elsewhere in the COBOL program. Unreferenced index names need not be uniquely defined. Up to 12 index-names can be specified in one table entry.