Using the format 2 SORT statement to sort a table

It is recommended to use the format 2 SORT statement to sort a table. It provides the following benefits when compared to the format 1 SORT statement.

Table 1. Comparison of format 1 and format 2 SORT statements
Characteristics Format 1 SORT statements Format 2 SORT statements
Can be used to sort a file or a table Yes No, it is for tables only
Requires DFSORT or equivalent sorting program Yes No
Supported in CICS® Limited Yes
Supported in UNIX System Services No Yes
Supported in programs that are compiled with the THREAD option No Yes
Table can be sorted by using a single SORT statement, which simplifies coding No, it requires the SELECT clauses, SD entries with record descriptions, and input and output procedures Yes
Keys for sorting can be specified as part of the table definition, which can also be used in the SEARCH ALL statement No, keys must be specified in the SORT statement. If the table is to be searched by using SEARCH ALL as well, the keys must also be redundantly specified as part of the table definition. Yes, and it also supports specifying keys in the SORT statement if needed
Can filter or preprocess table elements during the sorting process Yes, using input and output procedures No, all of the table elements are passed to SORT as-is
Uses special registers that include SORT-CONTROL, SORT-CORE-SIZE, SORT-FILE-SIZE, SORT-MESSAGE, SORT-MODE-SIZE, and SORT-RETURN Yes No
Can be executed within the range of an input or output procedure No Yes
Note: Do not use the format 2 SORT with large tables in an environment where storage is constrained, because the format 2 SORT uses heap storage to do the sort.

Related references  
SORT statement (Enterprise COBOL for z/OS® Language Reference)