‎2007 Jun 15 11:21 AM
‎2007 Jun 15 11:24 AM
Hello,
purpose: If multiple user try to access a database object, inconsistency may occer. To avoid that inconsistency and to let multiple user give the accessibility of the database objects the locking mechanism is used.
Steps: first we create a loc object in se11 . Suppose for a table mara. It will create two functional module.:
1. enque_lockobject
1. deque_lockobject
before updating any table first we lock the table by calling enque_lockobject fm and then after updating we release the lock by deque_lockobject.
Lock objects are use in SAP to avoid the inconsistancy at the time of data is being insert/change into database.
SAP Provide three type of Lock objects.
- Read Lock(Shared Locked)
protects read access to an object. The read lock allows other transactions read access but not write access to
the locked area of the table
- Write Lock(exclusive lock)
protects write access to an object. The write lock allows other transactions neither read nor write access to
the locked area of the table.
- Enhanced write lock (exclusive lock without cumulating)
works like a write lock except that the enhanced write lock also protects from further accesses from the
same transaction.
You can create a lock on a object of SAP thorugh transaction SE11 and enter any meaningful name start with EZ Example EZTEST_LOCK.
Use: you can see in almost all transaction when you are open an object in Change mode SAP could not allow to any other user to open the same object in change mode.
Example: in HR when we are enter a personal number in master data maintainance screen SAP can't allow to any other user to use same personal number for changes.
Technicaly:
When you create a lock object System automatically creat two function module.
1. ENQUEUE_<Lockobject name>. to insert the object in a queue.
2. DEQUEUE_<Lockobject name>. To remove the object is being queued through above FM.
Lock objects are use in SAP to avoid the inconsistancy at the time of data is being insert/change into database.
SAP Provide three type of Lock objects.
- Read Lock(Shared Locked)
protects read access to an object. The read lock allows other transactions read access but not write access to
the locked area of the table
- Write Lock(exclusive lock)
protects write access to an object. The write lock allows other transactions neither read nor write access to
the locked area of the table.
- Enhanced write lock (exclusive lock without cumulating)
works like a write lock except that the enhanced write lock also protects from further accesses from the
same transaction.
You can create a lock on a object of SAP thorugh transaction SE11 and enter any meaningful name start with EZ Example EZTEST_LOCK.
Use: you can see in almost all transaction when you are open an object in Change mode SAP could not allow to any other user to open the same object in change mode.
Example: in HR when we are enter a personal number in master data maintainance screen SAP can't allow to any other user to use same personal number for changes.
Technicaly:
When you create a lock object System automatically creat two function module.
1. ENQUEUE_<Lockobject name>. to insert the object in a queue.
2. DEQUEUE_<Lockobject name>. To remove the object is being queued through above FM.
http://help.sap.com/saphelp_nw04/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
GO TO SE11
Select the radio button "Lock object"..
Give the name starts with EZ or EY..
Example: EYTEST
Press Create button..
Give the short description..
Example: Lock object for table ZTABLE..
In the tables tab..Give the table name..
Example: ZTABLE
Save and generate..
Your lock object is now created..You can see the LOCK MODULES..
In the menu ..GOTO -> LOCK MODULES..There you can see the ENQUEUE and DEQUEUE function
Lock objects:
http://www.sap-img.com/abap/type-and-uses-of-lock-objects-in-sap.htm
http://help.sap.com/saphelp_nw04s/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
Match Code Objects:
http://help.sap.com/saphelp_nw2004s/helpdata/en/41/f6b237fec48c67e10000009b38f8cf/content.htm
http://searchsap.techtarget.com/tip/0,289483,sid21_gci553386,00.html
See this link:
http://www.sap-img.com/abap/type-and-uses-of-lock-objects-in-sap.htm
Check these links -
Vasanth
‎2007 Jun 15 11:26 AM
Hi,
Lock Objects are used to synchronize access to the same data by
more than one user. Function modules that can be used in
application programs are generated from the definition of a lock
object in the ABAP Dictionary.
The R/3 System synchronizes simultaneous access of
several users to the same data records with a lock
mechanism. When interactive transactions are programmed,
locks are set and released by calling function modules .
These function modules are automatically generated from the
definition of lock objects in the ABAP Dictionary.
Structure of a Lock Object
The tables in which data records should be locked with a
lock request are defined in a lock object together with their
key fields.
When tables are selected, one table (the primary table) is
first selected. Further tables (secondary tables) can also be
added using foreign key relationships.
Lock Arguments
The lock argument of a table in the lock object consists of the
key fields of the table.
The lock argument fields of a lock object are used as input
parameters in the function modules for setting and removing
locks generated from the lock object definition. When these
function modules are called, the table rows to be locked or
unlocked are specified by defining certain values in these fields.
These values can also be generic. The lock argument fields
therefore define which subset of the table rows should be
locked.
Data Dictionary/ Lock Objects
The simplest case of a lock object consists of exactly one
table and the lock argument of the table is the primary key of
this table. Several tables can also be included in a lock
object. A lock request therefore can lock an entire logical
object, and not only a record of a table. Such a logical object
can be for example a document comprising an entry in a
header table and N entries in a positiontable.
Lock Mode
The lock mode controls whether several users can access
data records at the same time. The lock mode can be
assigned separately for each table in the lock object. When
the lock is set, the corresponding lock entry is stored in the
lock table of the system for each table.
Access by more than one user can be synchronized in the
following ways:
Exclusive lock: The locked data can only be displayed or
edited by a single user. A request for another exclusive lock
or for a
shared lock is rejected.
Shared lock: More than one user can access the locked data
at the same time in display mode. A request for another
shared lock is
accepted, even if it comes from another user. An exclusive lock
is
rejected.
Exclusive but not cumulative: Exclusive locks can be requested
several times from the same transaction and are processed
successively. In contrast, exclusive but not cumulative locks
can be called only once from the same transaction. All other
lock requests are rejected.
1> Select object type Lock object in the initial screen of the ABAP
Dictionary, enter an object name and choose Create.
The name of a lock object should begin with an E (Enqueue).
The maintenance screen for lock objects is displayed.
2> Enter an explanatory short text in the field Short text.
You can then use the short text to find the lock object at a later
time, for example with the R/3 Repository Information System.
3> Enter the name of the primary table of the lock object.
All other tables in the lock object must be linked with the
primary table using foreign keys.
4> Select the lock mode of the primary table in the field below
it.
The lock mode is used as the default value for the
corresponding parameters of the function modules generated
from the lock object.
5> Choose Add if you want to lock records in more than one
table with the lock object.
A list of all the tables linked with the primary table using valid
foreign keys is displayed. Select the appropriate table. The lock
mode of the primary table is copied as lock mode. You can
change this setting as required, for example you can assign the
lock mode separately for each table.
Similarly, you can add a table linked with the secondary table
just added with foreign keys. To do this, place the cursor on
the name of the secondary table and choose Add.
If no lock mode is assigned to a table, no lock is set for the
entries in this table when the generated function modules are
called. You should not assign a lock mode if a secondary table
was only used to define a path between the primary table and
another secondary table with foreign keys.
6> Save your entries.
A dialog box appears in which you have to assign the lock
object a development class.
7> You can define whether the function modules generated from
the lock object should be RFC-enabled on the Attributes tab
page. If you set the Allow RFC flag, the generated function
modules can be called from within another system with Remote
Function Call. If you permit Remote Function Calls for an
existing lock object, you must ensure that the generated
function modules are called from within an ABAP program with
parameters appropriate for the type. You should therefore check
all programs that use the associated function modules before
activating the lock object with the new option.
8> Choose Activate.
ELSE.....
SE11->Enter the Lock Object name(EZ_MAT)->Provide Description/Enter the table name as MARA->Select Exclusive,cumulative->Click on Lock Parameter->here you can see key fields->activate this
got o SE37->
You can find 2 FM's which are assined to this.
DEQUEUE_EZ_MAT Release lock on object EZ_MAT
ENQUEUE_EZ_MAT Request lock for object EZ_MAT
Call this in your program/any where to lock/unlock the material (Example)...
Regards,
Priyanka.
‎2007 Jun 15 11:26 AM
Hi,
please have a look at
http://help.sap.com/saphelp_erp2005vp/helpdata/en/e0/bf39426f79f83ae10000000a1550b0/frameset.htm
Regards
Bernd
‎2007 Jun 15 11:27 AM
Hi,
A lock object is used as the locking mechisum. So for example, the user gos to VA02 to change a sales order, in this program, a lock is set. You can see such locks in transaction SM12. If a lock is set, and another user accesses the same sales order, then they will get a message saying that the sales order is locked. The ENQUEUE function module is used to set the lock, the DEQUEUE function module is to release the lock.
Lock objects are use in SAP to avoid the inconsistancy at the time of data is being insert/change into database.
SAP Provide three type of Lock objects.
- Read Lock(Shared Locked)
protects read access to an object. The read lock allows other transactions read access but not write access to
the locked area of the table
- Write Lock(exclusive lock)
protects write access to an object. The write lock allows other transactions neither read nor write access to
the locked area of the table.
- Enhanced write lock (exclusive lock without cumulating)
works like a write lock except that the enhanced write lock also protects from further accesses from the
same transaction.
You can create a lock on a object of SAP thorugh transaction SE11 and enter any meaningful name start with EZ Example EZTEST_LOCK.
Use: you can see in almost all transaction when you are open an object in Change mode SAP could not allow to any other user to open the same object in change mode.
Example: in HR when we are enter a personal number in master data maintainance screen SAP can't allow to any other user to use same personal number for changes.
Technicaly:
When you create a lock object System automatically creat two function module.
1. ENQUEUE_<Lockobject name>. to insert the object in a queue.
2. DEQUEUE_<Lockobject name>. To remove the object is being queued through above FM.
You have to use these function module in your program.
<b>Reward points</b>
Regards
‎2007 Jun 15 11:35 AM
hi,
<b>use</b>
Lock Object Mechanism is used to enforce the DATA INTEGRITY, that ia two users can't UPDATE the same object at the same time.
with lock object you can lock table fields or whole table.
<b>follow these steps to create lock object.</b>
1) Select object type Lock object in the initial screen of the ABAP Dictionary, enter an object name and choose Create.
The name of a lock object should begin with an E (Enqueue).
2)Enter an explanatory short text in the field Short text.
3)Enter the name of the primary table of the lock object.
All other tables in the lock object must be linked with the primary table using foreign keys
4)Select the lock mode of the primary table in the field below it.
The lock mode is used as the default value for the corresponding parameters of the function modules generated from the lock object.
5)Choose Add if you want to lock records in more than one table with the lock object.
6)Save your entries.
A dialog box appears in which you have to assign the lock object a development class.
7)You can (optionally) exclude lock parameters (see lock objects) from the function module generation on the Lock parameter tab page. This makes sense for example if you always want to lock a parameter generically
8)You can define whether the function modules generated from the lock object should be RFC-enabled on the Attributes tab page.
9) choose ACTIVATE.
When you activate the lock object, the two function modules <b>ENQUEUE_<lockobjectname></b> and <b>DEQUEUE_<lockobjectname></b> are generated from its definition to set and release locks.
You can find information about the activation flow in the activation log, which you can display with Utilities---> Activation log. If errors occurred during activation, the activation log is displayed immediately.
regards,
Ashokreddy.
‎2007 Jun 19 2:12 AM
Hi,
From Tr SE11, we can create loca object.
Execute the Tr SE11. Lock object should start with E.
A lock object is a virtual link of several SAP tables which is used to synchronize simultaneous access by two users to the same set of data ( SAP lock concept).
Locks are requested and released in the programming of online transactions by calling certain function modules which are automatically generated from the definition of the lock objects. These lock objects must be explicitly created in the ABAP Dictionary.
To set locks, you must perform the following steps:
1. You must define a lock object in the ABAP Dictionary. The name of the lock object should begin with E.
2. The function modules for requesting and releasing locks which are created automatically when the lock object is activated must be linked to the programming of the relevant online transactions.
Using the SAP Locking Facility
Definition of an SAP lock
The description of an SAP lock to a table is made via the lock condition and the lock mode.
The lock condition is a logical condition for the lines of the table to be locked. It describes the area of the table which the lock is to protect from competitive access. To avoid the administration of the lock becoming complicated, the lock condition can not be formulated as freely as the WHERE clauses: only fully qualified key fields related by AND may appear in the condition.
Via the lock mode you define which operations on the table are to be protected by the lock. The lock modes available are:
Read lock (shared lock)
protects read access to an object. The read lock allows other transactions read access but not write access to the locked area of the table.
Write lock (exclusive lock)
protects write access to an object. The write lock allows other transactions neither read nor write access to the locked area of the table.
Enhanced write lock (exclusive lock without cumulation)
works like a write lock except that the enhanced write lock also protects from further accesses from the same transaction.
In order to be able to define SAP locks for a table, you must first create a lock object for the table via Development->Dictionary.
If the data for an application object is distributed among several database tables, it is often necessary to be able to lock these tables simultaneously. It is therefore possible to include several tables in a lock object, althought they must be related via appropriate foreign key relationships. The tables involved in a lock object are also known as its base tables.
Requesting an SAP lock
When a lock object obj is activated, two function modules (see CALL FUNCTION) with the names ENQUEUE_obj and DEQUEUE_obj are generated. These lock modules are used to explicitly request or release SAP locks in an ABAP program. The SAP lock concept thus assumes a cooperative behavior by all the programs involved. This means that access from programs that do not call the specified modules are not protected.
The lock conditions and lock modes for the requested locks are defined by the IMPORT parameters of the lock modules.
The lock conditions are defined by the lock parameters of the lock object. If the lock object has only one base table, each primary key field of the table corresponds to exactly one lock parameter. Apart from this, a lock parameter corresponds to a group of primary key fields that are identified by the join conditions. For each lock parameter par, the lock modules have two IMPORT parameters with the names par and X_par. The lock condition is defined by these parameters. If a parameter par is not defined or if it is defined with the initial value, this means that the corresponding key fields should be locked generically. If you really want to lock the key field with the initial value, you must also define the parameter X_par with the value 'X'.
To define the lock modes, the lock modules have an IMPORT parameter MODE_tab for each base table tab, with which the lock mode for this table can be defined. A default value must already be set for this parameter in the definition of the lock object.
You cannot set an SAP lock by finding all the lines of the table which satisfy the lock condition and marking them as locked. Rather, the lock condition and lock mode for a table are entered in a special lock table.
Collision of SAP locks
Before a requested SAP lock is entered in the lock table, a check is made on whether it collides with a lock already entered in the lock table. Two locks on the same table collide if their lock conditions overlap and their lock modes are incompatible.
The overlapping of two lock conditions on one table is a purely logical attribute. It occurs if a row of the table which meets both conditions could exist. It is therefore irrelevant for the overlap whether or not such a row really exists in the table.
The following rules apply for the compatability of locks: An enhanced write lock is incompatible with all other locks, a write lock is incompatible with all locks requested by other transactions, and a read lock is compatible with all other read locks.
If locks are requested with the help of a lock object that has several base tables, all locks requested are regarded as colliding as soon as a collision is recognized for just one of the base tables involved.
Behaviour in a collision
An SAP lock that collides with an existing lock cannot be granted and is therefore not entered in the lock table.
With the help of the IMPORT parameter WAIT, you can determine how the ENQUEUE module should behave if the lock it requests collides with an existing lock. If this parameter has the value ' ', the exception FOREIGNLOCK is triggered. The system field SY-MSGV1 is supplied with the user set by the the colliding lock.
If the parameter has the value 'X', the lock request is repeated at set intervals until either the lock can be granted or an internal system time limit is exceeded. In the second case the exception FOREIGN_LOCK is also triggered.
Duration of an SAP lock
At the end of a transaction, this automatically releases all the SAP locks it holds. Note, however, that if an update routine is called by the transaction, locks can be transferred from the ordering transaction to the update routine. In the same way, these locks are automatically released at the end of the update routine.
Via the IMPORT parameter _SCOPE of the ENQUEUE module, you can determine whether a lock should be transferred to the update routine if one is called.
If _SCOPE has the value '1', the lock remains with the the ordering transaction. If _SCOPE has the value '2', the lock can pass to the update routine. Finally, if the parameter has the value '3', two locks of the same kind will be generated, one of which passes to an update routine when one is called.
By calling the DEQUEUE module, a transaction can explicitly release a lock which it holds. The lock parameter and lock mode must be supplied with the same value as for calling the ENQUEUE module. If the parameter _SCOPE has the value '1', only one lock is released which cannot pass to an update routine. If the parameter has the value '2', only one lock is released which can pass to the update program. Finally, if the parameter has the value '3', both locks can be released. Note however that a transaction can release neither a lock which has already been transferred to the update program, nor a lock which is held by another transaction.
Via the IMPORT parameter _SYNCHRON you can control whether the release of the lock should be synchronous or asynchronous. If this parameter has the value 'X', the module waits until the lock has really been removed from the lock table. If the parameter has the value ' ', a requst for deletion of the lock from the lock table is sent to the application server which manages the lock table, and then the execution of the program is immediately continued.
Monitoring of SAP locks
The transaction SM12 Display and delete locks monitors the SAP locks.
Regards,
Chandra
‎2007 Jun 19 4:16 AM
for there 3 Questions below is the answer ...
<b>How many types of lock objects?
How to create Lock objects?
What is the main use of it in real time?</b>
Lock objects are use in SAP to avoid the inconsistancy at the time of data is being insert/change into database.
SAP Provide three type of Lock objects.
- Read Lock(Shared Locked)
protects read access to an object. The read lock allows other transactions read access but not write access to
the locked area of the table
- Write Lock(exclusive lock)
protects write access to an object. The write lock allows other transactions neither read nor write access to
the locked area of the table.
- Enhanced write lock (exclusive lock without cumulating)
works like a write lock except that the enhanced write lock also protects from further accesses from the
same transaction.
You can create a lock on a object of SAP thorugh transaction SE11 and enter any meaningful name start with EZ Example EZTEST_LOCK.
Use: you can see in almost all transaction when you are open an object in Change mode SAP could not allow to any other user to open the same object in change mode.
Example: in HR when we are enter a personal number in master data maintainance screen SAP can't allow to any other user to use same personal number for changes.
Technicaly:
When you create a lock object System automatically creat two function module.
<b>1. ENQUEUE_<Lockobject name>. to insert the object in a queue.
2. DEQUEUE_<Lockobject name>. To remove the object is being queued through above FM.</b>
You have to use these function module in your program.
Hope this will give a basic idea.
Reward points if it is usefull ....
Girish