Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

@SORT - Sort line ranges

&pagelevel(3)&pagelevel

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
all the records in the current work file are sorted.

cols

Column range whose characters are to be included in the sort operation.
This column range is referred to as the sort field below.

If only one column number is specified then the characters from this column
up to the end of the line are included in the operation. If the first column
specification is greater than the line length then the corresponding line is
treated as if it contained an empty sort field.

The sort fields in two lines are compared one character at a time from left to
right. If the end of one of the sort fields is reached during this comparison
(with no differences being discovered) then the line with the shorter sort field
is considered to be smaller.

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
record back toward the start of the record simply determines the number of
characters present in the sort field. Despite this, the characters in the sort
field are compared from left to right. The specification 1-10, for example,
therefore means the last ten characters in every line.

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.