File Handling

Data Files

 

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 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$.

 

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.

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

Native OS records can vary in length and are typically accessed in a sequential manner from beginning to end.

 

Indexed

Records are the same length and are accessed by index number.

 

Keyed

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).

Keyed files are also categorized according to how the key is being used:

Direct Files

Consist of an external key plus data

Sort Files

Consist of keys but no data

Multi-Keyed Files

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 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 and REFILE, logically delete all records from a file but leave the file defined to the system. The FILE directive is used to recreate a file given its file description (returned by the FIB( ) or FID( ) function). The RENAME directive allows the user to rename a file (or, on some operating systems, a directory).

See Also

Processing Data Files