SORT command

Used to sort records in ACL table into ascending or descending order based on specified key fields and writes the results to a new table.


SORT ON {key_field <D>} <...n> TO tablename <IF test> <WHILE test>
<{FIRST|NEXT} range> <APPEND> <OPEN> <ISOLOCALE locale_code>


ON key_field

Specifies the key fields or expressions to use for sorting.


Optional. Specifies that key fields are sorted in descending order. The default sort order is ascending.

TO table_name

Specify TO table_name to save the results to an ACL table. You must specify the table_name value as a quoted string with a .FIL file extension to create an ACL table.

For example: TO "Output.FIL"

You can also specify an absolute or relative file path to save the .FIL file to an existing folder.

For example: TO "C:\Output.FIL" or TO "Results\Output.FIL"

IF test

Optional. Specifies a condition that must be met. The command is executed on only those records that meet the condition.

WHILE test

Optional. Specifies that the command is executed only while a condition is true. The command processing terminates as soon as the specified condition evaluates as false, or the end of the table is reached.

FIRST | NEXT range

Optional. Specify FIRST to start processing at the first record or NEXT to start processing at the currently selected record. Use the range value to specify the number of records to process.


Optional. Specifies that command output is appended to the end of an existing file instead of overwriting it. When using this parameter, you must ensure that the structure of the command output and the existing file is identical, if maintaining a consistent file structure is important (for example, when you are appending data to an existing ACL table), because ACL appends output to an existing file regardless of its structure.


Optional. Specifies that the table created by the command is opened after the command executes. This parameter is only valid if the command creates an output table.

ISOLOCALE locale_code

Optional. This parameter is only available in the Unicode edition of ACL. Specifies the locale. If you do not specify a locale, ACL uses the default locale. Locale codes are based on the ISO 639 standard language codes and the ISO 3166 standard country codes. Enter locale_code in the format language code_country code. For example, enter the code fr_ca for Canadian French. If you do not specify a country, ACL uses the default country for the language.


The SORT command creates a new ACL table that has been physically reordered. The command can be used on both fixed-length and variable-length data files.


The following command first sorts the records in the Transactions table by branch and then sorts the records for each branch by date in descending order. The sorted records are extracted to a new ACL table called trans_by_branch.

OPEN Transactions
SORT ON branch date D TO “trans_by_branch.fil”
Related reference
INDEX command

(C) 2015 ACL Services Ltd. All Rights Reserved.