Reputation: 55
D posDS ds
D pos1 2 0
D pos2 2 0
D posArr 2 0 dim(2)
C MoveA posDS posARR
In the above code I am getting RNF7262 - Factor 2 and Result field are not same type and length. Kindly assist in what going wrong as data type and size are defined correctly.
Upvotes: 0
Views: 659
Reputation: 3674
A data structure is also considered to be a character field. There isn't such a thing as a "decimal data structure".
If you want your "posArr" array to be separate from the subfields in your data structure, you would define an array within the data structure as Charles showed, and then define your other array outside the data structure. Then you could just assign the arrays using "EVAL" rather than trying to use the deprecated MOVEA opcode.
d posDs ds inz
d pos1 2 0
d pos2 2 0
d posArrDs 2 0 dim(2) samepos(pos1)
d posArr s 2 0 dim(2)
pos1 = 1;
pos2 = 2;
posArr = posArrDs; // Instead of MOVEA
return;
Upvotes: 2
Reputation: 23823
It appears you're possibly trying to access multiple "sequential" fields, perhaps originating in a table, as an array.
rather than trying to move the data, simply do the following
dcl-ds posDs;
pos1 zoned(2);
pos2 zoned(2);
posArr zoned(2) dim(2) pos(1);
end-ds;
fix format would look like
d posDs ds
d pos1 2 0
d pos2 2 0
d posArr 2 0 dim(2) overlay(posDs)
Upvotes: 2
Reputation: 1324
I believe you will need to specify which element of the array you are assigning to or from like posArr(1)
or posArr(2)
. If you are trying to assign both elements, I think it will take either two assignment statements or a loop.
Even if you fix that, you may still get a decimal data error though, because data structures in RPG are not initialized to zero. They are initialized to blanks unless you use the INZ keyword in your definition spec. This means that if you assign an uninitialized numeric field to another numeric, it will crash at runtime for writing invalid decimal data. This is easy to prevent on data structures by using INZ and is not a problem on standalone fields because the system initializes them to zero.
Upvotes: 1