SORT
Copy to a database (.dbf) file in sorted order
Syntax
SORT TO <xcDatabase> ON <idField1> [/[A | D][C]]
[, <idField2> [/[A | D][C]]...]
[<scope>] [WHILE <lCondition>] [FOR <lCondition>]
Arguments
TO <xcDatabase> is the name of the target file for the sorted records and can be specified either as a literal file name or as a character expression enclosed in parentheses. Unless otherwise specified, the new file is assigned a (.dbf) extension.
ON <idField> is the sort key and must be a field variable.
/[A|D][C] specifies how <xcDatabase> is to be sorted. /A sorts in ascending order. /D sorts in descending order. /C sorts in dictionary order by ignoring the case of the specified character field. The default SORT order is ascending.
<scope> is the portion of the current database file to SORT. The default is ALL records.
WHILE <lCondition> specifies the set of records meeting the condition from the current record until the condition fails.
FOR <lCondition> specifies the conditional set of records to SORT within the given scope.
Description
SORT is a database command that copies records from the current work area to another database file in sorted order. Clipper SORTs character fields in accordance with the ASCII value of each character within the string unless the /C option is specified. This option causes the database file to be sorted in dictionary order–capitalization is ignored. Numeric fields are sorted in numeric order, date fields are sorted chronologically, and logical fields are sorted with true (.T.) as the high value. Memo fields cannot be sorted.
SORT performs as much of its operation as possible in memory, and then, it spools to a uniquely named temporary disk file. This temporary file can be as large as the size of the source database file. Note also that a SORT uses up three file handles: the source database file, the target database file, and the temporary file. In a network environment, you must lock the database file to be SORTed with FLOCK() or USE it EXCLUSIVEly.
Notes
. Deleted source records: If DELETED is OFF, SORT copies deleted records to the target database file; however, the deleted records do not retain their deleted status. No record is marked for deletion in the target file regardless of its status in the source file.
If DELETED is ON, deleted records are not copied to the target database file. Similarly, filtered records are ignored during a SORT and are not included in the target file.
Examples
. This example copies a sorted subset of a mailing list to a
smaller list for printing:
USE Mailing INDEX Zip
SEEK "900"
SORT ON LastName, FirstName TO Invite WHILE Zip = "900"
USE Invite NEW
REPORT FORM RsvpList TO PRINTER
Seealso
ASORT(), FLOCK(), INDEX, USE