The @SORT statement is used to sort contiguous line ranges in the current work file in ascending or descending order. By specifying a column range, it is possible to restrict the sort operation to the relevant section of the record.
Operation | Operands | F mode, L mode |
@SORT | [lines] [ {:cols[:] | :R (cols*) } ] [ {A | D} ] |
lines | Line range in which the data is to be sorted. If no line range is specified then |
cols | Column range whose characters are to be included in the sort operation. If only one column number is specified then the characters from this column The sort fields in two lines are compared one character at a time from left to If no column range is specified then the sort field comprises the entire line. |
cols* | Column range starting at the end of the record. Counting from the end of the |
A D | Sorting is performed in ascending order. Sorting is performed in descending order. |
Lines with identical sort fields retain their original sequence in the work file.
If a 7-bit or 8-bit character set is assigned to the work file then the sequence of the individual characters is determined by their byte codes interpreted as binary numbers. If a Unicode character set is assigned to the work file then the sequence of the individual characters is determined by the UTF16
codes of the characters interpreted as binary numbers. The sort weighting managed by XHCS for the individual characters is ignored. The sort sequence when sorting with EDT may therefore differ from the sort sequence when sorting with the SORT program.
The @SORT statement uses a combination of quicksort and bubblesort.
The @SORT statement cannot be used for a file opened for real processing with @OPEN (format 2).
If the statement is interrupted with [K2] and the EDT session is continued with /INFORM-PROGRAM
then the processing of the statement is aborted and message EDT5501
is output.
Examples
@SORT :1-15
Sorts all the records in the current work file in ascending order on the basis of the contents of columns 1 to 15.
@SORT &:1-15
Sorts all the records in the range defined using the range symbol &
(see @RANGE statement) in the current work file in ascending order on the basis of the contents of columns 1 to 15.
@SORT %-.%+19L :R(1-8) D
Sorts the first 20 records in the current work file in descending order on the basis of the contents of the last 8 columns.
@SORT 20-.$:#I1-#I2
Sorts the records from line number 20 through to the end of the current work file in ascending order. The column range within which sorting is performed is defined by the integer variables #I1
and #I2
.