07-04-2007 9:53 AM
07-04-2007 9:56 AM
Hi,
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
<b>Reward points</b>
Regards
07-04-2007 9:56 AM
Hi,
ock objects are used to synchronize access to the same data by more than one program.
General information about the lock mechanism.
You can synchronize access by several programs to the same data with a logical lock mechanism. This lock mechanism fulfills two main functions:
A program can tell other programs which data records it is just reading or changing.
A program can prevent itself from reading data that is just being changed by another program.
When accessing data records, the records just being edited by other programs can be identified by the entry in the lock table. Such an entry 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 locks, a lock object 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_ 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.
Thanks,reward If Helpful.
07-04-2007 10:00 AM
SAP Lock Objects
SFLIGHT
SFLIGHT
SFLIGHT
SFLIGHT
Name
Primary table
Secondary tables
Table Field name Lock argument
Table Mode
MANDT
CARRID
CONNID
FLDATE
MANDT
CARRID
CONNID
FLDATE
SFLIGHT
ESFLIGHT
...
ABAP
Diiccttiioonnaarryy
SFLIGHT
. . .
Lock arguments
Lock mode
E Write lock
S Read lock
X Extended write lock
Lock modules are created for lock objects and not tables.
Lock objects are maintained in the dictionary. Customer lock objects must begin
with "EY" or "EZ".
A lock object is a logical object composed of a list of tables that are linked by
foreign key relationships. Lock modules are generated for these objects and
enable common lock entries to be set for all tables contained in the lock object.
This allows combinations of table entries to be locked.
Example: A lock object that contains the tables SFLIGHT and SBOOK enables a
flight with its bookings to be locked.
The list of tables for a lock object consists of a primary table. Further table
entries are referred to as secondary tables. Only tables with foreign key
relationships to the primary table can be used as secondary tables.
With lock objects, you can assign different names for the parameters that describe
the fields of the lock arguments for the lock modules. The names of the table fields
(key fields of the tables) are proposed by the system.
You can specify the lock mode (a write lock 'E' or 'X' or a read lock 'S') for each
table. These function as default values for the lock modules.
Generating Lock Modules
DEQUEUE_ESFLIGHT
Activate
Lock oobbjjeecctt
ESFLIGHT
Function module
ENQUEUE_ESFLIGHT
Function module
Set lock Release lock
Generraatteedd
automattiiccaallllyy
DEQUEUE_After you have assigned tables and default lock modes, lock objects must be
generated.
When you activate a lock object, the system generates an ENQUEUE and a
DEQUEUE function module.
??These have the names ENQUEUE_<object_name> and DEQUEUE_<object_name>
respectively.
Overview: Using Locks: Time Sequence
UUssiinngg lloocckkss:: ttiimmee s seeqquueennccee
LLoocckk oobbjjeeccttss
SSeettttiinngg aanndd rreelleeaassiinngg lloocckkss
OOvveerrvviieeww
Reading Current Data
User 1
lock
read change User 2
unlock
read change
SAP LUW 1
SAP LUW 2
unlock
lock
Lock 1 Lock 2
Lock durations
1
2 3
4
1
2 3
4
Time
If you want to ensure that you are reading current data in your program (with the
intention of changing and returning this to the database), you should use the
following procedure in your program for lock requests and database accesses:
1. Lock the data that you want to edit.
2. Read the current data from the database.
3. Process (change) the data in your program and write this to the database.
4. Release the locks that you set at the beginning.
This procedure ensures that your changes run fully with lock protection and that
you only read data, which has been changed consistently by other programs (with
the restriction that these are also using the SAP lock concept and following the
procedure described).
Risk of Inconsistent Data as a Result of Using Locks
Incorrectly
User 1
lock
read change User 2
unlock
read change
unlock
SAP LUW 1
SAP LUW 2
lock
Lock 1 Lock 2
Lock durations
1
2 3
4
Time
If you change the order of the four steps to Read -> Lock -> Change -> Unlock,
you run the risk that the data read by your program will not be up to date. Your
program can read data before another user's program writes changes to the
database. This means that a user of your program will make decisions for entries
that are not based on up-to-date data from the database. For this reason, you
should always follow the recommended procedure.
Using a Lock Container
ABAP
program
Lock module 1
Lock table
Lock module 2
Lock module n
FLUSH_ENQUEUE
Time
Container
Lock 1
Lock 2
...
Lock n
Orders:
Collect locks
Requesting a lock from a program is a communication step with lock
administration. The communication step requires a certain time interval. If your
program sets locks for several objects, this interval occurs more than once.
By using so-called local lock containers , you can reduce these communication
intervals with lock administration. To do so, collect the required lock requests of
your program and send them together to lock administration.
The locks (delayed execution) can be collected when the lock modules are called.
For this purpose, qualify the IMPORT parameter_collect with 'X'. The data
transferred via the lock module interface is then registered in a list (lock
container) as a lock request that needs to be executed.
The lock container can be terminated using the FLUSH_ENQUEUE function module
and sent to lock administration.
??When the lock orders of a lock container can be executed, the lock container is
deleted.
If one of the locks in a container cannot be set, the function module
FLUSH_ENQUEUE triggers the exception FOREIGN_LOCK. In this case, none of the
registered lock requests is executed. The registered locks remain in the lock
container.
You can delete the contents of an existing lock container with the function module
RESET_ENQUEUE.
The specified function modules have release status internally-released.