ILE COBOL Language Reference


Appendix H. Complex OCCURS DEPENDING ON

Complex OCCURS DEPENDING ON (ODO) is supported as an extension to the COBOL 85 Standard.

The basic forms of complex ODO permitted by the compiler are as follows:

Complex ODO can help you save disk space, but it can be tricky to use and can make maintaining your code more difficult.

The following example illustrates the possible types of occurrence of complex ODO:

01  FIELD-A.
    02 COUNTER-1                             PIC S99.
    02 COUNTER-2                             PIC S99.
    02 TABLE-1.
       03 RECORD-1 OCCURS 1 TO 5 TIMES
                   DEPENDING ON COUNTER-1    PIC X(3).
    02 EMPLOYEE-NUMBER                       PIC X(5). (1)
    02 TABLE-2 OCCURS 5 TIMES                          (2 3)
               INDEXED BY INDX.                        (4)
       03 TABLE-ITEM                         PIC 99.   (5)
       03 RECORD-2 OCCURS 1 TO 3 TIMES
                   DEPENDING ON COUNTER-2.
          04 DATA-NUM                        PIC S99.

In the example, COUNTER-1 is called an ODO object because it is the object of the DEPENDING ON clause of RECORD-1. RECORD-1 is called an ODO subject. Similarly, COUNTER-2 is the ODO object of the corresponding ODO subject, RECORD-2.

The types of complex ODO occurrences shown in the example above are as follows:

(1)
A variably located item: EMPLOYEE-NUMBER is a data item following, but not subordinate to, a variable-length table in the same level-01 record.
(2)
A variably located table: TABLE-2 is a table following, but not subordinate to, a variable-length table in the same level-01 record.
(3)
A table with variable-length elements: TABLE-2 is a table containing a subordinate data item, RECORD-2, whose number of occurrences varies depending on the content of its ODO object.
(4)
An index name, INDX, for a table with variable-length elements.
(5)
An element, TABLE-ITEM, of a table with variable-length elements.

The length of the variable portion of each record is the product of its ODO object and the length of its ODO subject. For example, whenever a reference is made to one of the complex ODO items shown above, the actual length, if used, is computed as follows:

You must set every ODO object in a group before you reference any complex ODO item in the group. For example, before you refer to EMPLOYEE-NUMBER in the code above, you must set COUNTER-1 and COUNTER-2 even though EMPLOYEE-NUMBER does not directly depend on either ODO object for its value.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]