READVL, READVU |
![]() ![]() ![]() |
The READVL statement reads a specific field from a record of a previously opened file, setting a read lock. The READVU statement is similar but sets an update lock.
Format
READVL var FROM file.var, record.id, field.expr {ON ERROR statement(s)} {LOCKED statement(s)} {THEN statement(s)} {ELSE statement(s)}
where
At least one of the THEN and ELSE clauses must be present.
The specified record is read and the field identified by field.expr is extracted into the named variable. If the field does not exist, var is set to a null string.
READVL sets a read lock is set on the record. READVU sets an update lock on the record. See Locks for full details of QM's locking mechanism.
A field.expr value of zero may be used to determine if the record exists. var will be set to a null string.
The LOCKED clause is executed if the file or record is locked by another process (exclusively in the case of READVL). The STATUS() function will return the user id of a process holding a lock on this file or record. If the LOCKED clause is omitted and the file or record is locked, the program will wait for the lock to be released.
The THEN clause is executed if the record is read successfully regardless of whether the specified field is present.
The ELSE clause is executed if the operation fails because no record with the given id is present on the file. If the PICK.READ mode of the $MODE directive is used var will be left unchanged, otherwise it will be set to a null string. The STATUS() function will indicate the cause of the error.
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
READVU ITEM FROM STOCK, ITEM.ID, 3 THEN ...processing statements... WRITEV ITEM TO STOCK, ITEM.ID, 3 END ELSE DISPLAY "Record " : ITEM.ID : " not found" RELEASE STOCK, ITEM.ID END
This program fragment reads field 3 of a record from the file previously opened to file variable STOCK into variable ITEM, setting an update lock. If successful, the processing statements are executed and the modified value is written back to the file. If the record is not found, a message is displayed and the record is unlocked. |