WRITEV Statement

The WRITEV statement writes or updates a single attribute of a file item.

Format

WRITEV expr ON [filevar,] item-ID, attr#

Parameter(s)

expr

An expression evaluating to the dynamic array variable representing the contents of the attribute.

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.

attr#

An expression evaluating to the attribute number to be written. If the number attr# evaluates to is a noninteger value, it is truncated. If this number evaluates to 0, expr is written into Attribute 1 and all existing attributes are pushed up one (i.e., Attribute 1 becomes Attribute 2, Attribute 2 becomes Attribute 3, and so on). If this number evaluates to a negative value, expr is written as the last attribute in the file item, and all previous attributes remain unchanged. In this respect the behavior of the WRITEV statement parallels that of the INS statement.

Description

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

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

Example

In this application, Attribute 6 of the file opened as CUST.FILE contains the customer’s phone number. A new phone number is prompted for, and the new record is then written back into Attribute 6 of the file item.

READVU OriginalPhone FROM CustomerFile,

   CustomerID,6

   THEN

      PRINT ’Current Phone is ’:OriginalPhone

      PRINT ’Is this correct? Y/N’:

   INPUT Response

   Response = OCONV((TRIM(Response))[1,1],’MCU’)

*This ignores spaces, extra characters, and ensures

*that the program only has to consider uppercase

*characters.

BEGIN CASE

CASE Response EQ ’Y’

*Do nothing.

   CASE Response EQ ’N’

      PRINT ’Enter a new phone number:’:

      INPUT NewPhone

      WRITEVU NewPhone ON CustomerFile,CustomerID

   CASE 1

   *They can’t type, so deal with invalid input.

   END CASE

END ELSE

   PRINT CustomerID:’was not found.’

RELEASE CustomerFile,CustomerID

   STOP

END

See Also

Statement and Function Reference