Hello again. Thanks so much for all your much appreciated help.
I would like to use an internal SORT if possible in a program that generates five reports. I know that only one SORT statement is permitted. I can get around that by using a common area in the Sort Record for the Sort Key which has a Report Code as the first field, the rest of the Sort Key redefined as necessary.
However, this necessitates that the program generates multiple Sort Records per main loop.
I have two questions:
The documentation states that when the program has nested loops, sort records are generated by the innermost loop. If there are loops (FINDs etc) in subroutines PERFORMed from the main loop, does SORT count these as nested loops for the purpose of generating sort records?
Does SORT count FOR statements and the like as nested loops ?
What’s a good way to generate multiple sort records per main loop - where IF statements would normally determine when to generate a sort record ?
The documentation states that when the program has nested loops, sort records are generated by the innermost loop. If there are loops (FINDs etc) in subroutines PERFORMed from the main loop, does SORT count these as nested loops for the purpose of generating sort records?
Does SORT count FOR statements and the like as nested loops ?
What’s a good way to generate multiple sort records per main loop - where IF statements would normally determine when to generate a sort record ?
Lets start with the simplest question, 2. FOR and REPEAT loops are definitely nested loops.
Question 3. If you use IF you should use it with ESCAPE TOP to avoid having records written to th e sort spinoff file. Alternatively, you could use ACCEPT or REJECT.
Question 1 is more complicated because it requires understanding how SORT works. Consider the following schematic:
READ
::::
END-ALL
SORT by....
::::
END-SORT
Look upon the END-ALL as being a statement that writes a spinoff record to the sort workfile. Now lets consider two structures
READ
:::
FOR #loop = 1 to 3
::::
end-all
This will generate three spinoff records per record READ.
By contrast
READ
:::
for #loop = 1 to 3
::::
end-for
:::::
end-all