XREAD, XWRITE

Revised and reviewed May 2012

In A-Shell build 1107 of April 2008, new "eXplicit" variations of READ and WRITE statements were added:

XREAD #CH, RECNO, VAR {,VAR2...,VARN}

XREADL #CH, RECNO, VAR {,VAR2...,VARN}

XREAD'READ'ONLY #CH, RECNO, VAR {,VAR2...,VARN}

XWRITE #CH, RECNO, VAR {,VAR2...,VARN}

XWRITEL #CH, RECNO, VAR {,VAR2...,VARN}

XWRITEN #CH, RECNO, VAR {,VAR2...,VARN}

XWRITELN #CH, RECNO, VAR {,VAR2...,VARN}

 

These are equivalent to the standard versions of these statements (without the "X" and without the RECNO variable), except that instead of getting the record number implicitly, from the variable specified in the OPEN statement, the record number is specified, eXplicitly, in the statement.

While the "X" versions of the READ and WRITE file operations can be used in any context without penalty, there are two specific situations where they are extremely advantageous:

• Within SBX routines, where they eliminate the need to use MX_FLSET to reset the address of the record number variable stored in the file's control structure. See Accessing Open Files for more information.

• In parameterized/generic file operations where you don't know the record size at the time of writing the code. The standard variations of the WRITE statements will abort with a "record size overflow" error if the record variable specified in the WRITE is larger than the record size specified in the OPEN. The XWRITE variants avoid this limitation by automatically truncating the specified record variable to match the record size specified in the OPEN statement.