Be careful if you reference a complex-ODO index name (an index name for a table with variable-length elements) after having changed the value of the ODO object for a subordinate data item in the table. When you change the value of an ODO object, the byte offset in an associated complex-ODO index is no longer valid because the table length has changed. Unless you take precautions, you will obtain unexpected results if you then code a reference to the index name such as in the following:
To avoid this type of error, do the following:
The following code shows how to save and restore the index name shown in Appendix H. Complex OCCURS DEPENDING ON when the ODO object COUNTER-2 changes.
77 INTEGER-DATA-ITEM-1 PIC 99.
...
SET INDX TO 5.
* INDX is valid at this point.
SET INTEGER-DATA-ITEM-1 TO INDX.
* INTEGER-DATA-ITEM-1 now has the
* occurrence number corresponding to INDX.
MOVE NEW-VALUE TO COUNTER-2.
* INDX is not valid at this point.
SET INDX TO INTEGER-DATA-ITEM-1.
* INDX is now valid, containing the offset
* corresponding to INTEGER-DATA-ITEM-1, and
* can be used with the expected results.