Record.LockTable([Boolean] [, Boolean]) Method

Version: Available or changed with runtime version 1.0.

Starts locking on a table to protect it from write transactions that conflict with each other.

Syntax

 Record.LockTable([Wait: Boolean] [, VersionCheck: Boolean])

Parameters

Record
 Type: Record
An instance of the Record data type.

[Optional] Wait
 Type: Boolean
Specifies what to do if the table is already locked. If this parameter is true and if another application has already locked the table, the system will wait until the table is unlocked. If this parameter is false and if another application has already locked the table, a run-time error occurs.

[Optional] VersionCheck
 Type: Boolean
If this parameter is true, the version of the Record will be checked. If this parameter is false, blank, or not used, the version will not be checked.

Remarks

If the session is not using Read Scale-Out, then LockTable does the following:

  1. Starts a transaction.
  2. Makes sure that all subsequent statements that read data will apply an UPDLOCK on the database.

If the session is using Read Scale-Out, then LockTable does the following:

  1. Makes sure that all subsequent statements that read data use REPEATABLEREAD on the database.

Because all write operations automatically lock the table that is being used, LockTable would appear unnecessary. However, you could have a transaction in which an application wants to inspect data before possibly changing it, with a guarantee that the data being changed has not been modified by other applications since the read operation. The solution is to explicitly lock the table before the read operation. This makes sure that no other application makes changes between the read operation and the possible write operation.

The table lock is released (unlocked) when the transaction is committed.

This method works the same as the RecordRef LockTable Method.

See Also

Record Data Type
Get Started with AL
Developing Extensions
AL Database Methods and Performance on SQL Server