Umm, no external program is run when a CL program "processes" commands like IF, GOTO, CHGVAR, DOUNTIL, DOWHILE, DOFOR, SELECT, WHEN, ENDDO, etc. For example, the IF command's CPP is QCLIF, however that program doesn't exist. The GOTO command's CPP is QCLGOTO; likewise that program doesn't exist. You get the point.

It shouldn't take much thought to realize why. When the CL compiler encounters these commands it just substitutes the necessary code, such as a branch instruction in place of the GOTO command.

So, not ALL commands actually call a program, but most do.

Here's something to try which proves this. Create a duplicate object of the GOTO command and call it BRANCH (or anything you want). Create a CL program that uses the BRANCH command to skip over some other command. Delete the BRANCH command and then run the program. It will still work. I created the following to test this and, as expected, the delay did not happen.

Pgm
Branch CmdLbl(EndPgm)
DlyJob 300
EndPgm: EndPgm

For years (since 1987) I used duplicates of the GOTO command called EXSR and ENDSR to provide pseudo-subroutines in CL using a "stack", a "stack pointer", a link section, and a lot of labels. It made it much easier to code and maintain programs that had loops within loops, such as processing a list of files and then processing a list of members for each file. This was long before we had real subroutines and looping constructs in CL, which we didn't get until 2004 or so.

Honestly, file processing in CL is limited. It can be done but why would you? To do this requires you call another program. Before anyone differs with me, remember that ALL commands call a program. Don't believe me? Try DSPCMD IF. Whether or not IBM supplies the program is a different matter.

Now as to your solution...
You could use the RUNSQL command that came out with TR4 in 7.1 to create a new file sorted in that order.
RUNSQL SQL('create table qtemp/crap as (
select * from erplxf/rco order by rrn(rco) desc) with data')
COMMIT(*NONE)
then you could process that table.
CL doesn't yet support imbedded sql, (like rpg does). Otherwise you could drop the create table and process that directly.

This mailing list archive is Copyright 1997-2015 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available here. If you have questions about this, please contact