4 handling tables, Handling tables – Compaq COBOL AAQ2G1FTK User Manual

Page 123

Advertising
background image

4

Handling Tables

A table is one or more repetitions of one element, composed of one or more data
items, stored in contiguous memory locations.

In this chapter you will find:

Defining tables (Section 4.1)

Initializing values of table elements (Section 4.2)

Accessing table elements (Section 4.3)

4.1 Defining Tables

You define a table by using an OCCURS clause following a data description
entry. The literal integer value you specify in the OCCURS clause determines the
number of repetitions, or occurrences, of the data description entry, thus creating
a table. Compaq COBOL allows you to define from 1- to 48-dimension tables.

After you have defined a table, you can load it with data. One way to load a table
is to use the INITIALIZE statement or the VALUE clause to assign values to the
table when you define it (see Figure 4–10).

To access data stored in tables, use subscripted or indexed procedural
instructions. In either case, you can directly access a known table element
occurrence or search for an occurrence based on some known condition.

You can define either fixed-length tables or variable-length tables, and they
may be single or multidimensional. The following sections describe how to
use the OCCURS clause and its options. For more information on tables and
subscripting, see the Compaq COBOL Reference Manual.

4.1.1 Defining Fixed-Length, One-Dimensional Tables

To define fixed-length tables, use Format 1 of the OCCURS clause (refer to the
Compaq COBOL Reference Manual). This format is useful when you are storing
large amounts of stable or frequently used reference data. Options allow you to
define single or multiple keys, or indexes, or both.

A definition of a one-dimensional table is shown in Example 4–1. The integer 2
in the OCCURS 2 TIMES clause determines the number of element repetitions.
For the table to have any real meaning, this integer must be equal to or greater
than 2.

Handling Tables 4–1

Advertising