# Data Files

> Source: https://manual.pvxplus.com/pxplus-user-guide/file-handling/data-files/overview

When processing large volumes of data, it becomes necessary to place output into a separate storage area called a *data file.* This generally involves the use of various program instructions for creating the file, opening the file, writing to or reading from the file, and closing the file. Each data file contains a collection of data organized in a specific format and for a specific purpose, which is stored somewhere in external storage.

This section explains how to create data files and describes the various **[Data File Types](https://manual.pvxplus.com/pxplus-user-guide/file-handling/data-files/overview#types)** that are available for use in PxPlus.

## Records and Fields

The contents of a data file is usually grouped into logically-related pieces of information called *records*. Records are generally composed of one or more *fields*, each of which contains a single item of information.

For example, a *Customer* file might contain records, where each record is comprised of three fields: a *Name* field, an *Address* field, and a *Phone* number field. Each record is maintained in the file using a separator between fields. PxPlus uses the character Hex $8A$ as a default field separator:

|  |  |  |  |  |
| --- | --- | --- | --- | --- |
|  | *The default field separator character is a Hex $8A$.* |  |  |  |
|  | ![](https://manual.pvxplus.com/migration-assets/1d2f0f82b53ed4be18d818e80556f3f341afb749bfc7c9008d571419ceae0ab9.gif) | ![](https://manual.pvxplus.com/migration-assets/340694567dea56336d93f039bfe6a8fb507fb0b4058329731c20cf3fb5427982.gif) | ![](https://manual.pvxplus.com/migration-assets/6a7a7ffb0f9c42e4f7a97cc42499cce76e1088558c175580223a82b864ed2097.gif) | ![](https://manual.pvxplus.com/migration-assets/8b0abb8061c071d08d2159aa39e1fa8db551be23309f27d855b075598104be10.gif) |
| *Record 1* | Field 1 | Field 2 | Field 3 | Field 4 |
| *Record 2* | Field 1 | Field 2 | Field 3 | Field 4 |
| *Record 3* | Field 1 | Field 2 | Field 3 | Field 4 |
| *Record 4* | Field 1 | Field 2 | Field 3 | Field 4 |
| *Record 5* | Field 1 | Field 2 | Field 3 | Field 4 |

A number of different PxPlus programs should be able to access this file for writing and retrieving data.

Note:  
The SQL environment uses the terms rows and columns for records and fields. See [Data Integration](https://manual.pvxplus.com/pxplus-user-guide/data-integration/introduction).

## Creating, Deleting and Renaming Data Files

After input and processing operations are complete, the resultant data can be saved to a file that is structured to facilitate future access. PxPlus supports the creation of different types of data files and record formats.

Each of these

***file types*** has its advantages and disadvantages for storing and retrieving data:

|  |  |  |
| --- | --- | --- |
|  | **[Serial](https://manual.pvxplus.com/pxplus-user-guide/file-handling/data-files/serial-files)** | Native OS records can vary in length and are typically accessed in a *sequential* manner from beginning to end. |
|  | **[Indexed](https://manual.pvxplus.com/pxplus-user-guide/file-handling/data-files/indexed-files)** | Records are the same length and are accessed by index number. |
|  | **[Keyed](https://manual.pvxplus.com/pxplus-user-guide/file-handling/data-files/keyed-files)** | This is the most common file type used in PxPlus. Each record has at least one *key* field and up to 15 *alternate keys* for FLR/VLR files (up to 255 for EFF). This type of file may be accessed by any key field, by index, or sequentially. The record formats for keyed files may include FLR (fixed-length records padded with $00$), VLR (variable-length records), and EFF (enhanced file format).  <br>  <br>Keyed files are also categorized according to how the key is being used:<br>\|  \|  \|<br>\| --- \| --- \|<br>\| **[Direct Files](https://manual.pvxplus.com/pxplus-user-guide/file-handling/data-files/keyed-files#direct)** \| Consist of an external key plus data \|<br>\| **[Sort Files](https://manual.pvxplus.com/pxplus-user-guide/file-handling/data-files/keyed-files#sort)** \| Consist of keys but no data \|<br>\| **[Multi-Keyed Files](https://manual.pvxplus.com/pxplus-user-guide/file-handling/data-files/keyed-files#multi_keyed)** \| Consist of one or more keys plus data \| |

The PxPlus file creation directives are designed to not only define data files but to initialize the control information within these files - each is associated with a specific format. The **[ERASE](https://manual.pvxplus.com/directives/erase)** directive is used to delete a file or directory. This deletes all the records from the file and de-allocates the disc space for the file. Two other directives, **[PURGE](https://manual.pvxplus.com/directives/purge)** and **[REFILE](https://manual.pvxplus.com/directives/refile)**, logically delete all records from a file but leave the file defined to the system. The **[FILE](https://manual.pvxplus.com/directives/file)** directive is used to recreate a file given its file description (returned by the **[FIB( )](https://manual.pvxplus.com/functions/fib)** or **[FID( )](https://manual.pvxplus.com/functions/fid)** function). The **[RENAME](https://manual.pvxplus.com/directives/rename)** directive allows the user to rename a file (or, on some operating systems, a directory).

## See Also

**[Processing Data Files](https://manual.pvxplus.com/pxplus-user-guide/file-handling/processing-data-files/overview)**
