WRITE Statement

The WRITE statement writes a file item into a file.

Format

WRITE expr ON [filevar,] item-ID {ON ERROR stmts}

Parameter(s)

expr

An expression evaluating to the dynamic array representing the contents of the file item.

filevar

File variable to which the file had been opened. If filevar is not specified, the default file variable is used, which is the file most recently opened without a file variable assignment.

item-ID

An expression evaluating to the item-ID to be written.

{ON ERROR stmts}

Statements in the ON ERROR clause are executed if the WRITE fails.

Description

The WRITE statement writes a new value to the specified item of a file. Any data previously stored in the specified file item is overwritten. If the item does not exist, a new item is created.

When updating a file, the WRITE statement releases the record update lock set with a READVU or MATREADU statement. To maintain the record update lock as it was set by the READVU or MATREADU statement, use a WRITEU statement instead of WRITE. See WRITEU Statement for more information.

When in the ON ERROR clause, SYSTEM(0) indicates the reason for the error.

Example

In this application, Attribute 6 contains the customer’s phone number. A new phone number is prompted for and then placed into Attribute 6. The new record is then written back into the file.

PRINT "ENTER THE NEW PHONE NUMBER: ":

INPUT NEW.PHONE

CUST.REC<6> = NEW.PHONE

WRITE CUST.REC ON CUSTFILE,ITEM.ID

See Also

Statement and Function Reference