Record primitiveRec type BasicRecord integerField INT; stringField STRING; charField CHAR(30); endCreating 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;
myRecVar.integerField = 6; myRecVar.stringField = "Hello"; myRecVar.charField = "Character field";
myFunction(myRecVar);
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.
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.
myRecordVar myCustomerRecordSQL; myRecordVar.customerNumber = 5; get myRecordVar; SysLib.writeStderr("Name: " + myRecordVar.customerFirstName + " " + myRecordVar.customerLastName);
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.
record structRec1 type BasicRecord 10 field1 int; 10 field2 int; 10 field3 int; end
Record CustomerRecord type BasicRecord 10 phoneNumber CHAR(10); 20 areaCode CHAR(3); 20 localNumber CHAR(7); endIn 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.”