Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Complex variables

&pagelevel(5)&pagelevel

It is possible to assign a simple value to an element of any type in a complex variable, exactly as for a simple variable.

Complex variables can also be used in assignments. The complex variables must then have the same data type on both sides of the equals sign.

When values are assigned to complex variables, in addition to the “overwrite” assignment mode (= *REPLACE), other assignment modes can also be used. These are merge
(= *MERGE) and extend (= *EXTEND or *PREFIX). However, you must note which modes can be used to link complex variables in the assignment and how these modes affect the contents of the variable elements and the structure of the complex variables.

Arrays

When values are assigned to an array as a whole, an array of the same type must also be specified on the right side of the equals sign:

/SET-VARIABLE array1 = array2

For arrays, the modes “overwrite” (WRITE-MODE = *REPLACE) and “merge” (WRITE-MODE = *MERGE) apply.

Overwrite (WRITE-MODE = *REPLACE)

First all elements of array1 are deleted. The elements of array2 are then created under the name array1 with the values from array2.

Example


/DECLARE-VARIABLE array1, MULTIPLE-ELEMENTS=*ARRAY
/DECLARE-VARIABLE array2, MULTIPLE-ELEMENTS=*ARRAY
/array1#1=1
/array2#2=2
/SET-VARIABLE array1 = array2, WRITE-MODE=*REPLACE
/SHOW-VARIABLE array1
array1#2 = 2

Merge (MODE = *MERGE)

If array1 and array2 have identical element names, “merging” and “overwriting” are also identical, i.e. array1#indexi = array2#indexi (WRITE-MODE = *MERGE has the same effect as WRITE-MODE = *REPLACE).

If array1 and array2 are not identical, “merging” has an effect only if the elements of array1 and array2 do not have the same array index.

Elements of array1 for which there is no counterpart with the same array index in array2 are not affected. They are not deleted implicitly.

If array2 contains elements for which there is no counterpart in array1, array1 is extended by these elements, i.e. the elements are placed in array1 in positions which correspond to their index.

Example


/DECLARE-VARIABLE array1, MULTIPLE-ELEMENTS=*ARRAY
/DECLARE-VARIABLE array2, MULTIPLE-ELEMENTS=*ARRAY
/array1#1 = 1
/array1#3 = 4
/array2#2 = 2
/array2#4 = 8
/SET-VARIABLE array1 = array2, WRITE-MODE=*MERGE
/SHOW-VARIABLE array1
array1#1 = 1
array1#2 = 2
array1#3 = 4
array1#4 = 8

Lists

When values are assigned to a list, the assignment mode determines what must be entered to the right of the equals sign.

For lists, the modes “overwrite” (WRITE-MODE = *REPLACE) and “extend” (WRITE-MODE = *EXTEND, WRITE-MODE = *PREFIX) apply.

Overwrite (WRITE-MODE = *REPLACE)

A list must be specified on the right side of the assignment:

/SET-VARIABLE list1 = list2, WRITE-MODE = *REPLACE

All elements of list1 are deleted. The elements of list2 are then created under the name list1 with the values of list2.

Extend (WRITE-MODE = *EXTEND)

If one or more elements are to be appended to a list, the operand WRITE-MODE = *EXTEND must be included in the SET-VARIABLE command. With WRITE-MODE = *EXTEND, an expression or another list can be assigned to a list:

/SET-VARIABLE list1 = expression, WRITE-MODE = *EXTEND
/SET-VARIABLE list1 = list2, WRITE-MODE = *EXTEND

If /SET-VARIABLE list1 = expression, WRITE-MODE = *EXTEND: list1 is extended by one element, i.e. an element is appended to list1. The results of “expression” are then assigned to this element.

If /SET-VARIABLE list1 = list2, WRITE-MODE = *EXTEND: list2 is appended to list1, i.e. the same number of elements as is contained in list2 is appended to list1. One after the other, these new elements are assigned the contents of the elements in list2.

Extend (WRITE-MODE = *PREFIX)

If one or more elements are to be added at the beginning of a list, the operand WRITE-MODE = *PREFIX must be included in the SET-VARIABLE command. With WRITE-MODE = *PREFIX, an expression or another list can be assigned to a list:

