# SORT Create File for Sorting

> Source: https://manual.pvxplus.com/directives/sort

## Format

**SORT** *filename$*,*max\_keysize*\[,*max_rec*\]\[,**ERR**=*stmtref*\]

***Where:***

|  |  |
| --- | --- |
| *filename$* | Name of the **SORT** file to create. String expression. |
| *max_keysize* | Maximum key size to be maintained for this file. Numeric expression. |
| *max_rec* | Estimated number of records that the file is to contain. Default is no initial allocation of file space with no limit on final size. Numeric expression. |
| *stmtref* | Program line number or statement label to which to transfer control. |

## Description

Use the **SORT** directive to create a data Sort file (a file with a key but no data record portion). You must include the size of the key along with the name. The maximum Sort key size allowed is 127. If the given filename already exists, PxPlus returns an Error #12: File does not exist (or already exists).

The type of file created can be determined by setting the **['KF'=](https://manual.pvxplus.com/parameters/kf)** system parameter. If **'KF'** is not zero, then the Sort file will be created as an EFF file. Only through the use of the **'KF'** parameter will Sort files be created as EFF files.

Note:  
WindX in PxPlus supports the use of this directive via the \[WDX\] or \[LCL\] tags; e.g. SORT "\[WDX\]somefile.ext". Non-PxPlus versions require you to encapsulate the command in an EXECUTE directive with a \[WDX\] tag (i.e. EXECUTE "\[WDX\]..."). See [\[WDX\] Direct Action to Client Machine](https://manual.pvxplus.com/command-tags/wdx) or [\[LCL\] Access to Users Local Machine](https://manual.pvxplus.com/command-tags/lcl).

## Example

***Example 1:***

```
0010 sort "CSTFLE",6,100
```

This line creates a file with the following structure:

|  |  |  |
| --- | --- | --- |
|  | Keyed file: C:\\OTHER\\MANUALS\\PVX\\CST\\CSTFLE |  |
|  | Maximum Record Size: | 0 (Sort file) |
|  | Maximum # Records: | 100 |
|  | Current # Records: | 0 |
|  | Size of Key Block: | 2048 bytes |
|  | External Key Size: | 6 |

***Example 2:***

```
0010 sort A$+"_"+B$,10,100,err=1090
```

This line creates the following structure:

|  |  |  |
| --- | --- | --- |
|  | Keyed file: C:\\OTHER\\MANUALS\\PVX\\CST\\CST_TST |  |
|  | Maximum Record Size: | 0 (Sort file) |
|  | Maximum # Records: | 100 |
|  | Current # Records: | 0 |
|  | Size of Key Block: | 3072 bytes |
|  | External Key Size: | 10 |
