Wednesday, June 4, 2008

Setting SAP Locks

Lock function modules set or release SAP locks when called. The function locks access a central lock table in the memory of a special application server work process. Every

ABAP system contains exactly one such table (administered by transaction SM12). An enqueue function module sets an SAP lock by writing a corresponding entry in the lock table. If you cannot set a lock because corresponding lock entries already exist in the lock table, the function module terminates with the FOREIGN_LOCK exception.

The most important entry parameters of an enqueue function module are:

Parameter Meaning
MODE_dbtab Type of lock for the dbtab database table of the lock object. Possible entry values include “S” for a shared lock, “E” for an exclusive lock, “X” for an expanded exclusive lock that can be requested only once unlike a regular exclusive lock within a program, and “O” for an optimistic lock which behaves like a shared lock at first, but can be converted to an exclusive lock.
key_fields For all key fields of the lock object, you can specify values that define the rows to be locked. If you have not specified a value for a key field, all corresponding rows are locked.
_SCOPE Definition of the lock duration with respect to an SAP LUW. Possible entry values include “1″ for handling the lock in the same program, “2″ for transferring the lock to the update, and “3″ for handling the lock in the program and in the update.

Note

You can check an SAP lock by trying to set a corresponding lock and handling the FOREIGN_LOCK exception in the process.

No comments: