WRITEBLK Statement

Appends data to a host file or Reality item that has been opened for sequential access.

Syntax

WRITEBLK data [ON || TO] seqfile-var {SETTING setting-var} {ON ERROR statement(s)} [ THEN statement(s) | ELSE statement(s) ]

Syntax Elements

data A string expression that evaluates to the data to be written.

seqfile-var is the name of a variable containing a sequential file reference (assigned via an OPENSEQ statement).

setting-var The name of a variable to which the return status is assigned. See Operation for details of the possible values for this variable.

statement(s) A sequence of one or more valid DataBasic statements, either separated by semicolons, or contained on separate lines and followed by an END statement.

Operation

The following details circumstances under which the different clauses are executed and the values returned in setting-var:

Clause Executed Reason setting-var STATUS() Value
THEN Write successful 0 0
ELSE Not at end of file or item 2420 206
ON ERROR File or item opened, but not for sequential access (not opened with OPENSEQ) B45 12
  File or item not open B12 12
  General file error Error number Error number

Notes:

Comments

You can only write if the current position is at the end of the file (see Writing to a Sequential File).

If the file or item does not exist, it is automatically created.

If a record size was specified when the file was opened for sequential access, the data will be padded with NUL characters (X'00') until its length is a multiple of the record size.

It is recommended that you always include an ON ERROR clause. If you do not and an error occurs at run time, your program will abort. This is particularly important if the file has a PRE-WRITE trigger that may cancel the CLOSESEQ operation.

Example

OPENSEQ APPENDING "/usr/pauls/qa4" TO SF1 THEN NULL
WRITEBLK DATA TO SF1 SETTING ERRVAR THEN NULL
IF ERRVAR <> 0 THEN PRINT "Write error!"
CLOSESEQ SF1

This program opens the host file /usr/pauls/qa4 for appending and saves a reference to the open file in variable SF1. The program then writes the contents of the variable DATA to the file, setting the variable ERRVAR to the WRITEBLK statement's return value. If an error occurs the message Write error! is displayed. Finally the file is closed.

See Also

WRITESEQ statement, OPENSEQ statement, CLOSESEQ statement, READSEQ statement, READBLK statement, SEEK statement, DELETESEQ statement, WEOFSEQ statement.

Go to top button