SORT Statement
The SORT statement accepts records from one or more files, sorts them according to the specified key(s), and makes the sorted records available either through an OUTPUT PROCEDURE or in an output file. A SORT statement may appear anywhere in the Procedure Division except in a Declarative Section. The maximum number of USING or GIVING files is 32.
SORT Statement - Format >>-SORT--file-name-1--------------------------------------------> .--------------------------------------------------. | .-------------. | V V | | >----+----+--+-ASCENDING--+--+-----+----data-name-1-+-+---------> '-ON-' '-DESCENDING-' '-KEY-' >--+------------------------------------+-----------------------> '-+------+--DUPLICATES--+----------+-' '-WITH-' '-IN ORDER-' >--+------------------------------------------------+-----------> '-+-----------+--SEQUENCE--+----+--alphabet-name-' '-COLLATING-' '-IS-' .-------------. V | >--+-USING----file-name-2-+-----+-------------------------------> '-| input procedure phrase |-' .-------------. V | >--+-GIVING----file-name-3-+-----+----------------------------->< '-| output procedure phrase |-' input procedure phrase |--INPUT PROCEDURE--+----+--procedure-name-1--------------------> '-IS-' >--+-------------------------------+----------------------------| '-+-THROUGH-+--procedure-name-2-' '-THRU----' output procedure phrase |--OUTPUT PROCEDURE--+----+--procedure-name-3-------------------> '-IS-' >--+-------------------------------+----------------------------| '-+-THROUGH-+--procedure-name-4-' '-THRU----'
- file-name-1
- The name given in the SD entry that describes the records being sorted.
Null-capable fields are supported, but null values are only supported for DATABASE files that have ALWNULL specified on their ASSIGN clause. If ALWNULL is not specified, the SORT operation will fail, and file status of 90 will be returned if a field contains a null value.
