‎2010 Nov 25 11:02 AM
Hello Everybody,
I have a question?
Is it possible, to lock a programm, while it is in use? (like the "lock objects" for tables, etc.) For example, User X1 uses a Z-Program. Now, user X2 also wants to use this Z-Program. This is not possible because user X1 is already using the Z-Program (because it is locked). User X2 can only use the Z-Programm if X1(or any other user) doesn't use it anymore! Is that possible?
If yes, how?
Thanks for all answers!
Best regards,
Oskar
‎2010 Nov 25 3:00 PM
Here it is, Try executin this program in two sessions. Also dequeue it after program gets executed.
TYPE-POOLS:abap.
DATA:lock TYPE boolean.
PARAMETERS: pa_chr TYPE char12.
INITIALIZATION.
IF lock = abap_off.
PERFORM enqueue_program.
ELSE.
PERFORM dequeue_program.
ENDIF.
START-OF-SELECTION.
WRITE :/ 'Processing Starts'.
WRITE :/ 'Program locked'.
WRITE :/ 'This program will not be allowed to be executed by multiple'.
WRITE :/ 'Users in the same time'.
FORM enqueue_program .
CALL FUNCTION 'ENQUEUE_E_DSVAS_TRDIR'
EXPORTING
mode_trdir = 'X'
name = sy-repid
x_name = ' '
_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.
ELSE.
lock = abap_on.
ENDIF.
ENDFORM. " ENQUEUE_PROGRAM
FORM dequeue_program .
lock = abap_off.
CALL FUNCTION 'DEQUEUE_E_DSVAS_TRDIR'
EXPORTING
mode_trdir = 'X'
name = sy-repid
x_name = ' '
_scope = '3'
_synchron = ' '
_collect = ' '.
ENDFORM. " DEQUEUE_PROGRAM
‎2010 Nov 25 11:26 AM
Hi,
Create a Z tcode for that Z program.
Before executing Z program check that Tcode executing by another user using FM:TH_USER_LIST
If any user is using same tcode then populate a error message.
Thanks and Regards,
Chandra
‎2010 Nov 25 11:34 AM
Hi Oskar,
First create a table with two fields MANDT and PROGRAMM (datatypes are the same) .
Then create a Lock Object using SE11 and use the created table as primary table.
Using the lock module (FM), you can make sure that only a single instance of a program is working at the same time.
(Your lock argument will be the program name)
Good luck,
Ozcan.
‎2010 Nov 25 11:38 AM
Use lock object E_DSVAS_TRDIR. Use it in your program in the begining. Enqueue and dequeue as required.
‎2010 Nov 25 12:02 PM
Hi,
Check this:
DATA: w_client LIKE sy-mandt,
w_uname LIKE sy-uname,
w_hostaddr LIKE msxxlist-hostadr,
w_addrstr TYPE ni_nodeaddr,
w_terminal(10) type c.
*TH_USER_INFO - Give information about the current user
*(sessions, workstation logged in from, etc)
CALL FUNCTION 'TH_USER_INFO'
EXPORTING
client = w_client
user = w_uname
check_gui = 0
IMPORTING
hostaddr = w_hostaddr
TERMINAL = w_TERMINAL
addrstr = w_addrstr.
WRITE 😕 w_hostaddr,
w_terminal,
w_addrstr.
*TH_USER_LIST - Show which users are logged into an app server.
DATA: i_itab1 TYPE TABLE OF uinfo,
i_itab2 TYPE TABLE OF usrinfo,
wa_itab1 LIKE LINE OF i_itab1,
wa_itab2 LIKE LINE OF i_itab2.
CALL FUNCTION 'TH_USER_LIST'
TABLES
list = i_itab1
usrlist = i_itab2.
LOOP AT i_itab2 INTO wa_itab2.
WRITE:/ wa_itab2-mandt,
wa_itab2-tcode,
wa_itab2-bname,
wa_itab2-HOSTADDR.
ENDLOOP.
***********U can lock the users by given a error msg ....
Regards
Alfred
‎2010 Nov 25 12:21 PM
Hey...
thanks for you answers, there are really good. Especially the answer with the FM: TH_USER_LIST and TH_USER_INFO. Actually they are the same. Anyway, the problem is that user can also have more than one modi. Am I able to list all users with all there transaction which are in use? Then I'm able to check this list with my Z-Transaction which are only allowed for one user.
Thanks again for the answers!
Best regards,
Oskar
‎2010 Nov 25 12:23 PM
‎2010 Nov 25 12:29 PM
Hello,
Instead of using all those fm's and preparing a logic , you can just use the lock object inside your program. It works very well.
‎2010 Nov 25 3:13 PM
Hello Keshav.T,
THANKS for your solution, very good!
I have another solution with the FM: ENQUEUE_E_TABLE!
This FM solves also the problem. I lock my programm with following parameter:
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
mode_rstable = 'S'
tabname = 'ZMGTQUEUE_TEST'
And check with sy-subrc following exception:
EXCEPTIONS
FOREIGN_LOCK = 1
IF sy-subrc is '1', the program is already locked. IF sy-subrc is not '1', the FM will lock the program!
What do you think? Could be also a good solution!
Here the code, it's only just this:
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
mode_rstable = 'X'
tabname = 'ZMGTQUEUE_TEST'
varkey = 'only one user'
x_tabname = ' '
x_varkey = ' '
_scope = '2'
_wait = ' '
_collect = ' '
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3
.
IF sy-subrc = 1.
MESSAGE 'Only one user allowed!'
TYPE 'E'.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Best regards,
Oskar
‎2010 Nov 25 3:18 PM
Hello Keshav.T,
ok, I tried your solution and decided to use it! Thanks!
Best regards,
Oskar
‎2010 Nov 25 3:21 PM
‎2010 Nov 25 3:22 PM
‎2010 Nov 25 3:00 PM
Here it is, Try executin this program in two sessions. Also dequeue it after program gets executed.
TYPE-POOLS:abap.
DATA:lock TYPE boolean.
PARAMETERS: pa_chr TYPE char12.
INITIALIZATION.
IF lock = abap_off.
PERFORM enqueue_program.
ELSE.
PERFORM dequeue_program.
ENDIF.
START-OF-SELECTION.
WRITE :/ 'Processing Starts'.
WRITE :/ 'Program locked'.
WRITE :/ 'This program will not be allowed to be executed by multiple'.
WRITE :/ 'Users in the same time'.
FORM enqueue_program .
CALL FUNCTION 'ENQUEUE_E_DSVAS_TRDIR'
EXPORTING
mode_trdir = 'X'
name = sy-repid
x_name = ' '
_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.
ELSE.
lock = abap_on.
ENDIF.
ENDFORM. " ENQUEUE_PROGRAM
FORM dequeue_program .
lock = abap_off.
CALL FUNCTION 'DEQUEUE_E_DSVAS_TRDIR'
EXPORTING
mode_trdir = 'X'
name = sy-repid
x_name = ' '
_scope = '3'
_synchron = ' '
_collect = ' '.
ENDFORM. " DEQUEUE_PROGRAM
‎2015 Feb 03 12:28 PM