The function sort_struct_array_index_characters sorts the indices of a DATASTRUCTURE array based on the elements in the array.
sort_struct_array_index_characters ( input;output;member;number of elements to sort )
The function sort_struct_array_index_characters is of type BOOL, and has four parameters:
The function sort_struct_array_index_characters will return TRUE if the array was sorted successfully, and FALSE in one of the following conditions:
sort_struct_array_index_characters fails the output array is unmodified. The input array is not modified by the function. The output array will receive 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. Any word processor instructions in text members are included in the sort, and sort before regular characters.
Example
DATASTRUCTURE EL
BEGIN
TEXT Key
END
DATASTRUCTURE DS
BEGIN
ARRAY FIELDSET Array[0]
END
DECLARE input DEFINED_AS DS
ARRAY NUMBER output[4]
NUMBER i
ASSIGN input.Array[1].Key := "c"
ASSIGN input.Array[2].Key := "d"
ASSIGN input.Array[3].Key := "a"
ASSIGN input.Array[4].Key := "b"
IF sort_struct_array_index_characters (input.Array; output; "Key"; 4) THEN
FOR i FROM 1 UPTO 4
DO
#
@(i) @(output.Array[ output[i] ].Key)
#
OD
ELSE
#
Failed to sort the input.
#
STOP
FI
Here the fact that the sort_struct_array_index_characters is a function of type BOOL is used to implement error handling. If the sort succeeds the return value of the function will be 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.
This example produces the same result as the example included with the function sort_struct_array_characters.