embed
The EGL embed keyword allows you to include the fields of one structured record in a second structured record without creating a substructure. An SQL record that is an I/O object for relational database access must have such a flat structure.
The only reason to use the embed keyword
in place
of a structure field name is to avoid adding a level of hierarchy.
A structure
field identified by the embed keyword has
these
restrictions:
- Can point to the format of a Record part, but not to a DataItem part
- Cannot specify an array or include a primitive-type specification
Syntax

- level
- A level number within the structured record.
- recordType
- The name from a record definition. The fields from this definition will be included at the current position and specified level.
Examples
In the following example, the keyword embed includes
all the fields from the
address record into record1: Record address type basicRecord
10 streetAddress1 CHAR(30);
10 streetAddress2 CHAR(30);
10 city CHAR(20);
end
Record record1 type serialRecord
{
fileName = "myFile"
}
10 person CHAR(30);
10 embed address;
end
The internal structure of the Record part is now
flat:
Record record1 type serialRecord
{
fileName = "myFile"
}
10 person CHAR(30);
10 streetAddress1 CHAR(30);
10 streetAddress2 CHAR(30);
10 city CHAR(20);
end
You can also use the embed keyword
to declare
identical structures in two records. The keyword does not overwrite
the properties
of those records with the properties from the embedded record:
Record common type serialRecord
{
fileName = "mySerialFile"
}
10 a BIN(10);
10 b CHAR(10);
end
Record recordA type indexedRecord
{
fileName = "myFile",
keyItem = "a"
}
embed common; // accepts the structure of common,
// not the properties
end
Record recordB type relativeRecord
{
fileName = "myOtherFile",
keyItem = "a"
}
embed common;
end
The last two Record parts are equivalent to these
declarations:
Record recordA type indexedRecord
{
fileName = "myFile",
keyItem = "a"
}
10 a BIN(10);
10 b CHAR(10);
end
Record recordB type relativeRecord
{
fileName = "myOtherFile",
keyItem = "a"
}
10 a BIN(10);
10 b CHAR(10);
end