Sort key descriptors

The SORT and FSORT commands can optionally take a KEY clause which describes how the sort is to be performed. The reserved work KEY is followed by a string expression which is interpreted as a list of 4 byte key segment descriptors. The list terminates either at the end of the string or at the first segment descriptor with a zero length.

The layout of a segment descriptor is as shown in the table.

Byte Purpose
1 Length, zero marks end of descriptors
2,2 Start of segment, counted from 1
4 Bits defining how the segment is to be sorted. These bits can be added together
KCML constant Bit Purpose
_SORT_ASCENDING HEX(00) Sort into ascending order
_SORT_DESCENDING HEX(20) Sort into descending order
_SORT_COLLATESEQ HEX(40) Use collating sequence
_SORT_CASEINSENSITIVE HEX(80) Case insensitive

Note that a case insensitive sort requires a collating sequence to be defined for the code page.