Try OpenEdge Now
skip to main content
ABL Essentials
Handling Data and Locking Records : Record locking in ABL
 

Record locking in ABL

When you read records from a database table, the AVM applies a level of locking to the record that you can control so that you can prevent conflicts where multiple users of the same data are trying to read or modify the same records at the same time. This locking doesn't apply to temp-tables since they are strictly local to a single ABL session and never shared between sessions.
When you read records using a FIND statement, a FOR EACH block, or the GET statement on a query that isn't being viewed in a browse, by default the AVM reads each record with a SHARE-LOCK. The SHARE-LOCK means that the AVM marks the record in the database to indicate that your session is using it. Another user (and the general term user here and elsewhere means code in any type of OpenEdge session that is accessing data, whether it's through an actual user interface or not) can also read the same record in the same way—that is why this is called a SHARE-LOCK.
You can also specify a keyword on your FIND or FOR EACH statement, or on the OPEN QUERY statement for a query, to read records with a different lock level. If you intend to change a record, you can use the EXCLUSIVE-LOCK keyword. This marks the record as being reserved for your session's exclusive use where any changes are concerned, including deleting the record. If any other user has a SHARE-LOCK on the record, an attempt to read it with an EXCLUSIVE-LOCK fails. Thus, a SHARE-LOCK assures you that while others can read the same record you have read, they cannot change it out from under you.
* Record locking examples
* Making sure you release record locks
* Lock table resources
* Optimistic and pessimistic locking strategies