Structured records
Use a structured record definition when you have to match the exact layout of an external file record or have to call an external program that requires data fields to be in an exact position in a parameter buffer.
- The record has a fixed layout in storage.
- The record occupies a fixed amount of storage.
- The variable values appear at a fixed offset and length within the storage area.
When you create a structured record, use level numbers to specify the exact layout of the record fields in storage.
- Primitive types or data items with a fixed or specified length (for example, INT or CHAR(10), but not STRING)
- Other structured records, although the field is treated as CHAR type
- Arrays of any of the preceding types, with a fixed dimension
A special case of the structured record is the variable-length record, where EGL finds the information it needs to determine the record size by looking in a variable. For more information, see Variable-length records.
Substructured records
Record CustomerRecord type BasicRecord
10 phoneNumber CHAR(10);
20 areaCode CHAR(3);
20 localNumber CHAR(7);
end After you declare a variable based on this
Record part (such as myCustomer) and read information
into the variable, you can access the entire phone number as myCustomer.phoneNumber,
or you can access pieces of the phone number using dot syntax (for
example, myCustomer.phoneNumber.localNumber, or more
simply, myCustomer.localNumber).
Structured records as fields
record Outer
5 a INT;
5 b Inner; // looks like a record, but is actually CHAR
end
record Inner
10 c CHAR(10);
15 c2 CHAR(10);
10 d CHAR(10);
endOuter.b is defined
with the Inner type, referring to a record. But
the actual type for Outer.b is CHAR(20). The length
of the CHAR field is determined by the total length of the record.
The Outer record could be defined this way instead:record Outer
5 a INT;
5 b CHAR(20);
10 c CHAR(10);
15 c2 CHAR(10);
10 d CHAR(10);
endStructured records in I/O
- IndexedRecord
- RelativeRecord
- SerialRecord
- MQRecord
Best practice is to use level numbers with these records to make it clear that they are structured. For more information, see the related references at the end of this topic.