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 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.