sort_text_array

The sort_text_array function sorts the elements of a text array and stores the sorted elements in a second array.

 sort_text_array ( input;output;number of
elements to sort )

The function sort_text_array is of type BOOL.

The function has three parameters:

  1. input; ARRAY of type TEXT. This array contains the elements that must be sorted.
  2. output; ARRAY of type TEXT. This array receives the sorted elements.
  3. number of elements to sort; NUMBER. This is the number of elements in the array that must be sorted starting from the first element. This can either be a number or a NUMBER variable or expression.

The function sort_text_array returns TRUE if the array was sorted successfully, and FALSE in one of the following conditions:

  • If number of elements to be sorted is negative or 0.
  • If the function sort_text_array fails the output array is unmodified. The input array is not modified by the function. The output array receives the sorted values from the input array. If the output array is larger than the number of sorted elements, those elements outside the sorted range are left unmodified.
  • The function sort_text_array performs an alphabetical sort on the text elements using the ANSI code page.

All Microsoft Word instructions in the text elements are included in the sort and might cause unexplainable orderings.

An example is provided here.

ARRAY TEXT input [4]
ARRAY TEXT output[4]
NUMBER i
ASSIGN input[1] := "c"		 
ASSIGN input[2] := "d"
ASSIGN input[3] := "a"
ASSIGN input[4] := "b"
IF sort_text_array (input; output; 4) THEN
  FOR i FROM 1 UPTO 4
DO
#
@(i) @(output[i])
#
OD

ELSE
#
Failed to sort the input.
#
  STOP
FI

The type BOOL of the sort_text_array function is used to implement error handling. If the sort succeeds, the return value of the function is TRUE, the IF statement becomes TRUE, and the THEN part is executed. If the return is FALSE, the ELSE part of the IF statement is executed.

The setting EnhancedUnicodeSupport in KCM Core Administrator can be used to map the function sort_text_array automatically to the function sort_text_array_characters (see sort_text_array_characters). For more information, see Enhanced Unicode Support.