11-06-2007 5:59 AM
hi all ,
can anybody tell me the concept of lock object with example,how we create lock object and how we use it in program???
thanks in advance .
saurabh srivastava .
11-06-2007 6:01 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.
You have to use these function module in your program.
check this link for example.
http://help.sap.com/saphelp_nw04s/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
tables:vbak.
call function 'ENQUEUE_EZLOCK3'
exporting
mode_vbak = 'E'
mandt = sy-mandt
vbeln = vbak-vbeln
X_VBELN = ' '
_SCOPE = '2'
_WAIT = ' '
_COLLECT = ' '
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
Normally ABAPers will create the Lock objects, because we know when to lock and how to lock and where to lock the Object then after completing our updations we unlock the Objects in the Tables
http://help.sap.com/saphelp_nw04s/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
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.
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 -
Regards
Anji
11-06-2007 6:17 AM
Hi
Go to SE11, click the radibutton for lock object, then do F4 on the field. Click the "All Selections" icon, in the "Basis Table" field, put the table that you want the lock object for. click green check.
The SAP System synchronizes simultaneous access of several users to the same data records with a <a href="http://help.sap.com/saphelp_nw04s/helpdata/en/cf/21eed9446011d189700000e8322d00/content.htm">Lock mechanisam</a>. When interactive transactions are programmed, locks are set and released by calling function modules (see <a href="http://help.sap.com/saphelp_nw04s/helpdata/en/cf/21eebf446011d189700000e8322d00/content.htm">Function Modules for Lock Requests</a>). These function modules are automatically generated from the definition of lock objects in the ABAP Dictionary.
Check this linnk
http://help.sap.com/saphelp_nw04s/helpdata/en/af/22ab01dd0b11d1952000a0c929b3c3/content.htm
Try like this
CALL FUNCTION 'ENQUEUE_EZXXX'
EXPORTING
MODE_ZSD_XXXX = 'E'
MANDT = SY-MANDT
LOAD_NO = 'XXX'
DN_NO = 'XXX'
ITEM_DN = 'XXX'.
or try like this
DATA:
i_varkey TYPE rstable-varkey,
i_tabname TYPE rstable-tabname VALUE 'ZGLACC'.
CONCATENATE sy-mandt i_final-vbeln
INTO i_varkey.
CALL FUNCTION 'ENQUEUE_E_TABLEE'
EXPORTING
tabname = i_tabname
varkey = i_varkey.
Regards
Pavan
11-06-2007 6:22 AM
Hi
Lock object concept
Lock modes
Creating a lock object (example)
Lock object sample code
SAP data dictionary provides you with a locking mechanism to synchronize simultaneous data access by different users.
Lock objects are created in SE11.
Customer lock objects must begin with EY or EZ .
Three possible lock modes exist for lock objects.
<b>Lock Mode</b>
Lock mode E: This sets a lock for changing data for single user. This lock can be accumulated.
Lock mode X: This mode is used like mode E for changing data. The only technical difference from mode E is that the respective lock does not allow accumulation.
Lock mode S: This mode ensures that data displayed in your program cannot be changed by other users during the entire display time. Here you do not want to change the data yourself (allows read only access for data).
<b>Creating Lock object</b>
Enter lock object name beginning with EY or EZ
and hit create.
Enter table names containing data records that should be locked and the lock mode.
The primary keys of the specified tables are automatically selected as lock parameters.
To set a lock in the application program
call a function module ENQUEUE_<LOCK_OBJECT>.
For our example, it would be ENQUEUE_EZMARA.
To release the lock in the application program
call a function module DEQUEUE_<LOCK_OBJECT>.
For our example, it would be DEQUEUE_EZMARA.
Refer the code executed by user (say abap1) for
matnr = 000000000000000012.
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.
Checking existing SAP locks
In the transaction SM12 you can see all current SAP locks, they can be selected using object or user name. If you want to get that list in your ABAP, the function ENQUEUE_READ will return you a list of object locks for specific objects (that can be specified with a pattern). The function can be useful if you want to process some object without locking it, for example, with a BAPI or BDC, and you want to check whether you may do this at the moment. If the object is currently locked by another user, you can read the lock and decide what to do: wait, or just report an error.
Enqueue Trace Records
The following list columns are particularly relevant to enqueue trace records:
In the Basic List
Duration Runtime for the lock operation in the form milliseconds.microseconds.
Object The name of the lock object.
Oper The lock operation. For further information, refer to Lock Objects.
RC Return code.
If the value in this column is zero, the enqueue operation was successful. If it is "1", the operation was unsuccessful because the lock object or parts of it were already locked.
Rec Number of granules in the lock object.
Statement This column lists the granules for the lock request. If there is more than one, they are separated by the "|" character. The lock mode, lock table, and lock argument of each granule are listed.
See also: Lock objects.
In the Extended List
hh:mm:ss.ms The time at which the lock operation was performed, in the form hours : minutes : seconds. milliseconds.
Program Name of the ABAP program that requested the lock operation.
Curs not used.
For a more detailed analysis, use the Detailed Display of Enqueue Trace Records.
/community [original link is broken]
<b>Reward if usefull</b>