|Powered by QM on a Rpi server|
KnowledgeBase 00085: Sorting Dynamic Arrays
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.
The !SORT() SubroutineThe subroutine is called as
CALL !SORT(in.list, out.list, sort.rule)where
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.