FILEUNLOCK

FILEUNLOCK

Top  Previous  Next

 

The FILEUNLOCK statement releases a file lock previously obtained using the FILELOCK statement.

 

 

Format

 

FILEUNLOCK file.var {ON ERROR statement(s)}

{THEN statement(s)}

{ELSE statement(s)}

where

 

file.varis the file variable associated with the file.

 

statement(s)are statements to be executed depending on the outcome of the operation.

 

 

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.

 

The THEN and ELSE clauses are both optional and neither need be present. The THEN clause will be executed if the file lock is successfully released. The ELSE clause will be executed if the lock cannot be released. Currently, this will only occur if the lock is not owned by the process executing the FILEUNLOCK.

 

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:

Locking, FILELOCK