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

Tables
NOTE: This topic applies to tables in the Data Division, not to SQL/MP or SQL/MX tables.
You can define a table by including an OCCURS clause in a data description entry. This clause
specifies that the data item be repeated a stated number of times. The item is a table element, and
the item’s name and description apply to each repetition of the element.
A table is a data structure composed of one or more occurrences of a specified data item. The
repeated data item is called a table element. The number of occurrences of a table element can
be fixed or variable. If the element is a table itself, or if it contains other tables, the table to which
the element belongs is multidimensional.
Because table elements do not have individual names, you must reference a table element by the
table name and its position in the table. Two methods for giving the position number are subscripting
and indexing. For information on subscripting, see Subscripts.
Topics explain how to declare:
One-Dimensional Tables With Fixed Number of Elements
One-Dimensional Tables With Variable Number of Elements
Multidimensional Tables
One-Dimensional Tables With Fixed Number of Elements
You can define a table by including an OCCURS clause in a data description entry. This clause
specifies that the data item be repeated a stated number of times. The item is a table element, and
the item’s name and description apply to each repetition of the element. For example, this entry
defines a 1-dimensional table:
02 TOTAL OCCURS 20 TIMES ...
Each reference to TOTAL must have exactly one subscript (except in SEARCH statements and some
intrinsic functions, which do not allow subscripts).
Example 14 One-Dimensional Table With Fixed Number of Elements
WORKING-STORAGE SECTION.
01 MONTH-NAME-TABLE.
05 FILLER PICTURE X(9) VALUE "January".
05 FILLER PICTURE X(9) VALUE "February".
05 FILLER PICTURE X(9) VALUE "March".
05 FILLER PICTURE X(9) VALUE "April".
05 FILLER PICTURE X(9) VALUE "May".
05 FILLER PICTURE X(9) VALUE "June".
05 FILLER PICTURE X(9) VALUE "July".
05 FILLER PICTURE X(9) VALUE "August".
05 FILLER PICTURE X(9) VALUE "September".
05 FILLER PICTURE X(9) VALUE "October".
05 FILLER PICTURE X(9) VALUE "November".
05 FILLER PICTURE X(9) VALUE "December".
01 MONTH-NAMES REDEFINES MONTH-NAME-TABLE.
05 MONTH-NAME OCCURS 12 TIMES PICTURE X(9).
One-Dimensional Tables With Variable Number of Elements
You can specify a fixed or variable number of occurrences of a table element. An element of a
table of the latter form is called a variable-occurrence data item. Because the number of elements
in such a table can vary during the execution of a program, the size of each data structure that
contains the table can also vary. Such data structures are said to have a variable size.
Data Structures 85