SORT primary command

The SORT command changes the order of the data you are viewing.

In an editor session, by default, File Manager sorts data in ascending order. For VTOC data sets and member lists, the default sequence depends on the sort criteria you specify.

Syntax

SORT command in View or Edit
In View and Edit, File Manager sorts the data using a hierarchy of keys starting with the first column or field parameter as the primary key, and subsequent columns or fields as less significant keys. The hierarchy is specified left to right.

If you do not specify any parameters for the SORT primary command, File Manager sorts the data record by record, according to each record's hexadecimal representation.

The sort order is based on EBCDIC (hex) values in the specified columns or fields, therefore, lowercase characters are sorted before uppercase characters.

When you use the SORT primary command, you can optionally specify that only excluded, or only not-excluded, records are sorted.

Figure 1. Syntax: View and Edit

1  SORT
1 
2.1! A
2.1 D
2.1 +  col1 col2
2.2.1! A
2.2.1 D
2.1 +  ref
2.2.1! A
2.2.1 D
2.1 X
2.1 NX
1 KEY
A
Sort data in ascending sequence. This is the default.
D
Sort data in descending sequence.
col1
(CHAR, HEX, or LHEX display formats only.) The first column to be included in the column range to be used as a sort key. Must be greater than or equal to 1, and less than or equal to the maximum record length. You can specify up to five pairs of column range values.
col2
(CHAR, HEX, or LHEX display formats only.) The last column to be included in the column range to be used as a sort key. Must be greater than col1 and less than or equal to the maximum record length. If col1 is specified, then col2 must also be specified.
ref
(TABL and SNGL display format only.) A field reference, specifying the field to be used as the sort key, for example: #3. To sort a TABL display format, you must provide at least one field reference.

When the field is an item in an array, you must specify a subscript in parentheses to identify the occurrence that you want to use, for example: #5(3). If your field is part of a multi-dimensional array, you must specify a subscript for each dimension in the array, for example #7(2,3).

You can specify up to 5 field references. Multiple field references must be separated by a blank, for example: #3 #5(3). The first reference specifies the primary (most significant) key, the second reference specifies the secondary (2nd most significant) key, and so on. Sorting proceeds from the most significant key to the least significant key.

SORT does not support fields with varying length or varying starting positions. If one of these fields is specified, an error message is displayed.

NX
Not-excluded records only. Sorts records as if any excluded records did not exist. If you subsequently display excluded records, they may be are interspersed with the sorted non-excluded records.
X
Excluded records only. Sorts excluded records as if any not-excluded records did not exist. If you subsequently display non-excluded records, they may be are interspersed with the sorted excluded records.
KEY
Sort a KSDS, VRDS, or RRDS VSAM data set into the KEY sequence of the file. Typically you use SORT KEY after performing other sort operations on the data. The SORT KEY function “restores” the records into the original key sequence of the file.

This option only sorts non-excluded records. So SORT KEY is the equivalent of SORT KEY NX (even though you cannot specify the NX).

Note: When you sort a RRDS file using SORT KEY, File Manager sorts the RRDS into VSAM SLOT sequence. The SLOT number is a unique number that the VSAM access method allocates for each record. If the records of the RRDS file have been re-ordered by moving records via a move (M, Mn, or MM) prefix command or SORT primary command, SORT KEY re-orders the records as they were when the file was opened. However, when you add records using insert (I or In), copy (C, Cn, or CC), or repeat (R, Rn, RR, or RRn) prefix commands, the new records do not have a SLOT number assigned as the file is still in memory. In this case, SORT KEY re-orders the new records at the bottom of the file.
SORT command in selection list panels

You can use the SORT command to sort specified column names in a panel showing a selection list.

When more than one column is to be sorted, the sequence in which you specify the columns has no impact on the sequence in which the columns are sorted. The columns are always sorted from left to right.

If you do not specify a sort order (A or D) for a column, the default sort order for that column is used. You can find the default sort order for a column in the Column Settings panel. To display this panel, position the cursor on the filter value for the column and press Enter.

After the SORT command has been entered, the list display is scrolled to the top with the order reflecting the changes after applying the sort to the specified columns.

Figure 2. Syntax: selection list panels
(1)
Notes:
  • 1 You can specify up to 5 columns to be sorted.
column
Column to be sorted.
A
Sort column in ascending order.
D
Sort column in descending order

Availability

Related tasks and examples