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

Example 15 One-Dimensional Table With Variable Number of Elements
WORKING-STORAGE SECTION.
01 ACTIVITY-TABLE-RECORD.
03 ACTIVITY-COUNT PICTURE 99.
03 ACTIVITY-TABLE OCCURS 10 TO 20 TIMES
DEPENDING ON ACTIVITY-COUNT
INDEXED BY SAVE-INX-1
SAVE-INX-2.
05 ACTIVITY-ENTRY PICTURE 999.
Multidimensional Tables
The elements of a table can be elementary items or groups of subordinate structures, some of which
can also be tables. In Example 16, TOTAL-B is a table subordinate to the 1-dimensional table
named TOTAL. This means TOTAL-B is a 2-dimensional table; each reference to TOTAL-B must have
exactly two subscripts (except in SEARCH statements and some intrinsic functions, which do not
allow subscripts). The first subscript specifies the element of the TOTAL table, and the second
subscript specifies the element of the TOTAL-B table within that element of TOTAL.
Example 16 Multidimensional Table
02 TOTAL OCCURS 20 TIMES.
03 TOTAL-A ...
03 TOTAL-B OCCURS 3 TIMES ...
A COBOL table can have a maximum of 7 dimensions. If the description of a data item T-B-S
subordinate to TOTAL-B also has an OCCURS clause, T-B-S is a 3-dimensional table.
The outermost table of a multidimensional table can be of variable size, but each subordinate table
must be of fixed size.
Data Representation
To define a language independent of computer designs, COBOL describes the structure and
representation of data in terms of a standard data format. This format represents numbers as
integers and represents noninteger and nonnumeric data as strings of characters. The amount of
computer storage space occupied by data is measured in character positions. A data item’s
description determines how many character positions it has. How data is stored depends on the
machine on which it executes.
A character position in an HP computer system is a byte: an 8-bit quantity. Data items represented
as strings of characters occupy one byte per character. HP COBOL has other data formats that do
not maintain the values of data items in characters but use forms more suitable for certain operations.
In such cases, the number of bytes into which a data item fits can differ from the number of
characters that express the value of the item.
Table 20 Allocation for COMPUTATIONAL Data Items
Byte AllocationPICTURE Size in Digits
2 bytes1 through 4
4 bytes5 through 9
8 bytes10 through 18
When an arithmetic or MOVE statement stores a value in a COMPUTATIONAL item, the number
of digits stored equals the number of 9 s in the item’s PICTURE clause. Because MOVE statements
lack the SIZE ERROR phrase, they cannot detect the loss of high-order digits.
In general, the set of bytes the compiler allocates for a record is simply the contiguous sequence
of bytes necessary to accommodate its constituent elementary data items. In some cases, however,
86 Data Fundamentals