/SET-VARIABLE list1 = expression, WRITE-MODE = *PREFIX
/SET-VARIABLE list1 = list2, WRITE-MODE = *PREFIX

If /SET-VARIABLE list1 = expression, WRITE-MODE = *PREFIX: list1 is extended by one element, i.e. a new element is inserted in list1 ahead of the element that is currently first (list1 is given a new list header). This element is then assigned the value of “expression”.

If /SET-VARIABLE list1 = list2, WRITE-MODE = *PREFIX: list2 is inserted before the element of list1 that is currently the first (the list header), i.e. the same number of list elements as is contained in list2 is inserted in list1 before the list header. One after the other, these new elements are assigned the contents of the elements in list2.

Structures

When values are assigned to a structure as a whole, a structure must also be specified to the right of the equals sign:

/SET-VARIABLE structure1 = structure2

For structures, the modes “overwrite” (WRITE-MODE = *REPLACE) and “merge” (WRITE-MODE = *MERGE) apply.

Overwrite (WRITE-MODE = *REPLACE)

A distinction must be made as to whether structure1 is a static or dynamic structure:

If structure1 is a static structure, the assignment applies only to those elements of structure1 for which there are elements of the same name in structure2. The contents of the elements of structure1 are first deleted implicitly (implicit FREE-VARIABLE). The contents of the corresponding elements in structure2 are then assigned to the elements in structure1. Elements that do not have a counterpart in the other structure are ignored.

Example


/DECLARE-VARIABLE structur1(TYPE=*STRUCTURE(*BY-SYSCMD))
/BEGIN-STRUCTURE
/   DECLARE-ELEMENT A(INITIAL-VALUE='A')
/   DECLARE-ELEMENT B(INITIAL-VALUE='B')
/END-STRUCTURE
/DECLARE-VARIABLE structur2(TYPE=*STRUCTURE)
/STRUCTUR2.A='C'
/STRUCTUR2.B='D'
/STRUCTUR2.C='E'
/SET-VARIABLE structur1=structur2,WRITE-MODE=*REPLACE
/SHOW-VARIABLE structur1
STRUCTUR1.A = C
STRUCTUR1.B = D

If structure1 is a dynamic structure then, just as for arrays, an implicit FREE-VARIABLE is executed on structure1 and an element is then declared implicitly in structure1 for each element in structure2. The contents of the elements in structure2 are then assigned to these new elements in structure1.

Merge (MODE = *MERGE)

If structure1 and structure2 are identical, “merging” and “overwriting” are also identical (WRITE-MODE = *MERGE has the same effect as WRITE-MODE = *REPLACE).

If structure1 and structure2 are not identical, a distinction must again be made as to whether structure1 is a static or dynamic structure.

If structure1 is a static structure, the assignment first affects all elements of structure1 that have the same names as elements in structure2, just as it did in overwriting. The contents of these elements in structure2 are then assigned to the elements in structure1. However, if structure2 contains further elements, structure1 is not extended.

If structure1 is a dynamic structure, an element is declared implicitly in structure1 for each element in structure2. The contents of the elements in structure2 are then assigned to these new elements in structure1. (WRITE-MODE = *MERGE does not have the same effect as WRITE-MODE = *REPLACE.). Elements of structure1 that do not have a counterpart in structure2 are not affected. The contents of the elements in structure2 are assigned to the elements of structure1 which have counterparts in structure2.

Example

/DECLARE-VARIABLE STRUCTUR1(TYPE=*STRUCTURE(*DYNAMIC))
/STRUCTUR1.A='A'
/STRUCTUR1.B='B'
/STRUCTUR1.D='X'
/DECLARE-VARIABLE STRUCTUR2(TYPE=*STRUCTURE)
/STRUCTUR2.A='C'
/STRUCTUR2.B='D'
/STRUCTUR2.C='E'
/SET-VARIABLE STRUCTUR1=STRUCTUR2,WRITE-MODE=*MERGE
/SHOW-VARIABLE STRUCTUR1
STRUCTUR1.A = C
STRUCTUR1.B = D
STRUCTUR1.D = X
STRUCTUR1.C = E
/SHOW-VARIABLE STRUCTUR2
STRUCTUR2.A = C
STRUCTUR2.B = D
STRUCTUR2.C = E