The AL developer preview is still evolving with frequent updates. Follow us on the Dynamics NAV Team Blog for the announcements.
Copies one or more elements in an array to a new array.
COPYARRAY(NewArray, Array, Position[, Length])
The array to copy to; the destination array.
The array to copy from; the source array.
The position of the first array element to copy.
The 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 method 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 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 global variables.
Array1 := 1; Array1 := 2; Array1 := 3; Array1 := 4; Array1 := 5; Array1 := 6; Array1 := 7; Array1 := 8; Array1 := 9; Array1 := 10; COPYARRAY(Array2,Array1,6,5);
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.
The error occurs because the code attempts to copy eight elements from Array1 to Array2, and Array2 has room for only five elements.