The function sort_fieldset_array sorts the elements of a FIELDSET array and stores the sorted elements in a second array.
sort_fieldset_array ( input;output;field;number of elements to sort )
The function sort_fieldset_array is of type BOOL, and has four parameters:
The function sort_fieldset_array will return TRUE if the array was sorted successfully, and FALSE in one of the following conditions:
sort_fieldset_array 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. sort_fieldset_array will perform an alphabetical sort on the text elements using the ANSI code page. Note
Any word processor instructions in the text elements are included in the sort, and might cause illogical orderings.
Example
DDATASTRUCTURE DS
BEGIN
ARRAY FIELDSET Array[0]
END
DECLARE input DEFINED_AS DS
DECLARE output DEFINED_AS DS
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_fieldset_array (input.Array; output.Array; "Key"; 4) THEN
FOR i FROM 1 UPTO 4
DO
#
@(i) @(output.Array[i].Key)
#
OD
ELSE
#
Failed to sort the input.
#
STOP
FI
Here the fact that the sort_fieldset_array 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.
Note
The setting EnhancedUnicodeSupport in the ITP/Server Administrator can be used to map the function sort_fieldset_array automatically to the function sort_fieldset_array_characters. Refer to topic Enhanced Unicode support for more details.