Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Lock Objects

Former Member
0 Likes
1,114

Hi ,

I knew a little bit about lock objects . Suppose I have created a Z table. For this table How can I create a Lock Objects ? . In which situtaion we create a lock objects ? Can I have any real time example ? because sap itself maintain luw.

so,What is the use of lock objects ?

Bye,

Muttu.

6 REPLIES 6
Read only

Former Member
0 Likes
832

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

Regards,

Priyanka.

Read only

0 Likes
832

Hi Priyanak,

Thank you very much. How can and where can we use these function moudules in the program ? And what type of code we write in the FM ?

Can you give any example like you have given previously .

By,

Muttu,

Read only

0 Likes
832

Hi Muttu,

As you are clear with the part of creating the lock object, the rest involves locking the desired table through this lock object. This is achieved by creating a report in se38. Call the function Enqueue_<lockobject>, give your table name, if you want to lock the entire table give the names of key fields of the table in the function module and give their values as blank. If you want to lock a particular record of the table, give the values of that record.

After coming out of the function, check with the following stmnt:

if sy-subrc = 0

<your table is locked and you can work on it>

else

<using the wait statement , wait for few seconds and again check whether the table is locked or not>

endif.

After you have finished working on the table, release your lock by using the FM Dequeue_<lockobject>.

Hope it helps.

Read only

amit_khare
Active Contributor
0 Likes
832

Check these links -

Regards,

Amit

Read only

Former Member
0 Likes
832

lock object are used to lock the table you are updating.

Once you ahev locked the table no1else can update or change the entries in the table your program is working ..

Hence to make sure no data chane happens, its is always recommended to lock the tables before updating.

U can creat a lock for table in se11, give the name EZ(table name).

in program u can lock the table with

call function ENQUEUE_(lock object craete above)

and unlock the table after updating using

call function DENQUEUE_(lock object craete above)

Read only

Former Member
0 Likes
832

Hi,

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 (see Function Modules for Lock Requests). These function modules are automatically generated from the definition of lock objects in the ABAP Dictionary.

chk out these links, u will find lot of info:

http://help.sap.com/saphelp_nw04s/helpdata/en/7b/f9813712f7434be10000009b38f8cf/content.htm

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

regards,

keerthi