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 should be sorted in descending order. The default sort order is ascending.

TO table_name

Specify TO table_name to write 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 an existing folder to write the .FIL file to.

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

IF test

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

WHILE test

Optional. Specifies that the command should only be executed while a condition is true. The command processing terminates as soon as the specified test 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 should be appended to the end of an existing file instead of overwriting the existing file. You must ensure that the structure of the two files is identical when using this parameter, if maintaining a consistent file structure is important (e.g., 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 should be 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) 2013 ACL Services Ltd. All Rights Reserved. | Send feedback