## 26. Func='sorted' Func='sorted_desc' Sorting input

Example 26.1

)text out='myqueue'

9

25

121

2

)endtext

)action in='myqueue'

)& func='sorted'

'square of' word.1 'is' word.1**2

)endaction

Output is:

square of 2 is 4

square of 9 is 81

square of 25 is 625

square of 121 is 14641

func='sorted' performs a sorting of the input before it is presented to the action block.

Input records are sorted ascending on the value of unit.1.

If all values of unit.1 are numeric, a numeric sort is performed; otherwise an alphanumeric sort is performed:

Example 26.2

Alphanumeric sort:

)text out='myqueue'

9

25

UPS

121

2

)endtext

)action in='myqueue'

)& func='sorted'

unit.1

)endaction

Output will be like this (Sorting is primarily on byte 1, that is 121 is ranked before 2 etc.):

UPS

121

2

25

9

If unit.2 is present in input, it will also participate in the sort. In this case unit.1 is the sorting key of the item and unit.2 is the value of the item:

Example 26.3

)action out='myqueue'

25, 'Winnie the Pooh'

121, 'Cinderella'

)endaction

)action in='myqueue'

)& func='sorted'

unit.2

)endaction

Output is:

Winnie the Pooh

Cinderella

If length of any input (unit.1) record exceeds 256, then consider putting input in unit.2 and create a sort criteria in unit.1.

If length of any input (unit.1) record exceeds 256 and is less than 4000, and if unit.2 is not used, the sorting schema changes to a alphanumeric sort of unit.1.

If

·       the length of any unit.1 in input is larger than 4000

·       the length of any unit.1 is larger than 256 and unit.2 is used

then the sort in RXS is terminated in error

### 26a. Sorted_desc

func='sorted_desc' works like func='sorted', except that a descending sort on unit.1 is performed.