|Note||This command is defined in a header file and will be preprocessed by the X# preprocessor to a function call. If you disable the standard header (-nostddefs) files then this command will not be available. If you tell the compiler to use a different standard header file (-stddef ) then this command may also be not available|
Copy records from the current work area to a database file in sorted order.
SORT TO <xcTargetFile> ON <idFieldList> [<Scope>] [WHILE <lCondition>] [FOR <lCondition>]
|TO <xcTargetFile>||The name of the target database file to write the sorted records, including an optional drive, directory, and extension. See SetDefault() and SetPath() for file searching and creation rules. The default extension for database files is determined by the RDD.|
|If <xcTargetFile> does not exist, it is created. If it exists, this command attempts to open the file in exclusive mode and, if successful, the file is overwritten without warning or error. If access is denied because, for example, another process is using the file, NetErr() is set to TRUE.|
|ON <idFieldList>||The sort keys, specified as a comma-separated list of field names. You may optionally add, after each field name, /A (to sort in dictionary order), /C (to ignore capitalization), or /D (to sort in descending order). The default setting is /A.|
|<Scope>||The portion of the current database file to process. The default is all visible records. Scope is one or more clauses of:|
[NEXT <NEXT>] Optionally specifies the number of records to process starting
with the first record of the source file.
[RECORD <rec>] An optional record ID If specified, the processing begins
with this data record in the source file.
[<rest:REST>] The option REST specifies whether records are sequentially
searched only from the current up to the last record.
If a condition is specified, the option ALL is the default value.
[ALL] The option ALL specifies that all records from the source file are imported.
This is the default setting.
|WHILE <lCondition>||A condition that each visible record within the scope must meet, starting with the current record. As soon as the while condition fails, the process terminates. If no <Scope> is specified, having a while condition changes the default scope to the rest of the visible records in the file.|
|FOR <lCondition>||A condition that each visible record within the scope must meet in order to be processed. If a record does not meet the specified condition, it is ignored and the next visible record is processed. If no <Scope> or WHILE clause is specified, having a for condition changes the default scope to all visible records.|
SORT is functionally equivalent to DBSort().
This example copies a mailing list using a descending sort key to a smaller list for printing:
USE mailing INDEX zip
SORT ON Lastname /D, Firstname /D TO invite ;
WHILE Zip = "900"
USE invite NEW
REPORT FORM rsvplist TO PRINTER
ASort(), DbSort(), FLock(), INDEX,SetDefault(), SetPath(), USE