Copies one or more elements in an array to a new array.

COPYARRAY(NewArray, Array, Position[, Length])



Type: ArrayThe array to copy to; the destination array.

Type: ArrayThe array to copy from; the source array.

Type: IntegerThe position of the first array element to copy.

Type: IntegerThe number of array elements to copy. If you do not specify Length, all array elements are copied from Position to the last element. Use the following equation to determine valid values.1 =< LENGTH =< MAXLEN(ARRAY) - POSITION + 1


You can only copy from one-dimensional arrays. Repeat the COPYARRAY function to copy two-dimensional and three-dimensional arrays.

You cannot copy an array if the data type of the array is a complex data type. For more information about complex data types, see C/AL Data Types.


The following example assigns values to Array1 and copies values from Array1 to Array2. Array1 is an integer array with the Dimensions Property set to 10. It contains integers from 1 to 10. The example code copies the numbers 6, 7, 8, 9, and 10 to Array2, an integer array with the Dimensions property set to 5. This example requires that you create the following variables in the C/AL Globals window.

Variable name DataType Dimension







  Copy Code
Array1[1] := 1;
Array1[2] := 2;
Array1[3] := 3;
Array1[4] := 4;
Array1[5] := 5;
Array1[6] := 6;
Array1[7] := 7;
Array1[8] := 8;
Array1[9] := 9;
Array1[10] := 10;

If Array1 is an integer array with dimension 10, and it contains the numbers from 1 to 10, and Array2 is an integer array with dimension 5, then the following command causes a run-time error.

  Copy Code

The error occurs because the code attempts to copy eight elements from Array1 to Array2, and Array2 has room for only five elements.

See Also