Inline DATASTRUCTURE definitions
Nested Data Structure members can also be defined inline in a Data Structure. These inline definitions define a member but cannot be used to define Data Structure variables. To declare an inline Data Structure, the definition can be placed in the statement DATASTRUCTURE.
DATASTRUCTURE Member BEGIN ... END
ARRAY DATASTRUCTURE Member [0] BEGIN ... END
MAP DATASTRUCTURE Member BEGIN ... END
Inline Data Structure member definitions can also be nested in another inline definition. The following example defines a Data Structure type Array2d that functions as a 2-dimensional array.
DATASTRUCTURE Array2d
BEGIN
ARRAY DATASTRUCTURE D [0]
BEGIN
ARRAY DATASTRUCTURE D [0]
BEGIN
TEXT T
END
END
END
The dimensions are implemented using the D-member arrays, the content is accessed in the T-member.
DECLARE my_grid DEFINED_AS Array2d
ASSIGN my_grid.D[4].D[8].T := "This is element[4][8]"
The inline Data Structure members function as Data Structure variables do but they can only be copied between variables of their parent Data Structure type.
SET my_grid.D[1] -> NEW my_grid.D[18] (* OK - copy *)
SET my_grid.D[2] -> reference_grid.D[1024] (* OK - reference *)
SET my_grid.D[3] -> my_grid.D[11].D[4] (* Different definitions: not
allowed *)
You can use Inline DATASTRUCTURE definitions as types by specifying the path to the definition.
In the following example, the member AnotherOne has the same structure as the member One that includes the member Two. The member AnotherTwo is a copy of the member's structure Two.
DATASTRUCTURE Example
BEGIN
DATASTRUCTURE One
BEGIN
DATASTRUCTURE Two
BEGIN
TEXT T
END
END
Example.One AnotherOne
Example.One.Two AnotherTwo
END
DECLARE full_struct DEFINED_AS Example
DECLARE two_sub_struct DEFINED_AS Example.One.Two
SET full_struct.One.Two -> two_sub_struct