The SORT statement creates a sort file by executing input procedures or transferring records from an input file. It sorts the records in the sort file using one or more keys that you specify. Finally, it returns each record from the sort file, in sorted order, to output procedures or an output file. Format - SORT sortfile { ON { ASCENDING } KEY { sortkey } ... } ... { { DESCENDING } } [ WITH DUPLICATES IN ORDER ] [ COLLATING SEQUENCE IS alpha ] { INPUT PROCEDURE IS first-proc [ { THRU } end-proc ] } { [ { THROUGH } ] } { USING { infile } ... } { OUTPUT PROCEDURE IS first-proc [ { THRU } end-proc ] } { [ { THROUGH } ] } { GIVING { outfile } ... }
1 – sortfile
is a file-name described in a sort-merge file description (SD) entry in the Data Division.
2 – sortkey
is the data-name of a data item in a record associated with sortfile.
3 – alpha
is an alphabet-name defined in the SPECIAL-NAMES paragraph of the Environment Division.
4 – first-proc
is the section-name or paragraph-name of the first (or only) section or paragraph of the INPUT or OUTPUT procedure range.
5 – infile
is the file-name of the input file. It must be described in a file description (FD) entry in the Data Division.
6 – end-proc
is the section-name or paragraph-name of the last section or paragraph of the INPUT or OUTPUT procedure range.
7 – outfile
is the file-name of the output file. It must be described in a file description (FD) entry in the Data Division.