In the SORT statement, you specify the key on which the file will be sorted. The key must have been defined in the record description of the file to be sorted. In the following example, notice that SORT-GRID-LOCATION and SORT-SHIFT are defined in the Data Division before they are used in the SORT statement.


To sort on more than one key, as shown in the example above, list the keys in descending order of importance. The example also shows the use of input and an output procedure. Use an input procedure if you want to process the records before you sort them, and use an output procedure if you want to further process the records after you sort them. The key used in the SORT statement cannot be variably located.

Restrictions on Sort-Key Length

There is no maximum number of keys, as long as the total length of the keys does not exceed 4092 bytes. (If the EQUALS keyword is coded on the DFSORT OPTION control statement at run time, the limit is 4088 bytes.)

Alternate Collating Sequences

You can sort records on EBCDIC, ASCII, or another collating sequence. The default collating sequence is EBCDIC or the PROGRAM COLLATING SEQUENCE you specified in the Configuration Section (if any). You can override the sequence named in the PROGRAM COLLATING SEQUENCE by using the COLLATING SEQUENCE option»of the SORT statement. Consequently, you can use different collating sequences for multiple sorts in your program.

When you sort an ASCII file, you have to request the ASCII collating sequence. To do this, use the COLLATING SEQUENCE alphabet-name option of the SORT statement, where the alphabet-name has been defined in the SPECIAL-NAMES paragraph as STANDARD-1.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

IBM Mainframe Topics