COBOL Manual for TNS and TNS/R Programs

Data Division
HP COBOL Manual for TNS and TNS/R Programs522555-006
7-82
OCCURS Clause for Fixed-Size Tables
Multidimensional Tables
Data items subordinate to the subject of an entry described with an OCCURS
clause can themselves contain an OCCURS clause; therefore, tables can consist
of multiple occurrences of subordinate tables for a maximum of seven levels. A
data description entry containing either type of OCCURS clause can be followed by
subordinate entries containing the OCCURS clause for fixed-size tables; however,
a data description entry with an OCCURS DEPENDING clause (discussed in the
next topic) cannot be subordinate to a group entry described with either type of
OCCURS clause.
Order of Subscripts in References
Up to seven subscripts can be used with one data item. When more than one
subscript is used, they are written to the right of the table name, in the order of
more inclusive to less inclusive dimensions of the data organization (that is, the
first subscript matches the table having the lowest level number).
All qualification must precede any subscripts (see VEHICLE in Example 7-17).
Index is a Variant of Subscript
In COBOL, an index is a variant of a subscript. The program can define an indexed
table within a nonindexed table (or the reverse). Both indexes and subscripts can
be augmented with an increment or a decrement. That is, if a table is described:
01 A-TABLE.
03 ROWE OCCURS 20 TIMES INDEXED BY R.
05 KOLUMN OCCURS 10 TIMES.
07 ELEMENT PIC X.
then a statement in the program could refer to any of these (assuming X, R, and Y
had acceptable values):
ELEMENT ( R , 5 )
ELEMENT ( 3 , Y - 3 )
ELEMENT ( R + 1 , X + 2 )
Applying Index-Names to Other Tables
If you use an index-name specified in the INDEXED phrase of one table to refer to
an element of another table in the program, the compiler reports an error. You must
use the SET statement to the index-name associated with one table to the
occurrence-number designated by the index-name associated with a different
table.
In Example 7-17, MY-TABLE is appropriate for the SEARCH ALL statement. The
order of the table is governed by FIRST-ITEM. It can just as well be declared to be
governed by MY-TABLE, FIRST-A, FIRST-B, FIRST-B-1, FIRST-B-2, or SECOND-
ITEM.