Copying arrays

Arrays can be copied to other arrays in different ways.

The .* notation

The compiler allows the .* notation to assign an array to another array with the same structure.

Static array elements are copied by value (except objects and LOB members), while elements of dynamic arrays are copied by reference.

This means that after assigning a dynamic array with the .* notation, if you modify an element in one of the arrays, the change will be visible in the other array. You must pay attention to this behavior if you are used to the .* notation for simple records:

MAIN
  DEFINE left, right DYNAMIC ARRAY OF RECORD
             key INTEGER
         END RECORD
  LET left[1].key = 123
  LET right.* = left.*
  DISPLAY right[1].key    -- shows 123
  LET right[1].key = 456
  DISPLAY left[1].key    -- shows 456
END MAIN

The copyTo() method

A dynamic array can be copied to another dynamic array with the copyTo() method. The source and destination array must be defined with the same type:
DEFINE source, destination DYNAMIC ARRAY OF RECORD
           key INT,
           name STRING
       END RECORD
CALL source.copyTo( destination )