FILEUNLOCK |
![]() ![]() ![]() |
The FILEUNLOCK statement releases a file lock previously obtained using the FILELOCK statement.
Format
FILEUNLOCK file.var {ON ERROR statement(s)}
where
The FILEUNLOCK statement releases a file lock, making the file available to other users. Read and update locks on records from the file are not affected.
The ON ERROR clause is executed in the event of a fatal error. The STATUS() function will return an error code giving the cause of the error.
Where the ON ERROR clause is not taken, the STATUS() function returns 0 if the file was previously locked by this user, ER$LCK if the lock is held by another user or ER$NLK if no user holds the lock.
Example
FILELOCK STOCK SELECT STOCK TOTAL = 0 LOOP READNEXT ID ELSE EXIT READ REC FROM STOCK, ID ELSE ABORT "Cannot read " : ID TOTAL += REC<QTY> REPEAT FILEUNLOCK STOCK
This program fragment obtains a file lock on the file open as STOCK and then reads all records from the file, forming a total of the values in the QTY field. The lock prevents other users obtaining update locks when they might be updating this field in some record. The lock ensures that the total value represents a true picture of the file when the file lock was obtained. The lock is released on leaving the main processing loop.
See also: |