Assignment Statement0
The assignment statement is used to assign values to attributes, local variables, global variables, and formal parameters. With respect to the definition in the EXPRESS language, the definition of the assignment statement in EDMexpressX has been enhanced with two new operators as well as the Coercion declaration.
assignment_stmt = assignment_receiver ( ':=' | '+=' | '-=' ) expression ?;? .
assignment_receiver = [ coercion ] ( global_ref | parameter_ref | general_ref { coercion_qualifier } .
coercion_qualifier = [ coercion ] qualifier .
Implicit creation of Instances and Aggregates
When the assignment statement receiver is an aggregate and the aggregate does not yet exist, the actual aggregate will implicitly be created by the assignment statement. before the result of the assignment expression will be written to the actual aggregate.
A reference path to an assignment receiver may include one or more attributes of instance type. For all such attributes that have no value assigned, the assignment statement will create an instance of the attribute domain type and connect it to the actual attribute before the result of the assignment expression is written to the assignment receiver.
Example:
SCHEMA Family;
TYPE SEX = ENUMERATION OF (MALE, FEMALE); END_TYPE;
ENTITY child;
Sex : sex;
DateOfBirth : STRING;
END_ENTITY;
ENTITY Man;
Wife : OPTIONAL Woman;
Children : OPTIONAL SET OF Child;
END_ENTITY;
ENTITY Woman;
MaidenName : STRING;
Husband : OPTIONAL Man;
Children : OPTIONAL SET of Child;
END_ENTITY;
. . .
END_SCHEMA;
SCHEMA_MAP ExampleFamily;
GLOBAL
DECLARE source INSTANCE OF SOURCE_SCHEMA SourceSchema;
DECLARE target INSTANCE OF TARGET_SCHEMA Family;
END_GLOBAL;
MAP m:target::man;
FROM (s:source::person)
WHILE TRUE;
BEGIN_MAP;
(* The following assignment statement will implicitly create an
instance of type WOMAN and connect this instance to the WIFE
attribute of the newly created map instance ?m? before the string
?Smith? is written to the MaidenName attribute of the implicitly
created WOMAN instance
*)
m.wife.MaidenName := ?Smith?;
REPEAT i := 1 TO HiIndex(p.children);
(* The following assignment statement will create an aggregate
(SET OF Child) the first time the assignment statement is
executed and connect the aggregate to the CHILDREN attribute of
the actual map instance ?m? before the result of the
assignment expression is ?added? to the aggregate.
*)
m.children ++ {target::child}p.children[i];
. . .
END_REPEAT;
. . .
END_MAP;
. . .
END_SCHEMA_MAP;