Defining a table (OCCURS)

To code a table, give the table a group name and define a subordinate item (the table element) to be repeated n times.

About this task


01  table-name.
    05 element-name OCCURS n TIMES.
    . . . (subordinate items of the table element)

In the example above, table-name is the name of an alphanumeric group item. The table element definition (which includes the OCCURS clause) is subordinate to the group item that contains the table. The OCCURS clause cannot be used in a level-01 description.

If a table is to contain only Unicode (UTF-16) data, and you want the group item that contains the table to behave like an elementary category national item in most operations, code the GROUP-USAGE NATIONAL clause for the group item:


01  table-nameN Group-Usage National.
    05  element-nameN OCCURS m TIMES.
        10  elementN1  Pic nn.
        10  elementN2  Pic S99 Sign Is Leading, Separate.
        . . .

Any elementary item that is subordinate to a national group must be explicitly or implicitly described as USAGE NATIONAL, and any subordinate numeric data item that is signed must be implicitly or explicitly described with the SIGN IS SEPARATE clause.

To create tables of two to seven dimensions, use nested OCCURS clauses.

To create a variable-length table, code the DEPENDING ON phrase of the OCCURS clause.

To specify that table elements will be arranged in ascending or descending order based on the values in one or more key fields of the table, code the ASCENDING or DESCENDING KEY phrases of the OCCURS clause, or both. Specify the names of the keys in decreasing order of significance. Keys can be of class alphabetic, alphanumeric, DBCS, national, or numeric. (If it has USAGE NATIONAL, a key can be of category national, or can be a national-edited, numeric-edited, national decimal, or national floating-point item.)

You must code the ASCENDING or DESCENDING KEY phrase of the OCCURS clause to do a binary search (SEARCH ALL) of a table. You can use a format 2 SORT statement to order the table according to its defined keys, thereby making the table searchable by the SEARCH ALL statement. Note that SEARCH ALL will return unpredictable results if the table has not been ordered according to the keys.

Example: binary search

Related concepts  
National groups

Related references  
OCCURS clause (COBOL for Linux® on x86 Language Reference)  
SIGN clause (COBOL for Linux on x86 Language Reference)  
ASCENDING KEY and DESCENDING KEY phrases
   (COBOL for Linux on x86 Language Reference)  
SORT statement (COBOL for Linux on x86 Language Reference)