Sorting Internal Tables
Know the techniques for sorting COBOL tables in memory when data must be ordered before further processing.
While DFSORT and SORT utilities handle sorting entire datasets at the JCL level, COBOL also needs to sort data already loaded into memory as a table — for instance, ranking a set of records read into an OCCURS table before producing a summary report. This is a more advanced topic because native COBOL (pre-2002 standard) has no built-in table-sort verb, so the classic approach is either a hand-rolled algorithm or the SORT verb with an internal input/output procedure.
Sorting an in-memory COBOL table by hand is like re-alphabetizing a small stack of index cards on your desk yourself, versus sending a whole filing cabinet's worth of paperwork to an outside sorting service — fine for a dozen cards, a bad idea for ten thousand.