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.
A structured record has the following characteristics:

When you create a structured record, use level numbers to specify the exact layout of the record fields in storage.

The types of fields in a structured record must have a fixed length. EGL supports the following types in structure fields (structured record fields):

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

Each field in a structured record can be substructured, that is, declared as a sum of smaller fields. You assign each field an arbitrary level number, with higher level numbers indicating a substructure field. The following example defines a field that holds a telephone number:
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

The following example shows a structured record that contains another structured record as a field:
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);
end
The field Outer.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);
end

Structured records in I/O

Structured records are most often used for I/O with specific kinds of data access technologies, such as hierarchical databases, message queues, or indexed files. For the following record stereotypes, EGL assumes structured records, even if the fields do not contain level numbers:

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.


Feedback