Setting sort or merge criteria

To set sort or merge criteria, define the keys on which the operation is to be performed.

About this task

Note: The process of setting sort criteria that is described in this topic relates to the format 1 SORT statement only. For more information about sorting a table by using the format 2 SORT statement, see Sorting a table.

Do these steps:

Procedure

  1. In the record description of the files to be sorted or merged, define the key or keys.

    There is no maximum number of keys, but the keys must be located in the first 4092 bytes of the record description. The total length of the keys cannot exceed 4092 bytes unless the EQUALS keyword is coded in the DFSORT OPTION control statement, in which case the total length of the keys must not exceed 4088 bytes.

    Restriction: A key cannot be variably located.

  2. In the SORT or MERGE statement, specify the key fields to be used for sequencing by coding the ASCENDING or DESCENDING KEY phrase, or both. When you code more than one key, some can be ascending, and some descending.

    Specify the names of the keys in decreasing order of significance. The leftmost key is the primary key. The next key is the secondary key, and so on.

Results

SORT and MERGE keys can be of class alphabetic, alphanumeric, national, or numeric (but not numeric of USAGE NATIONAL). If it has USAGE NATIONAL, a key can be of category national or can be a national-edited or numeric-edited data item. A key cannot be a national decimal data item or a national floating-point data item.

The collation order for national keys is determined by the binary order of the keys. If you specify a national data item as a key, any COLLATING SEQUENCE phrase in the SORT or MERGE statement does not apply to that key.

You can mix SORT and MERGE statements in the same COBOL program. A program can perform any number of sort or merge operations. However, one operation must end before another can begin.

Related tasks  

Sorting a table

Related references   
DFSORT Application Programming Guide (SORT control statement)
  
SORT statement (Enterprise COBOL for z/OS® Language Reference)  
MERGE statement (Enterprise COBOL for z/OS Language Reference)