Compaq COBOL AAQ2G1FTK User Manual

Page 128

Advertising
background image

Handling Tables
4.1 Defining Tables

It uses from two to four occurrences depending on the integer value assigned
to NUM-ELEM. You specify the table’s minimum and maximum size with the
OCCURS (minimum size) TO (maximum size) clause. The minimum size value
must be equal to or greater than zero and the maximum size value must be
greater than the minimum size value. The DEPENDING ON clause is also
required when you use the TO clause.

The data-name of an elementary, unsigned integer data item is specified in the
DEPENDING ON clause. Its value specifies the current number of occurrences.
The data-name in the DEPENDING ON clause must be within the minimum to
maximum range.

Unlike fixed-length tables, you can dynamically alter the number of element
occurrences in variable-length tables.

By generating the variable-length table in Example 4–6, you are, in effect, saying:
‘‘Build a table that can contain at least two occurrences, but no more than four
occurrences, and set its present number of occurrences equal to the value specified
by NUM-ELEM.’’

Example 4–6 Defining a Variable-Length Table

01

NUM-ELEM PIC 9.

.
.
.

01

VAR-LEN-TABLE.
05

TAB-ELEM OCCURS 2 TO 4 TIMES DEPENDING ON NUM-ELEM.
10 A PIC X.
10 B PIC X.

4.1.4 Storage Allocation for Tables

The compiler maps the table elements into memory, following mapping
rules that depend on the use of COMP, COMP-1, COMP-2, POINTER, and
INDEX data items in the table element, the presence or absence of the
SYNCHRONIZED (SYNC) clause with those data items, and the

-align

flag

(on the Tru64 UNIX operating system) or the /ALIGNMENT qualifier (on the
OpenVMS Alpha operating system).

The Compaq COBOL compiler allocates storage for data items within records
according to the rules of the Major-Minor Equivalence technique. This technique
ensures that identically defined group items have the same structure, even when
their subordinate items are aligned. Therefore, group moves always produce
predictable results. For more information, refer to the description of record
allocation in the Compaq COBOL Reference Manual.

Note

To determine exactly how much space your tables use, specify the

-map

flag (on Tru64 UNIX), or the /MAP qualifier (on OpenVMS Alpha). This
gives you an offset map of both the Data Division and the Procedure
Division.

4–6 Handling Tables

Advertising