Processing Data Files

Processing Records

 

File data is usually grouped into Records and Fields. The File Processing Directives are typically used to read/write records in a file separating the data into one or more fields.

Record-Specific Directives

In some cases, it is necessary to read the contents of a record from a file that does not contain fields; e.g. when reading data files not created by PxPlus or writing data files that are to be processed by some other application. To handle files of this type, PxPlus includes a set of record-specific directives. In these cases, only a single string parameter can be specified in the parameter list.

The READ RECORD directive reads the record specified and places its contents into the string variable specified in the parameter list. The WRITE RECORD directive writes the string specified in the parameter list to the file without the insertion of a field separator. If the file contains fixed length records, the WRITE RECORD statement will append nulls (Hex $00$) to the record being written. Other record-specific directives include FIND RECORD and EXTRACT RECORD.

Example:

0010 OPEN INPUT (1) "." ! open current directory
0020 READ RECORD (1,END=DONE)R$
0030 PRINT R$
0040 GOTO 0020
0050 DONE: CLOSE (1); END
run

*MEMORY* File

A *MEMORY* logical file is simply a memory-resident queue of records that can be accessed by index or (external) record key. The system functions KEC( ), KEF( ), KEL( ), KEN( ), KEP( ), KEY( ), and IND( ) will work with a memory file. As well, you can access memory files by record number, RNO( ). The record index will equal the logical placement of the records in key order sequence.

See *MEMORY* for complete syntax details.

Creating/Deleting the File

Two types of memory files may be created. The following syntax creates a memory-resident queue of records:

OPEN (chan) " *MEMORY* "

The following creates a memory-resident multi-key file similar to a regular-keyed file:

OPEN (chan [,fileopt ])" *MEMORY* [ ; KEYDEF=key_def$]"

The following syntax deletes a memory file and returns memory to the system:

CLOSE (chan)

Keyed (Direct File) Handling

The following syntax adds/updates a record:

WRITE (chan, KEY= string$) iolist 

or

WRITE RECORD (chan, KEY= string$) strexpr

To read a record:

READ (chan, KEY= string$) iolist 

or

READ RECORD (chan, KEY= string$) strvar

To remove a record:

REMOVE (chan, KEY= string$) iolist

Indexed Handling

The following syntax writes to the open file:

WRITE (chan, IND= num) iolist 

or

WRITE RECORD (chan, IND= num) strexpr

This will insert records at the specified point in the memory queue file. It will insert and not overwrite the existing records. If you currently have 5 records in the file and issue a WRITE (chan,IND=3), the record formerly at index 4 will now be at index 5.

To read a record:

READ (chan, IND= num) iolist 

or

READ RECORD (chan, IND= num) strvar

To remove a record:

REMOVE (chan, IND= num)