Introduction to Record parts

Record parts are collections of other data parts. The data parts within the Record part are called fields. A Record part can contain any number of fields; the fields can be primitives, data items, or other records.
A simple Record part is a group of other data parts. In this example, three different primitives are grouped into a single Record part:
Record primitiveRec type BasicRecord
    integerField  INT;
    stringField   STRING;
    charField     CHAR(30);
end
Creating a variable based on this Record part is similar to creating a variable based on a DataItem part or primitive:
myRecVar primitiveRec;
The record variable itself does not contain a value, but the fields within the record do contain values. After you have a variable based on a Record part, you can access the fields within the record as though they were individual variables:
myRecVar.integerField = 6;
myRecVar.stringField = "Hello";
myRecVar.charField = "Character field";
However, the record still behaves as a single unit, so you can pass it to functions as a single parameter, for example:
myFunction(myRecVar);

Record stereotypes

Record parts can be specialized with a stereotype (see Stereotypes. You set the stereotype for a Record part with the type keyword, as in this example of a Record part with the stereotype BasicRecord:
Record myCustomerRecord type BasicRecord
    customerNumber     INT;
    customerFirstName  STRING;
    customerLastName   STRING;
    customerBalance    FLOAT;
end

The BasicRecord stereotype denotes a general-purpose Record part. You can use this stereotype when you want to group one or more variables together for simplicity.

Because Record parts typically represent records or other groups of related data in a data source, the other stereotypes that you can apply specialize a Record part for use with a particular kind of data source. For example, the SQLRecord stereotype adapts the Record part for use with a SQL database. When creating a Record part of this type, use properties to link the record and its fields to the database table and its columns:
Record myCustomerRecordSQL type SQLRecord
    { tableNames = [["Customer"]], keyItems = [customerNumber] }
    customerNumber     int     {column = "CustomerID"};
    customerFirstName  string  {column = "FirstName"};
    customerLastName   string  {column = "LastName"};
end
In this case, the record is linked to a database table named Customer that has columns named CustomerID, FirstName, and LastName. When you link a record to a database table like this, EGL can use this information to access the database based on your interactions with the record. In simple terms, you can use the record as though it were the row in the database.
For example, the following code uses the Record part defined in the previous example to retrieve a specific row from the database:
myRecordVar myCustomerRecordSQL;
myRecordVar.customerNumber = 5;
get myRecordVar;
SysLib.writeStderr("Name: " +
    myRecordVar.customerFirstName + " " +
    myRecordVar.customerLastName);

Other stereotypes that you can add to Record parts include IndexedRecord, SerialRecord, RelativeRecord, and CSVRecord, which are used for accessing different types of files.

Structured records

Record parts can be structured to provide more detail about the layout and organization of their fields. In a structured record, each field is assigned a level number, an arbitrary number that indicates the relationship of that field to other fields.

The fields in unstructured records do not have level numbers, so each field is considered to be at the same level. Structured records can also behave this way, with each field at the same level number:
record structRec1 type BasicRecord
    10 field1 int;
    10 field2 int;
    10 field3 int;
end
Varying the level numbers creates substructures within the record:
Record CustomerRecord type BasicRecord
  10 phoneNumber CHAR(10); 
    20 areaCode CHAR(3); 
    20 localNumber CHAR(7);
end
In this case, the fields areaCode and localNumber are subfields of the field phoneNumber. You can access the phoneNumber field to get the entire value of the field, or you can access the areaCode or localNumber fields to get a portion of the value held in the phoneNumber field.

Structured records are limited to fields with fixed lengths. For more information on the limitations and uses of structured record, see Records.


Feedback