Hi all!
I am struggling with the function 'CopyArray'.
Documentation describes:
"Use this function to copy one or more elements in an array to a new array."
The Example is:
"If array1 is an integer array with dimension 10, and it contains the numbers from 1 to 10, the following command copies the numbers 6,7,8,9,10 to array2, an integer array with dimension 5:
COPYARRAY (array2,array1,6,5);"
In my case array1 has dimension 8 and array2 has dimension 12.
All I want is to copy all elements of array1 to array 2.
I tried this:
COPYARRAY(array2,array1,1);
And got this message:
"Array dimensions should be identical."
Also this did not work:
COPYARRAY(array2,array1,1,8);
What do I overlook?!
Please help me!
Gerald
0
Comments
b array = 12
a array = 8
i=integer
I am going to copy 8 elements from the 12 array to the 8 array with this instruction
or
and this returns error
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
RIS Plus, LLC
I disagree. Based on the example provided in Help the array dimensions clearly do NOT have to be identical:
It's a very bad error message that doesn't tell you what the actual problem is.
I agree with you mattrax...the error is somewhat misleading...i've never used this function a lot, and at the beginning i also tought it was a bug...and as you can see in my previous post, it's not immediate to solve this problem (at least for me :whistle: )
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
He's trying to put 8 elements into an array of 12, which fails because they do not have the same number of elements, the message is crystal clear to me. The example you are quoting there is copying an array of 5 (5 elements starting with element number 6) into an array of 5, which has the same number of elements. Granted the source array has 10 elements, but the command only tries to copy 5 elements into an array of 5 elements. It's a whole nother discussion as to why they wouldn't allow a small array to be copied into a larger array, but the message itself is very clear to me.
It's clear that the COPYARRAY command doesn't work, so program a little loop and you're done.
RIS Plus, LLC
maybe not exactly in the way you expect, but it works!
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
Here's the syntax for COPYARRAY:
COPYARRAY(NewArray, Array, Position [, Length])
The last parameters is Length. If you have a 10 element array, and you want to copy 5 of its elements into a 5 element array, you specify length as 5, just like the example that specified Position=6 and Length=5 to copy into a 5 element array. At that moment, your target as well as your source are both 5 elements, and COPYARRAY will work. It doesn't look at the actual source array, but at the 5 elements you're providing.
Apparently the command doesn't like it when your source array has fewer elements than the target array, it just needs identical numbers of elements. It wants you to provide as many elements as the target array.
It works exactly the way that I expect it to work, and the message is crystal clear to me. It means that if you want to copy x elements into an array that has more than x elements, you're going to have to loop through the elements in C/AL code and assign them that way.
RIS Plus, LLC
RIS Plus, LLC
about the error: you have two array of 5 elements, then you fill only the first 4 of the first array.
then you use the copyarray function to move the elements to the 2nd array and BANG!error...
the first thing I think is to take a look to array dimensions, which are the same...after that...what I have to do if i follow the error as is?
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
forget copyarray it not working as documented, use your own, its pretty simple:
FOR i := 1 TO ARRAYLEN(OriginalArray) DO
NewArray := OriginalArray;