WRITE, WRITEU

Top  Previous  Next

 

The WRITE statement writes a record to a previously opened file. The WRITEU statement is identical but preserves any lock on the record.

 

 

Format

 

WRITE var TO file.var, record.id {ON ERROR statement(s)}

 

where

 

varis the name of a variable containing the data to be written.

 

file.varis the file variable associated with the file.

 

record.idevaluates to the id of the record to be written.

 

statement(s)are statements to be executed if the write fails.

 

The keyword ON may be used in place of TO.

 

 

The contents of var are written to the file. Any existing record of the same id is replaced by this action.

 

When writing to a directory file, field marks in the data to be written are replaced by newlines. This action may be suppressed by using the MARK.MAPPING statement after opening the file.

 

The WRITE statement releases any read or update lock on this record. The WRITEU statement preserves the lock. Within a transaction, the lock is retained until the transaction terminates and then released regardless of which statement is used. Attempting to write a record in a transaction will fail if the process does not hold an update lock on the record or the file.

 

The ON ERROR clause is executed for serious fault conditions such as errors in a file's internal control structures. It is also executed if the write operation is disallowed by a pre-write trigger function associated with the file. The STATUS() function will return an error number. If no ON ERROR clause is present, an abort would occur.

 

When writing a new record to a directory file on a Linux or Unix system, the operating system level file that represents the QM record is created using the current umask value. For sessions that connect directly to QM rather than from the operating system shell (direct telnet and QMClient), the umask value is specified by the UMASK configuration parameter or, if this parameter is not present, a default of 002. This behaviour can be modified by executing a UMASK command within the session.

 

 

Example

 

WRITE ITEM TO STOCK, ITEM.ID

 

This statement writes the content of ITEM to a record with the id in ITEM.ID on the file previously opened to file variable STOCK.