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
|
Note that a case insensitive sort requires a collating sequence to be defined for the code page.