The READU statement performs a READ, simultaneously setting a lock on the item to be read.
Format
READU var FROM [filevar,] item-ID [LOCKED statements] [THEN statements1] [ELSE statements2] END |
Parameter(s)
LOCKED statements |
Executes statements if the item was already locked by another process. The statements of the LOCKED clause follow the syntax of statements in THEN or ELSE clauses. |
Description
The behavior of the READU statement is identical to that of the READ statement, except that a lock is placed on the file item to be read. See READ Statement for more information on the syntax and behavior of READU.
When a file item is locked, it cannot be read by another READU, READVU, or MATREADU statement until the lock is removed. The lock is removed by exiting the program, updating the file with the WRITE, WRITEV, MATWRITE, or DELETE statements, or releasing the lock with the RELEASE statement or RESET-ITEM-LOCKS command. The file can be updated without removing the item lock with the WRITEU, WRITEVU, or MATWRITEU statements. There is no limit to the number of items that can be locked simultaneously at a given time.
If the READU statement is executed on an item already locked by another user, the program hangs until the lock is released, unless the LOCKED clause is specified. The LOCKED clause allows the user to exit from the READU statement without waiting for the item to be released. If the LOCKED clause is used, the dynamic array variable var is not assigned.
If the file item does not exist, the item lock is still set and the ELSE clause is executed. Thus the READU statement may be used to reserve an item for use by the program even if it did not previously exist.
Example
In this application, the file CUSTOMERS contains customer billing information. The program tries to read the a customer’s record. If the file item is not locked, the program goes on to update addresses; otherwise the user is asked to try later.
OPEN "CUSTOMERS" TO CUSTFILE ELSE ABORT 201 , "CUSTOMERS" END READU RECORD FROM CUSTFILE , NAME LOCKED PRINT "ITEM IS LOCKED! TRY AGAIN LATER." END |
See Also