|Powered by QM on a Rpi server|
This article was originally published as a Tip of the Week.
There is frequently a need to sort a list of items that is held in a dynamic array. The !SORT() subroutine provides this functionality.
CALL !SORT(in.list, out.list, sort.rule)where
|in.list||The dynamic array to be sorted. Any mark character (or a mix) may be used to separate items. This variable is unchanged on return unless it is also out.list|
|out.list||The variable to received the field mark delimited result.|
|sort.rule||Defines how the sort is to be performed and is any consistent combination
of the following letters:
CUSTOMER.LIST = "" SELECT INVOICES LOOP READNEXT ID ELSE EXIT READ INVOICE.REC FROM INVOICES, ID THEN CUSTOMER.LIST<-1> = INVOICE.REC<CUSTOMER.NAME> END REPEAT CALL !SORT(CUSTOMER.LIST, CUSTOMER.LIST, "AU")The above program fragment reads all the records from the INVOICE file and builds a list of customer names. This is then sorted, removing duplicates.