COBOL Manual for TNS/E Programs (H06.08+, J06.03+)

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 50, 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.
Example 50 Fixed-Size Table
01 MY-TABLE-RECORD.
02 MY-TABLE OCCURS 100 TIMES
ASCENDING KEY IS FIRST-ITEM
INDEXED MY-INDEX.
05 FIRST-ITEM.
08 FIRST-A PICTURE 99.
08 FIRST-B.
10 FIRST-B-1 PICTURE 99.
10 FIRST-B-2 PICTURE 99.
05 SECOND-ITEM PICTURE X(6).
01 VEHICLE.
03 MODEL OCCURS 9 TIMES.
05 STYLE OCCURS 12 TIMES.
07 COLOR OCCURS 15 TIMES PICTURE 9(10).
05 LOCATION PICTURE X(25).
These identifiers specify elements of the table VEHICLE in Example 50:
MODEL (3)
STYLE OF MODEL (3, 11)
COLOR OF STYLE OF MODEL (3, 11, 14)
OCCURS Clause for Variable-Size Tables
The OCCURS clause with a DEPENDING phrase defines a variable-size table.
214 Data Division