Compaq AAQ2G1FTK Marine Radio User Manual


 
Handling Tables
4.3 Accessing Table Elements
4.3.2 Subscripting with Literals
A literal subscript is an integer value, enclosed in parentheses, that represents
the desired table element. In Example 4–15, the literal subscript ( 2 ) in the
MOVE instruction moves the contents of the second element of A-TABLE to
I-RECORD.
Example 4–15 Using a Literal Subscript to Access a Table
Table Description:
01 A-TABLE.
03 A-GROUP PIC X(5)
OCCURS 10 TIMES.
Instruction:
MOVE A-GROUP(2) TO I-RECORD.
If the table is multidimensional, follow the data name of the desired data item
with a list of subscripts, one for each OCCURS clause to which the item is
subordinate. The first subscript in the list applies to the first OCCURS clause
to which that item is subordinate. This is the most inclusive level, and is
represented by A-GROUP in Example 4–16. The second subscript applies to the
next most inclusive level and is represented by ITEM3 in the example. Finally,
the third subscript applies to the least inclusive level, represented by ITEM5.
(Note that Compaq COBOL can have 48 subscripts that follow the pattern in
Example 4–15.)
In Example 4–16, the subscripts (2,11,3) in the MOVE statements move the third
occurrence of ITEM5 in the eleventh repetition of ITEM3 in the second repetition
of A-GROUP to I-FIELD5. ITEM5(1,1,1) refers to the first occurrence of ITEM5
in the table, and ITEM5(5,20,4) refers to the last occurrence of ITEM5.
Example 4–16 Subscripting a Multidimensional Table
Table Description:
01 A-TABLE.
03 A-GROUP OCCURS 5 TIMES.
05 ITEM1 PIC X.
05 ITEM2 PIC 99 COMP OCCURS 20 TIMES.
05 ITEM3 OCCURS 20 TIMES.
07 ITEM4 PIC X.
07 ITEM5 PIC XX OCCURS 4 TIMES.
01 I-FIELD5 PIC XX.
Procedural Instruction:
MOVE ITEM5(2, 11, 3) TO I-FIELD5.
Handling Tables 4–13