Application Development 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: 

how to delete sm12 lock programmatically.

0 Kudos

Hello,

How to remove lock entry in sm12 transaction programmatically.

Scenario : I

call function 'enqueue_table_sample'. " creating lock in sm12.

if sy-subrc = 0. "no other user locked table_sample

call function 'dequeue_table_sample'. " is removing lock in sm12.

endif.

Scenario : II

call function 'enqueue_table_sample'. " creating lock in sm12.

if sy-subrc = 1. "some user locked table_sample or myself locked table_sample in another session

call function 'dequeue_table_sample'. " is not removing lock in sm12.

endif.

I can able to remove sm12 lock in Scenario I, but i want to remove sm12 lock in case II scenario.

With Regards,

Sunny.

8 REPLIES 8

FredericGirod
Active Contributor

Trace the code of suppress lock entry manually in transaction SM12

But be aware there will be a high risk to create inconsistency in your system and you could loose the SAP support if this code is identified by the support

VXLozano
Active Contributor

You are fighting the very main reason of the locking system's existence. If another user or session has a lock, you must assume they is working with the data you want to change. To break-in by deleting that lock will lead to inconsistencies (as Frederic pointed).

If your necessity comes from a dead session's lock, you'd be working on a solution for that dead session, not for a chance to kill a living one.

0 Kudos

I agree 100% with you both, but my table is getting updated for every 5 sec , if one job stuck, thousands are in waiting and this causes great disorder and confusion.

any way how to find what is blocking?? so that i can find reason for the block.

Many Thanks,

Sunny Ch.

matt
Active Contributor

If your table is getting updated every five seconds, automatically deleting locks is almost certain to lead to database corruption.

What are the key fields of your structure, what is the definition of your lock object, and what is the exact ABAP code you're using to lock/unlock?

Without this information, I can't help much further.

VXLozano
Active Contributor

A table what's been updated every 5 seconds looks like a design error. Real time data? OK, maybe some rows of your table must be updated, but the whole one?

As Matt pointed: are you locking it by key or the whole thing? If your job is locking the whole table, you should change that.

If you really need to lock the whole thing, then your only safe option is to check if there's a lock, and exit the program if there is. Your next job (five seconds later o.O) will take care of the new data.

Because if you are updating your table every 5s, you should NOT keep any updating program waiting, because when the waiting program will update your data, it will put there outdated information.

Sandra_Rossi
Active Contributor
0 Kudos

It was already asked and answered multiple times in the forum e.g. in 2008 by Uwe S.

0 Kudos

Thank you all for your efforts, I will agree with you people that deleting locks will make data inconsistency.

I am not locking whole table BTW, i am locking based on 4 parameters. table is related to production so, many 3rd party tools in shop floor will try to update same table frequently.

Coming back to my issue... i withdraw implementing code to delete locks in sm12, but could you help me to trace which record is making table lock for some extra time. How to analyze this??

Thank You.

JoeyLi
Product and Topic Expert
Product and Topic Expert
0 Kudos

Monitor dev trace when you found the locker.