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: 

Lock for transaction code.

Former Member
0 Kudos

i have created screen executed with Transaction code,having few Controls inside screen.

As soon as I enter action(click push button) inside the screen.(ie Transaction code), this transaction screen should be locked, and other users should not use the transaction simultaneously in the present System.

I have to do it inside the ABAP coding. could you please help me how to do it.

Regards

Chandra

9 REPLIES 9

Former Member
0 Kudos

You can lock tables for changes or a single line in table.

If your aim is to prevent any changes in a table by other users when one user is already maintaining it than you should use lock object.

For creating a lock object goto transaction code se11.

in lock object field write the [E + name of your table] and push create.

In tables tab write the name of your table in the name field and choose a lock mode.

after creating lock object your

lock FM will be ENQUEUE_lockobjectname

unlock FM will be DEQUEUE_lockobjectname

-


If it helps please give points.

0 Kudos

and in continuation to Fuat Ulugay's answer....

If any user has opened the custom transaction, make sure you call the ENQUEUE Function Module. And after calling the FM, check for the sy-subrc, in case that sy-subrc fails, someone has already opened the custom transaction. If it is successful, no one has started the transaction.

Regards,

Subramanian V.

Former Member
0 Kudos

You can use function module ENQUEUE_E_TABLE to lock anything. Make up a key for your transaction. Maybe the transaction code will work, just make sure the key you make up can never be a real table name. For example, if your transaction name is ZTRAN, then use key ZTRAN$ as the lock for your transaction. With the $ in the name, it can never be a real table name. Then invoke ENQUEUE_E_TABLE passing TABNAME = 'ZTRAN$'.

The reason you can make up a key is that we are not really locking anything. We are creating an entry in a lock list that SAP maintains in a central server. As long as all users of the lock use it correctly, for example, all users use ZTRAN$ as the lock of your transaction, then this will should meet your needs.

Likewise, you use FM DEQUEUE_E_TABLE to release the lock or FM DEQUEUE_ALL to release all or your locks.

0 Kudos

It may not be the best way, but maybe you could use the functionality behind transaction code SM01. Here you can lock/unlock the transaction code. If you look at the program, all it is really doing is updating table TSTC field CINFO. CINFO = 80 when unlocked, CINFO = A0 when locked. You could just update the field accordingly and then call this function module right after.

  • For locking

CALL FUNCTION 'RSAU_WRITE_SM01_LOG'

EXPORTING

TCODE = TSTC-TCODE

LOCK = 'X'

  • For unlocking

CALL FUNCTION 'RSAU_WRITE_SM01_LOG'

EXPORTING

TCODE = TSTC-TCODE

UNLOCK = 'X'

This isn't the way I would do it since it is a direct database update, but it is another option.

Regards,

Rich Heilman

Former Member
0 Kudos

TO use FM ENQUEUE_E_TABLE

I tried Creating Key ZTRAN$, using SE11 in LOCK OBJECT entry.

but it says "non alphanumeric char is not allowed."

I cant create key for my transaction.

Could you please tell me the step to create key.and sample

code to write inside the FM?

Would be great help.

Regards

0 Kudos

No SE11 necessary. Just invoke function module ENQUEUE_E_TABLE and pass ZTRAN$ to parameter TABNAME. The function module does not care what TABNAME you pass, the important thing is that another user of your program who also tries to lock ZTRAN$ will be denied. You can do a where used on the FM to find examples, but you will likely find examples that use a real table name. That is also fine, but as I mentioned, the FM does not care whether it is a real table or not. The locking process is matching up names so having a unique key is important.

Let us know how it goes!

Former Member
0 Kudos

hai

I used below FM with parameter 'ZTRAN$' for TABNAME as u said.my transaction name is ZTRANS.

Now tell me onething, If same user opens the same transaction again(\n) , transaction opens for simultaneous access.

How to deal this case..will this FM cover this function also?

CALL FUNCTION 'ENQUEUE_E_TABLE'

EXPORTING

  • MODE_RSTABLE = 'E'

TABNAME = 'ZTRAN$'

  • VARKEY =

  • X_TABNAME = ' '

  • X_VARKEY = ' '

  • _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.

0 Kudos

If you /n, the transaction is terminated and all locks invoked by the transaction are released.

If you mean /o to open a new mode, then the user is treated as if they are a different userid and the lock request will fail in the new mode.

Former Member
0 Kudos

Please do not forget to award points as you see fit. Glad to hear that you are getting a lot of good feedback from the forum.