# Processing Records

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

File data is usually grouped into **[Records and Fields](https://manual.pvxplus.com/pxplus-user-guide/file-handling/data-files/overview#records)**. The **[File Processing Directives](https://manual.pvxplus.com/pxplus-user-guide/file-handling/processing-data-files/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](https://manual.pvxplus.com/directives/read-record)** directive reads the record specified and places its contents into the string variable specified in the parameter list. The **[WRITE RECORD](https://manual.pvxplus.com/directives/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](https://manual.pvxplus.com/directives/find-record)** and **[EXTRACT RECORD](https://manual.pvxplus.com/directives/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( )](https://manual.pvxplus.com/functions/kec)**, **[KEF( )](https://manual.pvxplus.com/functions/kef)**, **[KEL( )](https://manual.pvxplus.com/functions/kel)**, **[KEN( )](https://manual.pvxplus.com/functions/ken)**, **[KEP( )](https://manual.pvxplus.com/functions/kep)**, **[KEY( )](https://manual.pvxplus.com/functions/key)**, and **[IND( )](https://manual.pvxplus.com/functions/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\*](https://manual.pvxplus.com/file-handling/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)
```
