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. 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. The STATUS() function will return an error number. If no ON ERROR clause is present, an abort would occur.

 

 

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.