What Is Locking ?
When two users simultaneously attempt to access the same data record, this is synchronised by a lock mechanism.
Step 2 - ABAP code to lock table entries
Add the following code in-order to create the table lock. This function module must be called
before any update takes place. If a lock has already been taken out it will display the appropriate message.
before any update takes place. If a lock has already been taken out it will display the appropriate message.
When two users simultaneously attempt to access the same data record, this is synchronised by a lock mechanism.
When dialog transactions are programmed, locks
are set and released by calling certain function modules. These function modules
are generated automatically from the definition of so-called lock objects in
the ABAP/4 Dictionary.
To synchronize the access to a table by setting
and removing locks, a Lock object has to be defined in the ABAP/4 Dictionary.
Activating the lock object automatically creates function modules for setting
and removing locks. These function modules must be included when programming
interactive transactions.
Lock
Mechanism :
To set locks, a lock object must be defined in
the ABAP/4 Dictionary. In this lock object, those tables in which data records
are to be locked by calling a lock are determined. All tables included in a
lock object must be connected to each other via foreign keys. The key fields of
the tables in a lock object form the Lock arguments for the tables. The lock
arguments are the basis for formulating the logical condition for identifying
the records to be locked.
SAP provides you with the
ability to restrict access to data while the table is being updated. This is
fairly simple to implement via the use of a lock object (Created in SE11).
Step 2 - ABAP code to lock table entries
Add the following code in-order to create the table lock. This function module must be called
before any update takes place. If a lock has already been taken out it will display the appropriate message.
before any update takes place. If a lock has already been taken out it will display the appropriate message.
CALL
FUNCTION 'ENQUEUE_EZ_ZTABLENAME'
EXPORTING
mode_ZTABLENAME = 'E' "E =
Write Lock, S = Read Lock, X = Exclusive not cumulative
mandt = sy-mandt
KEYFIELD1 = "Value
KEYFIELD2 = "Value
KEYFIELD3 = "Value
...
*
X_KEYFIELD1 = ' '
*
X_KEYFIELD2 = ' '
*
X_KEYFIELD3 = ' '
...
*
_SCOPE = '2'
*
_WAIT = ' '
*
_COLLECT = ' '
* If
exceptions are not used, message is displayed within FM
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3.
IF
sy-subrc <> 0.
*
Retrieve message displayed within Function Module
message id sy-msgid
type 'I'
number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
EXIT.
ENDIF.
Step 3
- ABAP code to Remove table lock(s)
The following code will remove the lock for the specific table entries.
The following code will remove the lock for the specific table entries.
CALL FUNCTION 'DEQUEUE_EZ_ZTABLENAME'
EXPORTING
MODE_ZTABLENAME = 'E'
MANDT = SY-MANDT
mandt = sy-mandt
KEYFIELD1 = "Value
KEYFIELD2 = "Value
KEYFIELD3 = "Value
...
* X_KEYFIELD1 = ' '
*
X_KEYFIELD2 = ' '
*
X_KEYFIELD3 = ' '
...
*
_SCOPE = '3'
*
_SYNCHRON = ' '
*
_COLLECT = ' '
No comments:
Post a Comment