The SORT statement rearranges records into a specified sequence for an output file or report. This makes the report easier to read, analyze, and interpret. It also helps in processing PRINT TOTAL statements.
You can specify up to 12 sort control fields. The total length of all sort fields cannot exceed 256 bytes. A SORT statement must be preceded by a WRITE or SUMMARIZE statement. A SORT statement does not sort the input file. Instead, it acts on an extract file created by a WRITE or SUMMARIZE statement. A SORT statement signifies the end of a processing step.
To process a SORT statement, VMRGRW needs access to an external sort program, such as CA VM:Sort, that is callable from VMRGRW and does not run in the user area. CMS SORT will not work.
For a successful link, you must ensure that the sort program is present as a TEXT file or in a TXTLIB file. You must issue a GLOBAL TXTLIB command before running VMRGRW to ensure proper linkage to the user-supplied sort routine. For example, if you have CA VM:Sort, enter this command:
GLOBAL TXTLIB VMSLIB
The syntax for the SORT statement is as follows:
SORT "Parms".
Parms:
fldname1 [UP | DOWN] [SIGNED] [WITHIN fldname2 [UP | DOWN] [SIGNED]] ...
- fldname1
Specifies the name of the first (lowest priority) sort field. - UP
Specifies an optional parameter used to sort fldname1 in ascending sort order. This is the default. In ascending sort order, data with smaller values precede data with greater values. - DOWN
Specifies an optional parameter used to sort fldname1 in descending sort order. In descending sort order, data with larger values precede data with smaller values. - SIGNED
Specifies that positive or negative values are figured into the sort. Thus, -1 sorts before .5 in an ascending sort. If this parameter is absent, records are sorted by the absolute values of the data, which are always positive. Thus, -1 sorts after .5 in an ascending sort. - fldname2
Defines the name of a field to be used as the next (higher priority) sort field. As many as 12 WITHIN clauses may be defined. Each specifies the field name of a higher priority sort field.
Examples
This statement sorts records by the LJOB field:
SORT LJOB.
This statement sorts records by LJOB and then by VOLSER:
SORT VOLSER WITHIN LJOB.