{"title":"System.CopyArray(Array of [Any], Array of [Any], Integer [, Integer]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/system/system-copyarray-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/system/system-copyarray-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/system/system-copyarray-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Copies one or more elements in an array to a new array.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"System.CopyArray(Array of [Any], Array of [Any], Integer [, Integer]) Method","slug":"systemcopyarrayarray-of-any-array-of-any-integer-integer-method","at":0,"chars":2401},{"level":2,"title":"Syntax","slug":"syntax","at":195,"chars":201},{"level":2,"title":"Parameters","slug":"parameters","at":396,"chars":509},{"level":2,"title":"Remarks","slug":"remarks","at":905,"chars":297},{"level":2,"title":"Example 1","slug":"example-1","at":1202,"chars":689},{"level":2,"title":"Example 2","slug":"example-2","at":1891,"chars":376},{"level":2,"title":"Related information","slug":"related-information","at":2267,"chars":134}],"text":"# System.CopyArray(Array of [Any], Array of [Any], Integer [, Integer]) Method\n> Version: _Available or changed with runtime version 1.0._\nCopies one or more elements in an array to a new array.\n## Syntax\n```al\n System.CopyArray(NewArray: Array of [Any], Array: Array of [Any], Position: Integer [, Length: Integer])\n```\n> NOTE\n> This method can be invoked without specifying the data type name.\n## Parameters\nNewArray\nType: ../any/any-data-type\nThe array to copy to; the destination array.\nArray\nType: ../any/any-data-type\nPosition\nType: ../integer/integer-data-type\nThe position of the first array element to copy.\n*[Optional] Length*\nType: ../integer/integer-data-type\nThe 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.\n1 =\\< LENGTH =\\< MAXLEN(ARRAY) - POSITION + 1\n## Remarks\nYou can only copy from one-dimensional arrays. Repeat the CopyArray method to copy two-dimensional and three-dimensional arrays.\nYou 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<../library>.\n## Example 1\nThe following example assigns values to Array1 and copies values from Array1 to Array2. Array1 is an integer array with the Dimensions Property<../../properties/devenv-properties> 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.\n```al\nvar\n    Array1: array[10] of Integer;\n    Array2: array[5] of Integer;\nbegin\n    Array1[1] := 1;\n    Array1[2] := 2;\n    Array1[3] := 3;\n    Array1[4] := 4;\n    Array1[5] := 5;\n    Array1[6] := 6;\n    Array1[7] := 7;\n    Array1[8] := 8;\n    Array1[9] := 9;\n    Array1[10] := 10;\n    COPYARRAY(Array2,Array1,6,5);\nend;\n```\n## Example 2\nIf 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.\n```al\nCopyArray(Array2,Array1,3);\n```\nThe error occurs because the code attempts to copy eight elements from Array1 to Array2, and Array2 has room for only five elements.\n## Related information\nsystem-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}