Sorta

Sorta is used to sort arrays of single-dimensioned variables.

Syntax

Sorta ARRAY_LISTSorta NUMBER ARRAY_LISTSorta ARRAY_LIST Order By EXPRESSION_LISTSorta NUMBER ARRAY_LIST Order By EXPRESSION_LISTSorta ARRAY_LIST ASCDESSorta NUMBER ARRAY_LIST ASCDESSorta ARRAY_LIST Order By EXPRESSION_LIST ASCDESSorta NUMBER ARRAY_LIST Order By EXPRESSION_LIST ASCDES

Example

You have three arrays called COMPOSER(1..11), FIRST_NAME(1..11), and BIRTH_YEAR(1..11). In this example, you can see the original order and the final order after the Sorta instruction, depending on the syntax:





































Sorta 10 BIRTH_YEAR, COMPOSER, FIRST_NAME
Original orderSorting order
#COMPOSERFIRST_NAMEBIRTH_YEAR
1HAENDELGeorg1685
2BACHJohann1685
3STRAUSSJohann1804
4BEETHOVENLudwig1770
5SCHUBERTFrantz1797
6WAGNERRichard1813
7STRAUSSJohann1825
8STRAUSSRichard1864
9BERGAlban1885
10MOZARTWolfgang1756
110

#COMPOSERFIRST_NAMEBIRTH_YEAR
1BACHJohann1685
2HAENDELGeorg1685
3MOZARTWolfgang1756
4BEETHOVENLudwig1770
5SCHUBERTFrantz1797
6STRAUSSJohann1804
7WAGNERRichard1813
8STRAUSSJohann1825
9STRAUSSRichard1864
10BERGAlban1885
110

Sorta BIRTH_YEAR, COMPOSER, FIRST_NAME
Original orderSorting order

#COMPOSERFIRST_NAMEBIRTH_YEAR
1HAENDELGeorg1685
2BACHJohann1685
3STRAUSSJohann1804
4BEETHOVENLudwig1770
5SCHUBERTFrantz1797
6WAGNERRichard1813
7STRAUSSJohann1825
8STRAUSSRichard1864
9BERGAlban1885
10MOZARTWolfgang1756
110

#COMPOSERFIRST_NAMEBIRTH_YEAR
10
2BACHJohann1685
3HAENDELGeorg1685
4MOZARTWolfgang1756
5BEETHOVENLudwig1770
6SCHUBERTFrantz1797
7STRAUSSJohann1804
8WAGNERRichard1813
9STRAUSSJohann1825
10STRAUSSRichard1864
11BERGAlban1885

Sorta 10 COMPOSER,FIRST_NAME,BIRTH_YEAR Order By COMPOSER(indice+1), -BIRTH_YEAR(indice+1), FIRST_NAME(indice+1)
Original orderSorting order

#COMPOSERFIRST_NAMEBIRTH_YEAR
1HAENDELGeorg1685
2BACHJohann1685
3STRAUSSJohann1804
4BEETHOVENLudwig1770
5SCHUBERTFrantz1797
6WAGNERRichard1813
7STRAUSSJohann1825
8STRAUSSRichard1864
9BERGAlban1885
10MOZARTWolfgang1756
110

#COMPOSERFIRST_NAMEBIRTH_YEAR
1BACHJohann1685
2BEETHOVENLudwig1770
3BERGAlban1885
4HAENDELGeorg1685
5MOZARTWolfgang1756
6SCHUBERTFrantz1797
7STRAUSSRichard1864
8STRAUSSJohann1825
9STRAUSSJohann1804
10WAGNERRichard1813
110

Sorta 10 COMPOSER,FIRST_NAME,BIRTH_YEAR Order By FIRST_NAME(indice+1),NAME(indice+1),-BIRTH_YEAR(indice+1) Desc
Original orderSorting order

#COMPOSERFIRST_NAMEBIRTH_YEAR
1HAENDELGeorg1685
2BACHJohann1685
3STRAUSSJohann1804
4BEETHOVENLudwig1770
5SCHUBERTFrantz1797
6WAGNERRichard1813
7STRAUSSJohann1825
8STRAUSSRichard1864
9BERGAlban1885
10MOZARTWolfgang1756
110

#COMPOSERFIRST_NAMEBIRTH_YEAR
1MOZARTWolfgang1756
2WAGNERRichard1813
3STRAUSSRichard1864
4BEETHOVENLudwig1770
5BACHJohann1685
6STRAUSSJohann1804
7STRAUSSJohann1825
8HAENDELGeorg1685
9SCHUBERTFrantz1797
10BERGAlban1885
110

Comments

Example of unexpected result when indice is used for arrays starting at index 1:





Sorta 5 COMPOSER,FIRST_NAME, BIRTH_YEAR Using -BIRTH_YEAR(indice),COMPOSER(indice)
Original orderSorting order
#COMPOSERFIRST_NAMEBIRTH_YEAR
1HAENDELGeorg1685
2BACHJohann1685
3STRAUSSJohann1804
4BEETHOVENLudwig1770
5SCHUBERTFrantz1797

#COMPOSERFIRST_NAMEBIRTH_YEAR
1BEETHOVENLudwig1770
2SCHUBERTFrantz1797
3STRAUSSJohann1804
4BACHJohann1685
5HAENDELGeorg1685

The reason is that the array was sorted in the order of the following expressions:

Associated errors

Error codeDescription
8Incorrect index value.
10NUMBER is not a numeric expression.
50NUMBER is negative.

See also