READBLK statement
Syntax
READBLK variable FROM file.variable, blocksize{ THEN statements [ ELSE statements ] | ELSE statements }
Description
Use the READBLK statement to read a block of data of a specified length from a file opened for sequential processing and assign it to a variable. The READBLK statement reads a block of data beginning at the current position in the file and continuing for blocksize bytes and assigns it to variable. The current position is reset to just beyond the last byte read.
file.variable specifies a file previously opened for sequential processing.
If the data can be read from the file, the THEN statements are executed; any ELSE statements are ignored. If the file is not readable or if the end of file is encountered, the ELSE statements are executed and the THEN statements are ignored. If the ELSE statements are executed, variable is set to an empty string.
If either file.variable or blocksize evaluates to the null value, the READBLK statement fails and the program terminates with a run-time error message.
In the event of a timeout, READBLK returns no bytes from the buffer, and the entire I/O operation must be retried.
The difference between the READSEQ statement and the READBLK statement is that the READBLK statement reads a block of data of a specified length, whereas the READSEQ statement reads a single line of data.
On Windows systems, if you use READBLK to read data from a 1/4-inch cartridge drive (60 or 150 MB) that you open with the OPENDEV statement, you must use a block size of 512 bytes or a multiple of 512 bytes.
For more information about sequential file processing, see the OPENSEQ statement, READSEQ statement, and WRITESEQ statements.
If NLS is enabled and file.variable has a map associated with it, the data is mapped accordingly.
Example
OPENSEQ 'FILE.E', 'RECORD4' TO FILE ELSE ABORT
READBLK VAR1 FROM FILE, 15 THEN PRINT VAR1
PRINT
READBLK VAR2 FROM FILE, 15 THEN PRINT VAR2
This is the program output:
FIRST LINE
SECO
ND LINE
THIRD L