SORT (Macro)

Read syntax diagramSkip visual syntax diagramSORT target* AD col1col2

Purpose

Use the SORT macro to arrange a specified number of file lines in ascending or descending EBCDIC order according to specified sort columns.

Operands

target
specifies the number of lines to be sorted. Lines are sorted starting with the current line, up to but not including the target line.

You can specify a target as an absolute line number, a relative displacement from the current line, a line name, or a string expression. For more information on targets, see LOCATE and z/VM: XEDIT User's Guide.

*
lines are sorted from the current line to the end of the file.
A
sorts the file in ascending EBCDIC order. This is the default.
D
sorts the file in descending EBCDIC order.
col1 col2
is a pair of numbers that define a sort field. The col1 is the starting column of a sort field within each line and may not exceed 4096. The ending column is col2. You can specify as many sort fields as you want, as long as the total length does not exceed 248.

Usage Notes

  1. If SET CASE UPPERCASE/MIXED RESPECT is in effect, sorting is done in EBCDIC order.
  2. If SET CASE UPPERCASE/MIXED IGNORE is in effect, sorting is done in alphabetic order, with lowercase and uppercase representations of the same letter considered to be identical.
  3. SORT operates outside the current SCOPE. (See Effects of Selective Line Editing Subcommands for more information about SORT and the SCOPE setting.)
  4. SORT cannot be issued when prefix subcommands or macros are pending and it cannot be issued from a prefix macro.
  5. The SORT macro provides a stable sort. If lines have identical sort fields, their relative position in the file is maintained following the sort.

Examples

In this example, suppose you are editing a file that has two fields of information. The first field, positioned between columns 8 and 16 of the file, contains a list of file names. The second field, positioned between columns 17 and 24 of the file, contains a list of file types. Issuing the command:
sort * 17 24 8 16
sorts the file by file type (columns 17 through 24) and, within each file type, by file name (columns 8 through 16). The asterisk tells XEDIT to sort the entire file. Because no sort order is specified, the file is sorted in ascending order (the default).

Messages and Return Codes

009E
Column nn exceeds record length [RC=24]
053E
Invalid sort field pair defined [RC=24]
063E
No sort list given [RC=40]
493E
SORT invalid in update mode [RC=3]
545E
Missing operand(s) [RC=5]
546E
Target not found [RC=2]
554E
Not enough virtual storage available [RC=104]
581E
Subcommand is not valid in extended mode [RC=3]
588E
Prefix subcommand waiting... [RC=8]
596E
This module must be called within the editor [RC=88]

where return codes are:

0
Normal
1
TOF or EOF reached during execution
2
Target line not found
3
SORT cannot be used when a file is edited in UPDATE mode or extended mode
5
Missing operand(s)
6
Subcommand rejected in the profile due to LOAD error, or QUIT subcommand has been issued in a macro called from the last file in the ring
8
Prefix area contains pending subcommand or macro
24
Invalid columns defined
40
No list given
88
Module must be called within the editor
104
Insufficient storage available