Hi, I hope it may help you
When you do
MOVE #WS-PROC-STATUS (1:1) TO #PROC-STATUS(13:14) ,
you are moving the first item of #WS-PROC-STATUS to the 13 and 14 occurrences of #PROC-STATUS; well, it is easy.
However, when you do Move #ws-proc-status (1:#M) to #proc-status (#fp:#lp), you must make sure (and apparently it is NOT the case because you are getting Nat1317) that
a) ether #M = 1
b) or #M = #LP - #FP + 1, e.g. you are moving the same number of items from the first array to the second
I would not hold my breath hoping that MOVE #WS-PROC-STATUS (1:#M) TO #PROC-STATUS (#FP:#LP) when #M = 1 will ever work. When we catalog Natural code, the compiler converts our statements into object code and makes the code as efficient as possible.
So, when you write MOVE #A (1:1) TO #B (#X:#Y) it knows that you are moving one occurrence to one or many occurrences, so it converts it to the equivalent of a for loop moving #A(1) to #B(n) – for n = #X to #Y.
When you write MOVE #A (1:#Z) TO #B (#X:#Y), Natural must assume that the two sub-arrays are identical in size so it builds to code to move the sub-array of #A to the appropriate sub-array of #B.
You are asking a bit much of Natural. Basically you are expecting Natural to assume that if #Z is 1, then move occurrence 1 of #A to every occurrence of #B between #X and #Y, otherwise, move the occurrences 1:#Z of #A to #X:#Y of #B. If that is really what you want, then write it that way.
IF #M = 1
MOVE #WS-PROC-STATUS (1) TO #PROC-STATUS (#FP:#LP)
ELSE
MOVE #WS-PROC-STATUS (1:#M) TO #PROC-STATUS (#FP:#LP)
END-IF
MOVE statement syntax allows you to copy a scalar to many target variables.
MOVE #SCALAR TO #PROC-STATUS(13) #PROC-STATUS(14)
or
MOVE #SCALAR TO #PROC-STATUS(13:14)
When you specify a single occurrence of an array, it is the same as for a scalar.
MOVE #WS-PROC-STATUS (1:1) TO #PROC-STATUS(13:14)
If you acre MOVEing multiple occurrences of one array to another, the number of occurrences must be the same on either side of the TO; Natural moves individual occurrences to corresponding target positions.
MOVE #WS-PROC-STATUS (1:2) TO #PROC-STATUS(13:14)
In the examples above, the Natural compiler knows what to do because all the indexes are specified as literals. If you introduce variables, then an error message is issued if the compiler cannot determine if the number of occurrences match. This is true even if your logic guarantees that the occurrences will be correct at execution time.
MOVE #WS-PROC-STATUS (1:#M) TO #PROC-STATUS(#FP:#LP)
#FP and #LP specify two occurrences, but what if #M was 5?
There are two cases where non-literals can be used, one using constants, the other using simple arithmetic.
1 #M (I4) CONST <1>
MOVE #WS-PROC-STATUS (1:#M) TO #PROC-STATUS(#FP:#LP) /* single occurrence of #WS-PROC-STATUS
MOVE #WS-PROC-STATUS(#FP:#LP) TO #PROC-STATUS(#FP:#LP) /* same range
MOVE #WS-PROC-STATUS(#FP:#LP) TO #PROC-STATUS(#FP+2:#LP+2) /* same count
Thank you so much for the replies!!! I like understanding what is happening!!.
Something is wrong with the logic of the program in a certain situation, and it is trying to move one occurrence to two occurrences. But when I tried to hardcode the occurrences it worked so I wasn’t sure what the error was.
Now on to figuring out why this is happening!