Re: The MOVE problem



On 30 Oct 2007 19:43:50 GMT, billg999@xxxxxxxxxxx (Bill Gunshannon) wrote:

In article <5dLVi.57745$c9.57091@xxxxxxxxxxxxxxxxxxxxxx>,
"Judson McClendon" <judmc@xxxxxxxxxxxxx> writes:
"Bill Gunshannon" <billg999@xxxxxxxxxxx> wrote:
Robert <no@xxxxxx> writes:
"Roger While" <simrw@xxxxxxxxxxxx> wrote:

IDENTIFICATION DIVISION.
PROGRAM-ID. MOVEX.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 AA.
03 A PIC 9 OCCURS 9.
01 CC.
03 C PIC 9 OCCURS 9.
01 B PIC 9.
PROCEDURE DIVISION.
MOVE "987654321" TO AA.
MOVE "123456789" TO CC.
MOVE 3 TO B.
MOVE A(B) TO B C(B).
DISPLAY CC.
DISPLAY B.
GOBACK.

What shouzld be displayed in various compatible modes?

123456789
7

I got:

123456389
7

which is about what I expected, but I am not sure that the correct
answer isn't compiler dependant. Does the standard address actual
order of execution for things like this? Or side effects?

Net Express 3.1:

123456789
7

I think the subscripts should properly be calculated before the MOVE,
as Net Express apparently does here.

That was what I meant by my question. Does the standard say that all
expressions shold be evaluated before the MOVE? Or shoud expressions
be evaluated as you progress thru the statement? Or, (and not having
read the standard this is what I would have expected based on their
handling of other items) is it un-defined and therefore left up to the
mplementor?

The Standard says data is copied to receiving fields "in the order specified."
In other words
MOVE A(B) TO B C(B)
is the same as
MOVE A(B) TO B
MOVE A(B) TO C(B)

The same goes for arithmetics with multiple receiving items. Fujitsu gives this example:

More Than One Arithmetic Result
An arithmetic statement can contain one or more resultant identifiers (data items to
contain results). In this case, the results of an arithmetic statement are computed as
follows:
1. In a statement, all data items to be initially evaluated are computed as required.
The result is stored in a temporary data item.
2. The temporary data item obtained in (1) is computed for each resultant
identifier, and the results are stored. This computation is done in the order in
which the identifiers are specified (from left to right).
An example of obtaining more than one result is shown below. temp indicates a
temporary storage field created by the compiler.

Example 1:
?ADD a b c TO c d(c) e? is computed as follows:
ADD a b c GIVING temp
ADD temp TO c
ADD temp TO d(c)
.... The value of c was changed by the preceding addition.
ADD temp TO e

Example 2:
?MULTIPLY a(i) BY i a(i)? is computed as follows:
MOVE a(i) TO temp
MULTIPLY temp BY i
MULTIPLY temp BY a(i)
.