Traditionally, you copy one array to another array using a loop or nested loops to copy one array element at a time. You can also use an ASSIGN statement or Assignment (=) 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 unsubscripted references to the array objects. 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 without a size to a determinate array. That is, if an array does not yet have a size, you cannot assign it to one that does have a size.
  • You can assign any array to an indeterminate array without a size. The size of the indeterminate array is set to the size of the other array.
  • You cannot assign a scalar value to an indeterminate array without a size.

For more information, see Work with one-dimensional arrays in Basic ABL.