Example: indexing
The following example shows how displacements to elements that are referenced with indexes are calculated.
Consider the following three-dimensional table, SAMPLE-TABLE-FOUR
:
01 SAMPLE-TABLE-FOUR
05 TABLE-DEPTH OCCURS 3 TIMES INDEXED BY INX-A.
10 TABLE-ROW OCCURS 4 TIMES INDEXED BY INX-B.
15 TABLE-COLUMN OCCURS 8 TIMES INDEXED BY INX-C PIC X(8).
Suppose you code the following relative indexing reference to SAMPLE-TABLE-FOUR
:
TABLE-COLUMN (INX-A + 1, INX-B + 2, INX-C - 1)
This reference causes the following computation of the displacement
to the TABLE-COLUMN
element:
(contents of INX-A) + (256 * 1)
+ (contents of INX-B) + (64 * 2)
+ (contents of INX-C) - (8 * 1)
This calculation is based on the following element lengths:
- Each occurrence of
TABLE-DEPTH
is 256 bytes in length (4 * 8 * 8). - Each occurrence of
TABLE-ROW
is 64 bytes in length (8 * 8). - Each occurrence of
TABLE-COLUMN
is 8 bytes in length.