Synergy block file I/O

Synergy block file I/O is used to access files and block devices on a binary basis. All I/O to or from the file must be in multiples of 512 bytes. (For most operating systems, a minimum of 4096 bytes at a time is most efficient.) This type of I/O bypasses the file organization and retrieves or writes the raw data to and from the file or device.

Block file structure

The block submode is a way to bypass the native file organization to manipulate the binary data in a file in multiples of 512-byte blocks.

Block file types

There is no specific block file type on any system. Block file I/O is only a way to access the raw data in a file.

You can create a file in block mode by specifying a mode of O:B or A:B in the OPEN statement. To open an existing relative file, specify the mode as I:B, U:B, or A:B on the OPEN statement.

Data access

Data is accessed randomly if you specify the block number as a numeric field in the key field of READ, FIND, and WRITE statements, or sequentially using the READS or WRITES statements.

Block mode input and output statements

This section lists the primary input and output statements and describes how their use affects block I/O. See Synergy DBL Statements for information about other statement qualifiers that are not specific to block mode access.

READ statement

read(channel, block, block_number)

You can use the READ statement to retrieve records from the file by specifying block_number. To specify the first or last record in the file, replace the block number in the READ statement with ^FIRST or ^LAST, respectively. The POSITION qualifier can replace ^FIRST or ^LAST.

FIND statement

find(channel, block, block_number)

The FIND statement positions to the block specified by block_number. To position to the first or last block in the file, replace the block number in the FIND statement with ^FIRST or ^LAST. To position to the beginning (before the first block) or end (after the last block) of the file, replace the block number in the FIND statement with ^BOF or ^EOF, respectively. The POSITION qualifier can replace ^FIRST, ^LAST, ^BOF, or ^EOF.

WRITE statement

write(channel, block, block_number)

You can use the WRITE statement to update blocks or add blocks to the file by specifying the block number. To specify the first or last block in the file, replace the block number in the WRITE statement with ^FIRST or ^LAST, respectively. The POSITION qualifier can replace ^FIRST or ^LAST. To extend a file opened in update mode, specify the block at the current end-of-file position.

READS statement

reads(channel, block, eof_label)

The READS statement retrieves the next sequential block in the file.

WRITES statement

writes(channel, block)

The WRITES statement updates the next sequential block in the file. If the file is opened in append or output mode, the operation adds the next sequential block to the file.

%RSIZE function

size = %rsize

The %RSIZE (or %RDLEN) function retrieves the size of the last block read. When the end-of-file block is read, size is the actual number of bytes contained in that block. The value returned is for the last operation, regardless of the channel used.