01-07-2005 3:25 AM
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
01-07-2005 7:17 AM
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.
01-07-2005 7:46 AM
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.
01-07-2005 2:50 PM
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.
01-07-2005 3:54 PM
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
01-08-2005 2:23 AM
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
01-08-2005 8:35 PM
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!
01-11-2005 5:15 AM
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.
01-11-2005 4:57 PM
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.
01-13-2005 2:25 PM
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.