MATREADU Statement

The MATREADU statement performs a MATREAD, simultaneously setting an item lock.

Format

MATREADU array FROM [filevar,] item-ID [SETTING var]

[LOCKED statements

END] THEN/ELSE statements

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 MATREADU statement is identical to that of the MATREAD statement, except that a lock is placed on the file item to be read. See MATREAD Statement for more information on the syntax for MATREADU.

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 may 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 MATREADU 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 MATREADU statement without waiting for the item to be released. Note that if the LOCKED clause is used, the array variable array is not assigned.

If the file item does not exist, the item lock is still set, and the ELSE clause is executed. Thus the MATREADU statement may be used to reserve an item for use by the program even if it did not previously exist.

The MATREADU statement performs the same function as using the READU statement to read a dynamic array and then using the MATPARSE statement to assign a dimensioned array to the same elements.

Example

In this application, the MATREADU statement is used to read a dimensioned array EMP from the file opened as EMPLOYEES. If the item is already locked, a message that the item was not found is printed, and the program stops. If the item is not locked, the program continues. After the array EMP is adapted, a MATWRITE statement is used to write the new array back into the file, releasing the item lock.

MATREADU EMP FROM EMPLOYEES,ID SETTING NUM

LOCKED

   PRINT "ITEM ALREADY LOCKED!"

   STOP

END ELSE

   PRINT "CANNOT FIND ITEM"

   STOP

END   

IF NUM > 50 THEN

   PRINT "WARNING : LAST ENTRY GARBLED."

END

   .

   .

   .

MATWRITE EMP TO EMPLOYEES,ID

See Also

Statement and Function Reference