# DIRECT Create File with Keyed Access

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

## Format

**DIRECT** *filename$*,*max\_len*\[,*max_recs*\[,*rec_size*\]\]\[,**ERR**=*stmtref*\]

***Where:***

|  |  |
| --- | --- |
| *filename$* | ***(Required)*** Filename of the Direct (Keyed) file. String expression. |
| *max_len* | ***(Required)*** Maximum length of the key for all records in the file. Numeric expression, integer. |
| *max_recs* | Maximum number of records in the file. Optional numeric expression. The default is 0 (no limit). (Use a *comma* with no value to set the default.) If a positive value is supplied, PxPlus creates and pre-allocates disk space for the file. With a negative value, PxPlus allocates sufficient disk space for the file but will set the *max_recs* count back to 0 (unlimited). |
| *rec_size* | Maximum size of the data portion of each record (excluding the key). Optional. Numeric expression. You can use:<br>\|  \|  \|  \|<br>\| --- \| --- \| --- \|<br>\|  \| *No Value* \| Default is VLR with maximum size of 256 \|<br>\|  \| *Positive Integer* \| FLR of size specified \|<br>\|  \| *Negative Integer* \| VLR with maximum length specified \| |
| *stmtref* | Program line number or statement label to which to transfer control. |

## Description

Use the **DIRECT** directive to create a Direct file with an external key field. PxPlus considers a Direct file to be the same as a Keyed file with an external key. If you use a filename that already exists, PxPlus returns an Error #12: File does not exist (or already exists). The maximum size of the key to the file is mandatory along with the filename. The file type can be controlled by setting the **['KF'=](https://manual.pvxplus.com/parameters/kf)** system parameter.

You can limit the number of records by specifying a maximum (an integer other than 0). If you do attempt to set a maximum, then attempt to exceed this value (e.g. on a **WRITE** statement), an Error #2 is generated. You can use 0 to create a dynamic file, limited by physical file size limits and the amount of available drive space.

If you include the maximum data length, it must be long enough to hold the combined length of all the data fields and field separators for each record written to the file.

Note:  
WindX in PxPlus supports the use of this directive via the \[WDX\] or \[LCL\] tags; e.g. DIRECT "\[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).

## See Also

**[CREATE TABLE Create Keyed File (EFF)](https://manual.pvxplus.com/directives/create-table)**  
**[KEYED Create Single/Multi-Keyed File](https://manual.pvxplus.com/directives/keyed)**

## Example

```
0110 direct A$+"-"+B$,10,100,50,err=1090
0200 direct "CSTFLE",6,0,-128
```

Line 0200 creates a file with the following structure:

|  |  |  |
| --- | --- | --- |
|  | Keyed file: C:\\MANUALS\\PVX\\CST\\CSTFLE |  |
|  | Maximum Record Size: | 128 (variable) |
|  | Maximum # Records: | (No limit) |
|  | Current # Records: | 0 |
|  | Size of Key Block: | 2048 bytes |
|  | External Key Size: | 6 |
