Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

Overview of language elements

To use the sort feature, the user must provide additional information in the Environment, Data, and Procedure Divisions of the compilation unit. This information is summarized in the following table and is described in detail in the remainder of this section.

compilation unit division

Contents and meaning

Environment division

A SELECT clause in the FILE-CONTROL paragraph for the sort-file (sort-file-name).

SELECT clauses in the FILE-CONTROL paragraph for all files used as input and output procedures for the sort-file (section-name-1, section-name-2, section-name-3, section-name-4 for SORT; section-name-1, section-name-2 for MERGE) and for files appearing in the USING or GIVING phrase of a SORT or MERGE statement (file-name-1,...).

To permit restart of programs containing the SORT statement, the RERUN clause may be used in the I-O-CONTROL paragraph.

The SAME SORT AREA or the SAME SORT-MERGE AREA clause in the I-O-CONTROL paragraph is intended to optimize the allocation of internal storage to a sort-file.

Data Division

A sort-file description (SD) entry and associated record description entries for the sort-file; record descriptions must include sort-key fields.

File description (FD) entries and associated record description entries for all files used in input/output procedures for the sort-file section-name-1, section-name-2, section-name-3, section-name-4 for SORT; section-name-1, section-name-2 for MERGE) and for files appearing in the USING or GIVING phrase of a SORT or MERGE statement (file-name-1,...).

Data description entries for the above files.

Procedure Division

A SORT or MERGE statement for the sort-file specifying the following information:

  • Sort-key names

  • Whether the sort is to be in ascending or descending order of key.

  • Input/output information specified by the following options:

Specification

Meaning

INPUT PROCEDURE

Records will be released to the sort-file by an input procedure.

USING file-name-1,...

Specifies files from which the SORT statement will accept records to be released to the sort-file.

OUTPUT PROCEDURE

Records will be returned from the sort-file by an output procedure.

GIVING file-name-3,...

Specifies a file to which the SORT and MERGE statements will return sorted and merged records, respectively.

If input and/or output procedures are specified in the SORT or MERGE statement, these procedures must be included in the Procedure Division. An input procedure must include a RELEASE statement, to transfer records to the sort-file. An output procedure must include a RETURN statement, to accept records from the sort-file.

Special sort-registers can be referenced in the Procedure Division (see section "Special registers for files: SORT").