SORT example
Suppose you have a large table and you want to delete any duplicate records, records that have the same value in 6 important fields. The easiest way to remove duplicate records in general is to index the table so that all duplicate records are next to each other. Unfortunately, some of the 6 important fields are large; the resulting the index key would be larger than the allowed limit, 100 characters. So you sort the table to a temporary table instead.
use THETABLE
sort to SORTTEMP on FIELD1, FIELD2, FIELD3, FIELD4, FIELD5, FIELD6
use SORTTEMP
set fields to KEY = FIELD1 + FIELD2 + FIELD3 + FIELD4 + FIELD5 + FIELD6
local cKey
do while .not. eof( )
cKey = KEY
skip
delete while KEY == cKey
enddo
clear fields
SET FIELDS is used to create a temporary calculated field to make it easier to compare the important field values for each record.