2 Sort Statements and Functions

The READ # and PRINT # Statements

The READ # and PRINT # statements operate on workfiles in much the same way as they operate on DATA files. Although their syntax is identical, certain restrictions apply when operating on workfiles.

The first restriction is that only an integral number of logical records can be read or written. If a partial logical record is read, an error is issued and the record pointer is left at word one of the incompletely read record. If a partial logical record is written, the incompletely written record is not changed; instead, the record pointer at the beginning of that record and an error is issued. Strings cannot be read or written on workfiles. Arrays can be written or read by using the array notation (i.e. A(*), or via MAT PRINT # and MAT READ #.

Note that a pointer value is a value between 1 and the capacity of the set to which it pertains.

If a non-integral value is PRINTed on a workfile, it is rounded to an integer. If the rounded value is less than 1 or greater than the set capacity, an error occurs.

The record pointer for READ # and PRINT # can be positioned at any record from 1 through WFLEN + 1. Attempting to position past record number WFLEN + 1 results in an end-of-file error (which is trappable by ON END #). When printing to records greater than WFLEN, the value of WFLEN is adjusted appropriately. However, actually trying to read values in records beyond WFLEN causes end-of-file error.

PRINTing an END on a workfile resets WFLEN to a value corresponding to the record where END was printed -1. This effectively erases all information from the record where END was printed to the end of the workfile.

Other Statements and Functions

Certain statements and functions behave differently when applied to workfiles. Briefly, these are:

TYP
Returns 0 since the data stored in a workfile is not a standard data type. (Each pointer may have a value from 1 through 231 and takes 4 bytes of storage.)
WRD
Always returns 1. Since only complete logical records can be read from or written to a workfile, the word pointer of the file will always be the first word of the record.
REC
Works the same as DATA files. The value returned will be between 1 and WFLEN + 1. If no pointers are put into the workfile, however, 0 is returned.
SIZE
Returns file size in sectors for a positive argument, and thread length for a negative argument.
RESET #
Erases the workfile. Result is same as WORKFILE IS #; THREAD.

Eloquence Sort Manual - 19 DEC 2002