Previous Topic: SET Control StatementNext Topic: STOP Control Statement


SORT Control Statement

The SORT control statement orders information that is eventually written to the print and output files. Capabilities are provided to sort up to 15 fields in ascending or descending sequence.

Syntax

SORT field[-seq][,field[-seq]], …]

where:

field

Specifies the name of the field to sort.

This field can be a database field, a defined field, or a reserved field.

-seq

Specifies the sequence for sorting the field.

The sequence A is used for sorting in ascending sequence; the sequence D is used for sorting in descending sequence. If omitted, the field is sorted in ascending sequence.

The SORT control statement cannot be embedded in IF or DO control statements. Statements supplied before the SORT control statement are considered statements that are executed before the sort record is released to the sort. Statements following the SORT control statement are statements that are executed after the sort record is returned from the sort.

Example

To sort job name and SYSOUT ID in ascending sequence for a cross reference report, enter the following:

/SORT JOBNAME, ID

The same sort criteria can be given by specifying the sort sequence:

/SORT JOBNAME-A, ID-A

To print SYSOUT information sorted by page count from the largest to the smallest, specify the following:

/SORT PAGES-D, ID-A
/PRINT ID  'ID'                            
/PRINT EDIT(GEN,'ZZZZ9') '  Gen'           
/PRINT EDIT(SEQ,'ZZZZ9') '  Seq'           
/PRINT ARCHDATE 'Arc Date'                 
/PRINT ARCHTIME 'Arc Time'                 
/PRINT EDIT(LINES,'ZZZZZZZZ9') '    Lines'
/PRINT EDIT(PAGES,’ZZZZZZZ9’) '   Pages'