Domain: PROCEDURE
Command description
The SORT-VARIABLE command sorts the elements of a list variable in ascending or descending order according to their content. Only list variables whose elements are simple variables of the same type (STRING, INTEGER, BOOLEAN or ANY) can be sorted.
Format
SORT-VARIABLE |
VARIABLE-NAME = list-poss(2000): <composed-name 1..255> , SORTING-ORDER = *ASCENDING / *DESCENDING |
Operands
VARIABLE-NAME = list-poss(2000): <composed-name 1..255>
Specifies the variable to be sorted. When specified in list form, multiple variable names can be specified.
SORTING-ORDER = *ASCENDING / *DESCENDING
Determines the sorting order.
SORTING-ORDER = *ASCENDING
Sorts the elements from the lowest to the highest value. Depending on the type of elements to be compared, the size comparison is performed as follows:
Elements of the type STRING
In the case of a list with elements of the type STRING, the elements are sorted in ascending order according to the size of the string values. The value of the hexadecimal coding is compared for each byte (see also “String comparison” (Relational operators )). This type of comparison also enables X literals to be sorted.The following applies:
When two strings begin with the same values but have different lengths, the shorter string contains the lower value.
An empty string always has the lowest possible value.
Example:
The following size relationship results for the strings
BC
,ABC
andBCD
:ABC
<BC
andABC
<BCD
andBC
<BCD
Sorting in ascending order results in the sequence
ABC
,BC
andBCD
.Elements of the type INTEGER
In the case of a list with elements of the type INTEGER, the elements are sorted in ascending order according to the size of the integer values (numerical comparison).Elements of the type BOOLEAN
In the case of a list with elements of the type BOOLEAN, the elements are sorted in ascending order according to the size of the Boolean values. The following applies: the value “FALSE” is less then “TRUE”.Elements of the type ANY
In the case of a list with elements of the type ANY, the elements are sorted in ascending order according to the type of the current value (ascending order of string, integer or Boolean values, as described above).
If the elements in the list have values of different types, the list cannot be sorted.
SORTING-ORDER = *DESCENDING
Sorts the elements from the highest to the lowest value. The type of size comparison depends on the type of elements to be compared (see SORTING-ORDER=*ASCENDING).Command return code
When lists are sorted, it is possible that some of the commands will have been processed and executed before an error occurrs. In this case the result of the command is not guaranteed.
(SC2)
SC1
Maincode
Meaning/Guaranteed messages
0 CMD0001 No error 1 0 SDP2000 Warning: some elements could not be sorted 64 SDP2001 None of the elements could be sorted Example
/DECLARE-VARIABLE LANGUAGE-LIST (TYPE = *STRING), - / MULTIPLE-ELEMENTS = *LIST / LANGUAGE-LIST = 'GERMAN', WRITE-MODE=*EXTEND / LANGUAGE-LIST = 'ENGLISH', WRITE-MODE=*EXTEND / LANGUAGE-LIST = 'FRENCH', WRITE-MODE=*EXTEND / LANGUAGE-LIST = 'ITALIAN', WRITE-MODE=*EXTEND / LANGUAGE-LIST = 'GREEK', WRITE-MODE=*EXTEND / /SORT-VARIABLE VARIABLE-NAME=LANGUAGE-LIST, SORTING-ORDER=*ASCENDING /SHOW-VARIABLE VARIABLE-NAME=LANGUAGE-LIST LANGUAGE-LIST(*LIST) = ENGLISH LANGUAGE-LIST(*LIST) = FRENCH LANGUAGE-LIST(*LIST) = GERMAN LANGUAGE-LIST(*LIST) = GREEK LANGUAGE-LIST(*LIST) = ITALIAN