Assigning a Data Set variable to another Data Set variable

Data Set variables are assigned using the SET statement.

SET destination -> source         (* Creates a reference *)
SET destination -> NEW source (* Creates a copy *)

Assigning a variable Data Set to another variable Data Set will create a reference to the source Data Set; no data is copied. All instances of a reference access the same set of content members and changes will affect both variables equally. Both the source variable Data Set and destination variable Data Set must have the same type.

The optional statement NEW forces ITP to copy all content from the source Data Set instead of creating a reference. Any subsequent changes to either the source variable Data Set or the destination variable Data Set will only affect that variable, and not affect the other variable.

Example

DECLARE pol DEFINED_AS Policy
DECLARE customer DEFINED_AS Relation
DECLARE someone_else DEFINED_AS Relation
...
ASSIGN customer.CustomerNumber := 42
ASSIGN someone_else.CustomerNumber := 1
SET pol.Insured -> customer

Creates a reference between the customer variable and the Insured member of the pol variable. Both customer.CustomerNumber and pol.Insured.CustomerNumber share the same content and have the value 42.

ASSIGN pol.Insured.CustomerNumber := 100

Because of the reference both customer.CustomerNumber and pol.Insured.CustomerNumber now have the value 100.

SET pol.Insured -> NEW someone_else

Copy the content of the variable someone_else to pol.Insured. The existing reference is overwritten by this copy and does not affect the variable customer.

ASSIGN pol.Insured.CustomerNumber := 123456

Since there is no reference anymore the assignment to pol.Insured only affects its own content. customer.CustomerNumber still has the value 100. Because of the copy someone_else.CustomerNumber is also unaffected and retains the value 1.

The statement SET can be used to create references to Data Set members within a larger variable Data Set and access these structures directly.

Example

FOR i FROM 1 UPTO length_struct_array (life_insurance.Benificiaries) DO
DECLARE ben
SET ben -> life_insurance.Benificiaries[i]
...
ASSIGN ... := ... ben.CustomerNumber ...
ASSIGN ben.Person := ...
...
OD

This code loops through all elements of the member array Beneficiaries and assigns them one by one to the variable ben. Since ben is assigned as a reference it functions as an alias for the current element in the Beneficiaries member. Any changes to ben will also effect the current element.

The declaration of the variable ben does not need an explicit type because this can be derived from the subsequent statement SET.

Example

DECLARE senior
FOR i FROM 1 UPTO length_struct_array (life_insurance.Benificiaries) DO
IF life_insurance.Beneficiaries[i].Age > senior.Age THEN
SET senior -> life_insurance.Beneficiaries[i]
FI
OD
...

This loop selects the most senior element from the Beneficiaries array for further processing.