z/OS ISPF Edit and Edit Macros
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


SORT—Sort Data

z/OS ISPF Edit and Edit Macros
SC19-3621-00

The SORT macro command puts data in a specified order.

Syntax

Read syntax diagramSkip visual syntax diagram
Macro command syntax

                  .-.ZFIRST--.ZLAST-.           
>>-ISREDIT--SORT--+-----------------+--+----+------------------->
                  '-labela--labelb--'  +-X--+   
                                       '-NX-'   

>--+--------------------+--------------------------------------><
   | .----------------. |   
   | V                | |   
   '---| sort_field |-+-'   

sort_field

   .-A-.                           
|--+---+--start_col--+---------+--------------------------------|
   '-D-'             '-end_col-'   

labela, labelb
Labels identifying the start and end of the group of lines for the sort operation.

For more information about using labels to identify a group of lines, see Labels and line ranges.

X
Specifies that only excluded lines are to be sorted.
NX
Specifies that only non-excluded lines are to be sorted.
sort_field
Specifies the field to be used in sorting data. You can specify up to five sort fields using these operands:
A
Specifies ascending order. It can either precede or follow the column specification.
D
Specifies descending order. It can either precede or follow the column specification.
start_col
Defines the starting column of the field that is to be compared. It must be within the current boundaries.
end_col
Defines the ending column of the field that is to be compared. It must be within the current boundaries.

If you specify several fields, you must specify both the starting and ending columns of each field. The fields cannot overlap. If you specify A or D for one field, you must specify it for all fields.

Description

The SORT command operates in two different modes, based on the hexadecimal mode status. If hexadecimal mode is on, the data is ordered according to its hexadecimal representation. If hexadecimal mode is off, data is sorted in the collating sequence defined for the national language being used.

Sorting data without operands

For a SORT command with no operands, the editor compares the data within the current boundaries character by character, and then orders it line by line in the proper collating sequence. It ignores data outside the current boundaries during both operations. This means that only the data inside the current boundaries is changed. Labels, excluded lines, line numbers, and change, error, and special line flags are considered associated with the data, and therefore points to the same data fields after the sort as they did before the sort.

For example, if you issue a CHANGE ALL command that changes the first, third, and sixth lines in a data set, these lines are flagged with the change flag, ==CHG>. If you then issue a SORT command that results in the former lines 1, 3 and 6 becoming the first, second and third lines of the sorted file, the changed line flags would now exist on the first, second and third lines of the sorted data set.

It is important to properly set the boundaries before issuing the SORT command. SORT is a powerful tool for editing data that may be formatted in multiple columns. You can set the boundaries, for example, to the first half of a record and sort one column of data. Then you can set the boundaries to the last half of the record and sort a second column of data.

Limiting the SORT command

You can specify up to five sort fields by labeling starting and ending columns. You can identify each field as having data sorted in ascending or descending order.

Optionally, you can limit sorting to a range of lines by specifying the labels of the first and last lines of the range. You can also limit sorting to either excluded or non-excluded lines.

If you have labels or line ranges that are between the labels or line ranges specified with the SORT command, you can keep SORT from rearranging them by:
  • Excluding them before you enter the SORT command
  • Using the NX operand to sort only lines that are not excluded

See the definition of the NX operand and EXCLUDE—Exclude Lines from the Display for more information.

Sorting DBCS data

When sorting data that contains DBCS character strings, you must ensure that no DBCS string crosses the boundaries. Also, all records must have the same format at the boundaries, although the format of the left and right boundaries can differ.

If a boundary divides a DBCS character, or if all records do not have the same format at the boundaries, the result is unpredictable.

Return codes

0
Normal completion
4
Lines were already in sort order
8
No records to sort
16
Not enough storage to perform sort
20
Severe error

Examples

To sort the data in descending order, using the sort key in columns 15 through 20:
ISREDIT SORT D 15 20
To sort all excluded lines in ascending order:
ISREDIT SORT X A

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014