Try OpenEdge Now
skip to main content
ABL Data Types Addenda
Arrays : Deep copying arrays
 

Deep copying arrays

Traditionally, you copy one array to another array using a loop or nested loops to copy one array element at a time. In Release 10.2A, you can also use an ASSIGN statement to deep copy (clone) one array to another, where it makes semantic sense to do so. This process copies all elements of one array into memory and then copies the data to the target array. Therefore, deep copying may not be practical for very large arrays. For deep copies, use an ASSIGN statement and unsubscripted references to the array object. For example:
DEFINE VARIABLE firstArray AS INTEGER EXTENT 3.
DEFINE VARIABLE secondArray AS INTEGER EXTENT 3.

ASSIGN firstArray[1] = 100
       firstArray[2] = 200
       firstArray[3] = 300.

ASSIGN secondArray = firstArray.
When deep copying one array to another, the following rules apply:
*If both the array on the left-hand side and the right-hand side of the assignment are determinate arrays, the EXTENT size must match or the AVM raises an error.
*You cannot assign an indeterminate array to a determinate array. That is, if an array does not yet have a fixed size, you cannot assign it to one that does have a fixed size.
*You can assign any array to an indeterminate array and the indeterminate array is fixed at the size of the other array.
*You cannot assign a scalar value to an indeterminate array.
For more information, see the ASSIGN statement reference entry in OpenEdge Development: ABL Reference.