READVU Statement

Locks a file item, then reads an attribute value from the item and assigns its string value to a specified variable.

Syntax

READVU variable FROM {fileVar,}itemId, attr# {SETTING settingVar} {LOCKED statement(s)} [THEN statement(s) | ELSE statement(s)]

Syntax Elements

variable The name of a variable to which the value of the attribute is assigned.

fileVar The name of a variable containing a file reference (assigned via an OPEN statement). If fileVar is not specified, the internal default file variable is used; that is, the file used is that most recently opened without a file variable.

itemId The name of the item from which the data is to be read.

attr# The number of the attribute to be read.

If attr# is 0, READVU checks that the specified item exists and executes the THEN or ELSE clause as appropriate. variable is returned unchanged.

settingVar The name of a variable that is set to a return value. If the data is read successfully, settingVar is set to 0 and the THEN clause is executed. If an error occurs, settingVar is set to the appropriate error code and the ELSE clause is executed. The error codes and corresponding messages are given in File I/O and IPC Error Codes).

If the item is locked, settingVar is returned unchanged.

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.

  • The LOCKED clause (if any) is executed if the item is locked by another process. Use SYSTEM(43) to obtain the number of the port that has locked the item.

    If there is no LOCKED clause, READVU is suspended until the item becomes unlocked.

  • The THEN clause is executed (and the item is locked) if the read is successful.

  • The ELSE clause is executed (and the item is locked) if the item does not exist.

A THEN or an ELSE clause, or both, must be included.

Note

This behaviour can be changed with the NO.IO.ERR compatibility option.

Operation

READVU works the same way as the READV statement, except that it locks the item to be read. This prevents an item from being simultaneously updated by two or more processes.

MultiValue Compatibility

If you call the STATUS function immediately after a READVU statement, if a LOCKED clause was specified and has been executed STATUS returns the port number of the process that has locked the item; otherwise STATUS returns zero.

Example

READVU ATTR FROM B, "RECORD", 6 LOCKED PRINT "UNABLE TO ACCESS"
ELSE STOP

Locks item RECORD in file B. Reads attribute 6 of RECORD to variable ATTR or, if RECORD does not exist, an error message is displayed and the program terminates.

See Also

Item Locks, Statements and Functions by Category.