Lock Mechanism
The access of several users to the same data can be synchronized with a logical lock mechanism. This lock mechanism fulfills two main functions:
The data records of a table to be locked are defined by a logical condition. When a lock is set, this logical condition is entered in a lock table. This entry is retained until it is removed by the transaction or the transaction is finished. All of the locks set by this transaction are thus removed at the end of the transaction.
When accessing data records, the records just being edited by other transactions can be identified by the entry in the lock table.
Such a logical condition for the lock must define a number of fully specified key fields, that is either a value is passed for the key field or this field is locked generically.
To set the locks, a lock object (see
Lock Objects) must be defined in the ABAP Dictionary. When this lock object is activated, two function modules (see Function Modules for Lock Requests) are generated with the names ENQUEUE_<object_name> and DEQUEUE_<object_name>.The ENQUEUE function module is used for setting a lock, and the DEQUEUE function module for removing an existing lock. These function modules each contain an argument for each lock field of a table included in the lock object. A value can thus be copied for each field of the lock argument. The records of the table whose key fields correspond with the copied values are then locked.
If data records are to be locked, the function module ENQUEUE_<object_name> is called. When it is called, the values of the key fields which specify the records to be locked are copied to it. A generic lock is made for the data records without values. The function module writes the corresponding lock entry. If another transaction now also requests a lock, it is accepted or rejected depending on the
Lock Mode.This lock procedure requires that all programs involved cooperate. Inconsistencies can occur if a program reads or changes data without having previously locked it. When a lock is set, the data records are only protected against changes by another program if this program also follows the lock conventions by requesting a lock before accessing the data.
Instead of writing lock requests or lock releases directly in the lock table, it is also possible to collect them first in a local lock container. The collected locks can be sent as a group at a later time.
A parameter of the relevant function module controls whether a lock request or lock release is sent directly.
See also:
Local Lock Container