This system function is used to convert "incorrectly sorted" characters (or combinations of characters) into other characters (or combinations of characters) that are "correctly sorted" alphabetically by the sort program or database system.
Several national languages contain characters (or combinations of characters) which are not sorted in the correct alphabetical order by a sort program or database system, because the sequence of the characters in the character set used by the computer does not always correspond to the alphabetical order of the characters.
For example, the Spanish letter "CH" would be treated by a sort program or database system as two separate letters and sorted between "CG" and "CI" - although in the Spanish alphabet it is in fact a letter in its own right and belongs between "C" and "D".
Or it may be that, contrary to your requirements, lower-case and upper-case letters are not treated equally in a sort sequence, that letters are sorted after numbers (although you may wish them to be sorted before numbers), or that special characters (for example, hyphens in double names) lead to an undesired sort sequence.
In such cases, you can use the system function
SORTKEY(character-string). The values
SORTKEY are only used as sort criterion, while the
original values are used for the interaction with the end-user.
You can use the
SORTKEY function as an arithmetic
operand in a
statement and in a logical condition.
You can write this user exit in any programming language that
provides a standard
CALL interface. The
character-string specified with
will be passed to the user exit. The user exit has to be programmed so that it
converts any "incorrectly sorted" characters in this string into
corresponding "correctly sorted" characters. The converted
character string is then used in the Natural program for further
The general calling conventions for external programs are explained
in the description of the
Exit for Computation of Sort Keys for more details on the
calling conventions for
SORTKEY user exits.
DEFINE DATA LOCAL 1 CUST VIEW OF CUSTOMERFILE 2 NAME 2 SORTNAME END-DEFINE ... *LANGUAGE := 4 ... REPEAT INPUT NAME SORTNAME := SORTKEY(NAME) STORE CUST END TRANSACTION ... END-REPEAT ... READ CUST BY SORTNAME DISPLAY NAME END-READ ...
Assume that in the above example, at repeated executions of the
INPUT statement, the following values are entered:
"Sanchez", "Sandino" and
At the assignment of
SORTNAME, the user exit NATUSK04 would be invoked. This user exit
would have to be programmed so that it first converts all lower-case letters to
upper-case, and then converts the character combination
"Cx" - where
x would correspond to the last character in the
character set used, i.e. hexadecimal H'FF' (assuming that this last character
is a non-printable character).
The "original" names (
NAME) as well as the
converted names to be used for the desired sorting (
stored. To read the file,
SORTNAME is used. The
would then output the names in the correct Spanish alphabetical order:
Sancinto Sanchez Sandino