Type and Uses of Lock Objects in SAP

How many types of lock objects?
How to create Lock objects?
What is the main use of it in real time?

Lock objects are use in SAP to avoid the inconsistency 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 through 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 maintenance screen SAP can't allow to any other user to use same personal number for changes.

Technically:

When you create a lock object System automatically create 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.

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.

For example:

The user goes 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.

ABAP Tips

See Also

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Main Index
SAP ERP Modules, Basis, ABAP and Other IMG Stuff

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.