Friday, December 18, 2009

Input parameters for ENQUEUE/DEQUEUE Functions . - SAP Lock Mechanism -

A closer look at the lock FM parameters which is used commonly by transactional processes.

****************************************************

X_

A further parameter X_ that defines the lock behavior when the initial value is passed exists for every lock field . If the initial value is assigned to and X_, then a generic lock is initialized with respect to . If is assigned the initial value and X_ is defined as X, the lock is set with exactly the initial value of .

Well , this means if you need a parameters initial value to lock , you must set X_ = 'X' for this purpose otherwise it locks entire values.

_SCOPE

1: Locks or lock releases are not passed to the update program. The lock is removed when the transaction is ended.
2: The lock or lock release is passed to the update program. The update program is responsible for removing the lock. The interactive program with which the lock was requested no longer has an influence on the lock behavior. This is the standard setting for the ENQUEUE function module.
3: The lock or lock release is also passed to the update program. The lock must be removed in both the interactive program and in the update program. This is the standard setting for the DEQUEUE function module.

Meaning of the _SCOPE Values
Value
Description
_SCOPE = 1
The lock belongs only to the dialog owner (owner_1), and therefore only exists in the dialog transaction. The DEQUEUE call or the end of the transaction, not COMMIT WORK or ROLLBACK WORK, cancels the lock.
_SCOPE = 2
The lock belongs to the update owner (owner_2) only. Therefore, the update inherits the lock when CALL FUNCTION ‘…‘ IN UPDATE TASK and COMMIT WORK are called. The lock is released when the update transaction is complete. You can release the lock before it is transferred to the update using ROLLBACK WORK. COMMIT WORK has no effect, unless CALL FUNCTION ‘…‘ IN UPDATE TASK has been called.
_SCOPE = 3
The lock belongs to both owners (owner_1 and owner_2). In other words, it combines the behavior of both. This lock is canceled when the last of the two owners has released it.


MODE_

S (read lock) 
E (write lock) 
X (extended write lock)
O (optimistic lock)

Locks Modes
Type of Lock
Lock mode
Description
Shared lock
S (Shared)
Several users (transactions) can access locked data at the same time in display mode. Requests from further shared locks are accepted, even if they are from different users. An exclusive lock set on an object that already has a shared lock will be rejected.
Exclusive lock
E (Exclusive)
An exclusive lock protects the locked object against all types of locks from other transactions. Only the same lock owner can reset the lock (accumulate).
Exclusive but not cumulative lock
X (eXclusive non-cumulative)
Whereas exclusive locks can be requested several times by the same transaction and released one by one, an exclusive, non-cumulative lock can only be requested once by the same transaction. Each further lock request will be rejected.
Optimistic lock
O (Optimistic)
Optimistic locks initially behave like shared locks and can be converted into exclusive locks. See Optimistic Locks.

_COLLECT

Initial Value: The lock request or lock release is sent directly to the lock server.
X: The lock request or lock release is placed in the local lock container. The lock requests and lock releases collected in this lock container can then be sent to the lock server at a later time as a group by calling the function module FLUSH_ENQUEUE.

_WAIT

Initial Value: If a lock attempt fails because there is a competing lock, the exception FOREIGN_LOCK is triggered.
X: If a lock attempt fails because there is a competing lock, the lock attempt is repeated after waiting for a certain time. The exception FOREIGN_LOCK is triggered only if a certain time limit has elapsed since the first lock attempt. The waiting time and the time limit are defined by profile parameters.

_SYNCHRON

If X is passed, the DEQUEUE function waits until the entry has been removed from the lock table. Otherwise it is deleted asynchronously, that is, if the lock table of the system is read directly after the lock is removed, the entry in the lock table may still exist.

Exceptions of the ENQUEUE Function Module

FOREIGN_LOCK: A competing lock already exists. You can find out the name of the user holding the lock by looking at system variable SY-MSGV1.
SYSTEM_FAILURE: This exception is triggered when the lock server reports that a problem occurred while setting the lock. In this case, the lock could not be set.

 Ref : The SAP Lock Concept


 Ref : SAP Documentation LOCK OBJECTS

1 comment:

  1. This comment has been removed by a blog administrator.

    ReplyDelete