Cobol SORT Verb

Most computer languages offer no direct support for sorting files -- that's a job usually reserved for system utilities. COBOL's SORT verb reflects COBOL's orientation toward business data processing.

Typically a program using the SORT verb uses both an input procedure and an output procedure. Otherwise there would be little reason to do the sort within the program rather than a separate job step.

Even in this case, however, the SORT verb is not as useful as one might think. It is usually better to split such a program into three separate job steps: one corresponding to the input procedure and one corresponding to the output procedure, with a sort step in between. This approach offers several advantages:

  1. Two small programs are easier to read and maintain than one big program.
  2. Two small programs are easier to test. You can examine the output of the input program, or manipulate the input of the output program.
  3. You can more easily rearrange the smaller programs to fit changing requirements. For example, the output of the input program may turn out to be useful for some other purpose. The output program may find uses in another context where the input program is not relevant, or where the records are already sorted.
In older dialects of COBOL, input and output procedures carry some extra baggage. Each procedure must be a COBOL section. If the section contains more than a single paragraph, standard COBOL syntax all but forces you to use a GO TO to exit the section. COBOL II and later releases have removed this requirement.

When the SORT Verb is Appropriate

Despite the above considerations, the SORT verb may be the best solution in some cases:
COBOL Home COBOL Style Forum