lengthItem

The lengthItem property identifies a field that is used when EGL reads or writes a variable length record.
Use the lengthItem property with one of the following stereotypes only:

EGL sets the field when it reads from a file into the record, and uses the field to determine how many bytes to write to the file. The maximum length for the record is based on the fields defined for the record. When a variable-length record is written to a file, the value in the field specified by lengthItem must be less than or equal to the maximum length.

The length field can be any of the following variables:

The length field is an integer of no more than 9 digits.

When you use a variable-length record, you must specify the lengthItem property, or the numElementsItem property, or both. If both properties are present when EGL writes the record to the file, it uses the numElementsItem field to calculate the total length of the record, and then places that length in the variable specified by lengthItem before writing the record. For more information, see Variable-length records.

Example

The following example shows a variable-length Record part with a lengthItem property that points to a variable outside the record:
  Record SerialRecordPart1 type serialRecord
    {
      fileName = "myFile",
      lengthItem = myOtherField
    }
    10 myField01 BIN(4);   // 2 bytes long
    10 myField02 NUM(3);   // 3 bytes long
    10 myField03 CHAR(20); // 20 bytes long
  end

myOtherField NUM(4);
When you write a record, the value of the length field must match field boundaries, unless the last field is a character field. For example, a record of type SerialRecordPart1 can have the length field, myOtherField, set to any of the following values:
2
The written record contains myField01 only.
5
The written record contains myField01 and myField02.
6-25
The written record contains myField01, myField02, and some portion of myField03.

Compatibility

Table 1. Compatibility considerations for lengthItem
Platform Issue
DL/I The lengthItem variable contains the name of the field in the DL/I segment that contains the length of the entire segment, including the field itself. You must specify the lengthItem if the segment has a variable length. The field must be a SMALLINT and have the same length and offset as the length field in the segment in the DL/I database description.

The field that lengthItem points to is usually the first field in the segment. However, this is not the case when a concatenated segment in a logical database is built from a fixed-length segment followed by a variable-length segment.

WebSphere® MQ When a program adds the record to a message queue, the message length is set equal to the value in the variable that the lengthItem property specifies. When a program reads the message from the queue, the message length is returned in the variable specified by the lengthItem property. If you specify variable names for both the lengthItem and the numElementsItem properties, the lengthItem variable is set to the length calculated from the number of elements in the record before a message is added to the queue.

For other platform and resource association issues, see the "Compatibility" section of numElementsItem.


Feedback