Support for variable-length arrays

A variable-length array is defined in a COBOL copybook by an OCCURS DEPENDING ON (ODO) clause, and in a PL/I copybook by a dimension attribute where the lower or upper bounds (or both) are defined by REFER options.

Note: Variable-length segments begin with a 2-byte binary numeric size field. So, in a layout for a variable-length segment, the first elementary item must be a 2-byte binary numeric field.

The following considerations apply when using layouts that contain variable-length arrays:

  • Only use variable-length arrays in layouts for variable-length segment types.
  • A layout can contain multiple variable-length arrays, however, the fields that define the size of the arrays (the ODO or refer objects) must all be in the layout before the first variable-length array item.
  • When browsing or editing a database, if either of the following conditions is true, the Cmd field for the segment contains the tag =LG, indicating that the segment length is incorrect for its layout.
    • (COBOL copybook only.) The object is out of the range specified by the ODO clause.
    • The actual length of a segment does not match the calculated length of a segment with the number of array items specified by the object.
  • In SNGL or TABL display format:
    • If you change the value of an object field, then the number of items in the array expands or contracts automatically, and the value of the size field (the 2-byte binary numeric field at the start of a variable-length segment) is adjusted to match the new segment length.

      New items are inserted at the end of the current array (and before any fields that follow the array); numeric items are initialized to zero and alphanumeric items are initialized to blanks.

      Similarly, items are deleted from the end of the array, and any fields subsequent to the end of the array are not affected.

      For PL/I, the number of items in an array is determined by subtracting the lower bound of the dimension attribute from the upper bound. If both the lower and upper bounds are specified using REFER options, then changing the value of either of the refer object fields inserts or deletes array items accordingly.

    • (COBOL copybook only.) You cannot change the object field to a value outside the range specified by the ODO clause. (FM/IMS supports an ODO lower value of 0.)
    • (COBOL copybook only.) Inserting a new segment results in a segment with the minimum number of array items specified by the ODO definition. For example:
      • Given the following ODO clause, when you insert a new segment, the ODO-CNTRL-ONE field is initialized to zero and there are no ODO-ONE array items in the new segment:
        ODO-ONE OCCURS 0 TO 10 TIMES DEPENDING ON ODO-CNTRL-ONE.
      • Given the following ODO clause, then ODO-CNTRL-ONE is initialized to 5, and there are five ODO-ONE array items in the new segment.:
        ODO-ONE OCCURS 5 TO 7 TIMES DEPENDING ON ODO-CNTRL-ONE.
    • (PL/I copybook only.) Inserting a new segment results in a segment with zero array items. Upper and lower bound refer object fields are initialized to zero.
  • In CHAR, HEX or LHEX display format, changing the value of an object field does not change the segment length. In these display formats, changing the value of an object field can result in a mismatch between the object field value and the calculated length of the segment with that many array items.