Nat1317 error help

Hi, I hope someone can help.

For the following statement I get error Nat1317 - Array range operation on invalid ranges
Move #ws-proc-status (1:#M) to #proc-status (#fp:#lp)

When I hardcode the values I don’t get an error:
MOVE #WS-PROC-STATUS (1:1) TO #PROC-STATUS(13:14)

The second version will move one occurrence to 2 occurrences without an error.

What exactly is the error?

Thank you!

Hi, I hope it may help you :slight_smile:
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

Thank you for your quick reply!!!

#M=1, #fp = 13 and #lp = 14

The first version allows 1 → 2 but the second version only allows 1->1?
I was wondering why it was only abending in one version.

I hope
Move #ws-proc-status (1:#M) to #proc-status (#fp:#lp)
when #M = 1 will function well in the next release of Natural :slight_smile:

To my opinion, it should be legal to move (1:#M) when #M = 1, but it is just NOT implemented this way YET!

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!