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 one Record part:
Record primitiveRec type BasicRecord
    integerField  INT;
    stringField   STRING;
    charField     CHAR(30);
end
Creating a variable that is based on this Record part is similar to creating a variable that is based on a DataItem part or primitive:
myRecVar primitiveRec;
The record variable does not contain a value, but the fields within the record contain values. After you have a variable that is 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 functions as a single unit, so you can pass it to functions as a single parameter, for example:
myFunction(myRecVar);

Record stereotypes

You can specialize Record parts with a stereotype, as noted in “Stereotypes." To set the stereotype for a Record part, use 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 to group one or more variables 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 you create 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 example, 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: you can use the record as though it were the row in the database.

For example, the following code uses the Record part that was 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);
You can also add these stereotypes, which are used to access different files, to Record parts:
  • IndexedRecord
  • SerialRecord
  • RelativeRecord
  • CSVRecord

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 function in this way, with each field at the same level number:
record structRec1 type BasicRecord
    10 field1 int;
    10 field2 int;
    10 field3 int;
end
When you vary the level numbers, you create substructures within the record:
Record CustomerRecord type BasicRecord
  10 phoneNumber CHAR(10); 
    20 areaCode CHAR(3); 
    20 localNumber CHAR(7);
end
In this example, the areaCode and localNumber fields are subfields of the phoneNumber field. To get the value of the entire field, you can access the phoneNumber field; to get portions of the value in the phoneNumber field, you can access the areaCode or localNumber fields.

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


Feedback