1. SORT
The SORT statement receives records from one or more files, and sorts them based on a described key.
The following items are specified in the statement.
-
file-name-1
-
The name of the file in which the record to be merged is to be included. It is described in the SD entry.
-
-
identifier-1
-
The data description that includes the record to be sorted. It is a group type and must contain data to be sorted.
-
-
ASCENDING KEY and DESCENDING KEY phrases
-
Specifies either an ascending or descending sequence for the sort key.
Item Description data-name-1
Describes a KEY data item to be used in the SORT statement. data-name-1 must be a data item that is included in the record for file-name-1.
The leftmost data item is the major key, and the next data item is the second major key, based on the order in which the data items are specified.
-
In each input file, a KEY data item must be located in the same position and share the same data format. They do not need to have the same data-name.
-
If one or more records are described in file-name-1, the KEY data items must be specified in one of the records.
-
KEY data items cannot include an OCCURS clause, and cannot belong to an item containing an OCCURS clause.
-
KEY data items can be qualified. KEY data items can be one of the following data categories.
-
Alphabetical, alphanumeric, alphanumeric-edited
-
Numeric
-
Numeric-edited (with usage DISPLAY)
-
Internal floating-point or display floating-point
-
If file-name-3 references an indexed file, data-name-1 must be described with an ASCENDING phrase, and data-item must specify the same position as that of the major record key of the indexed file.
-
-
-
DUPLICATES phrase
-
If the DUPLICATES phrase is not described, the order of records that have the same key is unpredictable.
-
If the phrase is specified, the records with the same key are sorted in the following order.
-
They are sorted in the same order as the records in the input files.
-
If an input procedure exists, the records are sorted in the order that records are used in the RELEASE statement.
-
-
-
COLLATING SEQUENCE phrase
-
Only syntax checking is performed.
-
-
USING phrase
-
Describes input files.
Item Description file-name-2,…
Defines input files. If the USING phrase is specified, all records of the input files (file-name-2,…,) are automatically transmitted to file-name-1. All input files must be described in the FD entries in the data division.
-
-
INPUT PROCEDURE phrase
-
The INPUT PROCEDURE phrase contains the RELEASE statement, and transfers one record at a time to the file referenced by file-name-1. By using various statements such as OPEN, READ, and CLOSE, input records can be selected, copied, and modified.
-
Select an input record before executing a sort operation, and describe a procedure name to be modified.
Item Description procedure-name-1
Must be described with the first or only section or paragraph of the input procedure.
procedure-name-2
Must be described with the last section or paragraph of the input procedure.
-
-
GIVING phrase
-
Describes output files.
Item Description file-name-3,…
Defines output files. If the GIVING phrase is specified, all sorted records are automatically transferred to the output files. All output files must be described in the FD entries in the data division.
-
-
OUTPUT PROCEDURE phrase
-
The OUTPUT PROCEDURE phrase contains the RETURN statement, so that one record is transferred at a time from the file referenced by file-name-1. By using various statements such as OPEN, WRITE, and CLOSE, output records can be selected, copied, and modified.
-
Select an output record after executing a sort operation, and specify the name of a procedure to be modified.
Item Description procedure-name-3
Must be described with the first or only section or paragraph of the output procedure.
procedure-name-4
Must be described with the last section or paragraph of the output procedure.
-