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

Table Lock

Former Member
0 Likes
1,131

Hi Experts,

Some times we lock some DB tables?..Y we lock them?

How to lock and unlock a table?

Regards,

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,055

if one user updating the data base table another user can't use it at the time of updation at same time.

*-------------lock Table
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
tabname = table_name
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
 
 
 
*-------------Unlock Table
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
tabname = table_name

also check ....

7 REPLIES 7
Read only

Former Member
0 Likes
1,056

if one user updating the data base table another user can't use it at the time of updation at same time.

*-------------lock Table
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
tabname = table_name
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
 
 
 
*-------------Unlock Table
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
tabname = table_name

also check ....

Read only

Former Member
0 Likes
1,055

Yes, Lock objects are used to set locks on database tables. Usually the lock is applied using the key of the database table. This insures that only one user can change a specific record in a database table at one time. You create the lock object in SE11, once defined, there will be two function modules created, an ENQUEUE function module and a DEQUEUE function module. The naming convention is ENQUEUE_E<name of lock object>, DEQUEUE is the same, but replace ENQUEUE with DEQUEUE.

Why to lock the databse tables:

You can consider example of bank transactions. Suppose I am transfering some amount from one account to other. Once i click on transfer button, immediately the amount will be debited from my account but at the next second it may or may be credited to other account. In betwwen if I try to do other transcations with the same amount, then that may not be correct one bcoz the money is not there in my account.

Other example, Suppose a travel agent want to book a flight. The customer wants to fly to a particular city with a certain airline on a certain day. The booking must only be possible if there are still free places on the flight. To avoid the possibility of overbooking, the database entry corresponding to the flight must be locked against access from other transactions. This ensures that one user can find out the number of free places, make the booking, and change the number of free places without the data being changed in the meantime by another transaction.

http://help.sap.com/saphelp_nw04s/helpdata/en/c2/2d7037ecc92a7ee10000009b38f8cf/content.htm

http://help.sap.com/saphelp_nw04s/helpdata/en/41/7af4c5a79e11d1950f0000e82de14a/content.htm

Best Regards,

Vibha

*Please mark all the helpful answers

Read only

Former Member
0 Likes
1,055

Hi Ravi,

We Lock Database table to avoid Duplicate Entries. For Example if you are creating a Purchase Order from an Legacy say Excel file and at the same time there could be some one who would create an PO internaly. If the last PO is 10 an dyou Excel Contains from 11 to 20 at this time if a person creates PO internaly then it would be 11 so you cannot create from your Program so we Lock the DataBase.

Locking and Unloacking can be done using Enque and Deque Function Modules.

Hope this would have cleared you.

Thanks,

Prashanth

Read only

dani_mn
Active Contributor
0 Likes
1,055

HI,

create the lock objects from the transaction 'SE11' and then use them in the program.

once you created two function module will be generated one for locking that is 'ENQUEUE_tabelname' and for unlocking 'DEQUEUE_tablename'.

you can call these FMs to lock and unlock the records.

REgards,

Read only

anversha_s
Active Contributor
0 Likes
1,055

Hi,

Lock objects are used to lock the database table while making the modifications on the database table.

you can create your own lock objects using SE11.

if you create lock objects on any table system will create two function modules.

1.ENQUEUE....

2.DEQUEUE.....

first one is used to lock the table

second one used to removing lock on the table.

*-------------lock Table
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
tabname = table_name
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
 
 
 
*-------------Unlock Table
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
tabname = table_name

check this link :

http://help.sap.com/saphelp_40b/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm

rgds

Anver

pls amrk all hlpful answers

Read only

Former Member
0 Likes
1,055

Hi Ravi,

When we are changing data base table then at that time if we have not put lock then others can also change it at a same time.

Imagine you need to change the name of emp 1000 from PA0001 table. Now without locking table if you are making change of name from Vikas to Vishal.

Now at the same time i am making change in name and chaning it to Vikas to Amit.

Imaging what will happen ????

To avoid such scenario locking is required in table.

To lock database table we need to create LOCK object.

SE11 there is option to create a lock object.

This will create 2 function module

1. ENQUEUE_*

2. DEQUEUE_*

in program when you are chaning DB then use FM ENQUEUE_*

this will lock DB table and if any one else is chaging DB at the same time then he ll get message that DB is locked.

Once updatiuon is done via DEQUEUE_* FM unlock it.

*HOPE this will help you to understand lock/unlock concept

Read only

Former Member
0 Likes
1,055

Hi Ravi,

I will give u one live example. When u r trying to Draw cash from you bank account and one of u'r friend is also having a duplicat card of u'r account. You both cannot Draw the Cash at a time. Means when one is With Drawing the cash u'r account is locked after he Took the cash u can With Draw. Same way When u r Doing some thing on the Data base table and if any other person is trying to Access the data the data obtained will give errors as u r modifying them. In oder to avoid this We lock the DBTables.

bye

Murthy.