Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

SORT-VARIABLE Sort list variable

&pagelevel(4)&pagelevel

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 and BCD:

    ABC < BC and ABC < BCD and BC < BCD

    Sorting in ascending order results in the sequence ABC, BC and BCD.

    • 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


    0CMD0001No error
    10SDP2000Warning: some elements could not be sorted

    64SDP2001None 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