Dick, Creating an internal sort or cross reference duplicates routine in REXX is easy enough, but when the number of records gets higher the time taken is much increased. At one site the internal REXX sort ran for 14 hours, but an invoked SORT for the same data took 23 seconds.
The code below will read the contents of the stem FILE99 into the SORTIN DD, perform the external sort, and then read the sorted output back into the stem FILE99.
Obviously you will need to change your SYSOUT parameter to fit with your site standards, also to set the SORT parameters to your requirement, and of course to use the stem name that you have chosen.
X = MSG('OFF')
"ALLOC FI(SYSOUT) SYSOUT(X)"
"ALLOC FI(SYSIN) NEW TRACKS SPACE(3 3) RECFM(F B) LRECL(80)"
"ALLOC FI(SORTIN) NEW TRACKS SPACE(300 300) RECFM(V B) LRECL(80)"
"ALLOC FI(SORTOUT) NEW TRACKS SPACE(300 300) RECFM(V B) LRECL(80)"
QUEUE " OPTION VLSHRT VLSCMP"
QUEUE " SORT FIELDS=(5,44,CH,A)"
QUEUE " SUM FIELDS=NONE"
"EXECIO "QUEUED() "DISKW SYSIN ( FINIS"
"EXECIO * DISKW SORTIN ( STEM FILE99. FINIS"
FILE99.0 = 0
"EXECIO * DISKR SORTOUT ( STEM FILE99. FINIS"