|
The !MULTISORT() subroutine sorts multiple related lists simultaneously.
Format
CALL !MULTISORT(mode, keys, data1 {, data2...})
where
| mode | is the the sort mode to be used. |
| keys | is a field mark delimited list to be sorted. |
| data1 | is a parallel list to be sorted, maintaining pairing of items with keys. A minimum of 1 and a maximum of 10 data lists may be specified. |
The !MULTISORT() subroutine sorts multiple field mark delimited lists in parallel, maintaining the relationship between items in the keys list and the data lists. The keys and data lists are updated on return.
The subroutine uses char(0) internally so the lists to be sorted must not contain this character.
The mode argument determines how the data will be sorted
At most one of the following sort styles:
|
0
|
SRT$LEFT
|
A simple left justified comparison, examining corresponding characters from the start of each string until either a difference is found or the end of both strings has been reached.
|
1
|
SRT$RIGHT
|
A simple right justified comparison in which the shorter item is effectively padded with leading spaces and the resultant strings are compared character by character from the start until either a difference is found or the end of both strings has been reached. If both strings can be treated as integer values, possibly with a leading sign character, a numeric comparison is performed.
|
2
|
SRT$COMPOUND
|
A compound sort in which the two strings are considered to be formed from a series of alternating numeric and non-numeric elements. Numeric elements are sorted into numerical value, non-numeric elements are sorted into collating sequence order. If the first element is numeric, it may have an optional leading sign character. Sign characters appearing later in the strings are treated as being non-numeric characters.
|
3
|
SRT$RIGHT.FLOAT
|
The same as mode 1 except that the test for numeric items allows non-integer values.
|
Any combination of the following sort options:
|
16
|
SRT$DESCENDING
|
The result of the comparison operation is reversed.
|
32
|
SRT$UNIQUE
|
Duplicate key values are ignored.
|
64
|
SRT$NOCASE
|
Case insensitive sort.
|
Example
KEYS = CHANGE('17|4|38|25|66', '|', @FM)
DATA = CHANGE('A|B|C|D|E', '|', @FM)
CALL !MULTISORT(SRT$RIGHT, KEYS, DATA)
FOR I = 1 TO 5
DISPLAY KEYS<I>, DATA<I>
NEXT I
The above program fragment sets up KEYS and DATA as two parallel lists. The CHANGE() function is used here for clarity as a literal string cannot contain a field mark. After using the !MULTISORT() subroutine the displayed data would be:
4 B
17 A
25 D
38 C
66 E
See also:
SORT()
|