Hi Anthony;
“Note by the way that the code is not moving the data in the array,”
True, but the SORT is changing the array.
Take a look at Page 1 and Page 3 of output. They are both displaying #NAME (1:10), before and after the SORT. The names are not in the same order. There are even duplicates in the page 3 list.
What I missed the first time around was noting that even page 2 output was incorrect; look at the duplicate of ADAM.
Here is the problem with having the subscripted array in the SORT.
Suppose I have the following code:
READ (10) MYVIEW
:::
END-ALL
SORT BY NAME USING CITY COUNTRY
DISPLAY NAME CITY COUNTRY
END-SORT
Natural reads a record from Adabas; processes the record, then creates a “spin-off” record to be used by the sort. After processing all ten records, the spin off file looks like:
NAME-1 CITY-1 COUNTRY-1
NAME-2 CITY-2 COUNTRY-1
:::::::::::::::::::::::::::::::::
NAME-10 CITY-10 COUNTRY-10
Natural now sorts the spinoff file. Now takes the first spinoff record and places it in the memory locations MYVIEW.NAME MYVIEW.CITY MYVIEW.COUNTRY. etc.
The point is that the values from the spinoff record are being placed in memory locations.
Okay, on to the code that doesn’t quite do what one expects:
SORT BY #NAME (#S) USING #S
the spinoff part is easy. The spinoff file correctly has values 1…10 for #S and the appropriate names from #NAMES.
Now the fun part. After the sort, Natural takes the first entry in the spinoff file, which would be ADAM 1, and puts the 1 in #S and puts ADAM … WHERE ??? Note the “problem” is that we are indeed putting values into the array.
Suppose (and I have not confirmed this yet), Natural looks at #NAME (#S) before moving the 1 into #S. What is in #S? Answer, probably 10 from the first loop. Hence ADAM goes into #NAME (10).
Okay, the second entry in the spinoff file is BLOND - 2. Where does Natural put BLOND? The value of #S is 1 (from the move of the first spinoff record). Hence, BLOND appears in #NAME (1). If you look at Page 3 of the output, this is indeed true.
I have to leave in a few minutes. When I get back I will continue “playing” SORT, to try and confirm what is going on.
Regardless of the “behind the scenes” stuff, it should be clear that the array has been destroyed by the basic SORT actions.
More this afternoon. Have a good weekend playing with this. javascript:emoticon(‘:D’)
steve