Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Sort processing

The user can sort a file on the basis of a series of keys. These sort keys are specified by the user and are present in each record of the file. The records may be sorted so that all of their keys are in ascending or in descending order, or so that some of their keys are ascending and others are descending.

Records are sorted on a file called a sort-file. This file is defined in the Data Division in a sort-file description (SD) entry, and in the record description associated with the SD. The SORT statement in the Procedure Division initiates the sort operation.

Sort processing consists of:

  1. Releasing all records to the sort-file.

  2. Sorting the records on the sort-file.

  3. Returning all records from the sort-file.

The user may either provide an input procedure to process records and transfer them to the sort-file, or he may specify an input file containing the records to be sorted and allow the SORT statement to transfer these records to the sort-file. Accordingly, he may either provide an output procedure to retrieve records from the sort-file and process them further, or he may specify an output file and allow the SORT statement to output the sorted records to this file.

Multiple sort operations may be specified in a single program.