|
The SORT.COMPARE() function compares two items using a specified set of comparison rules.
Format
SORT.COMPARE(string1, string2, mode {, no.case})
where
| string1 | is the first string to be compared. |
| string2 | is the second string to be compared. |
| mode | identifies the manner in which the comparison is to be performed. |
| no.case | a Boolean value indicating whether the comparison should be case insensitive. This argument is retained for compatibility with earlier releases but case insensitivity can be specified in the mode value. |
The SORT.COMPARE() function compares string1 and string2 according to the sort rules specified by the mode value which may be specified as a numeric value or by use of the tokens from the SYSCOM KEYS.H include record shown below.
| Mode 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. |
| Mode 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. |
| Mode 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. |
| Mode 3 | SRT$RIGHT.FLOAT. The same as mode 1 except that the test for numeric items allows non-integer values. |
| Mode 4 | SRT$STRICT. Similar to a compound sort but numerically equivalent elements such as "28" and "028" to be treated as being different. |
Other additive mode flags are:
| SRT$DESCENDING | The result of the comparison operation is reversed. |
| SRT$NOCASE | Perform a case insensitive comparison. |
In all cases, the no.case argument can be used to specify that alphabetic items should be treated as case insensitive, effectively replacing lower case letters with their upper case equivalents.
The SORT.COMPARE() function returns
| -1 | string1 comes before string2 |
| 0 | string1 is equal to string2 |
| 1 | string1 comes after string2 |
Examples
Using the modes indicated below, the effect of sorting GC5, ND620, GC41, CD631, 55, 3AB and GC would be
| Mode 0 | 3AB, 55, CD631, GC, GC41, GC5, ND620 |
| Mode 1 | 55, GC, 3AB, GC5, GC41, CD631, ND620 |
| Mode 2 | 3AB, 55, CD631, GC, GC5, GC41, ND620 |
See also:
COMPARE(), !SORT()
|