The WRITEBLK statement writes a block of data to a file opened for sequential processing.



WRITEBLK expression ON file.variable {THEN statements [ELSE statements]|ELSE statements}


Each WRITEBLK statement writes the value of expression starting at the current position in the file. The current position is incremented to beyond the last byte written. WRITEBLK does not add a new line at the end of the data.

file.variable specifies a file opened for sequential processing. The value of expression is written to the file, and the THEN statements are executed. If no THEN statements are specified, program execution continues with the next statement. If the file is neither accessible or does not exist, it executes the ELSE statements; and ignores any THEN statements.

If either expression or file.variable evaluates to null, the WRITEBLK statement fails and the program enters the debugger with a run-time error message.



When using the WRITEBLK statement in International Mode, care must be taken to ensure that the write variable is handled properly before the WRITEBLK statement.

The WRITEBLK statement expects the output variable to be in “bytes”, however when manipulating variables in International Mode character length rather than byte lengths are usually used and hence possible confusion or program malfunction can occur. If requiring byte count data the output variable can be converted from the UTF-8 byte sequence to ‘binary/latin1’ via the LATIN1 function.

It is not recommended that you use the READBLK/WRITEBLK statements when executing in International Mode. You can obtain similar functionality via the READSEQ/WRITESEQ statement, which can be used to read/write, characters a line at a time from a file.