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

Check if program is currently running

Former Member
0 Likes
7,480

Hello all,

I have developed a interactive Z application and I would like to add a routine to check to see if the user executing the program currently in the program in another session. Essentially I'd like to enforce one session of my program per user so if knows the code or function module to check this I would appreciate it.

Thanks!

1 ACCEPTED SOLUTION
Read only

Former Member
4,361

Use FM ENQUEUE_ESINDX .

Change your program so as to call the above FM before the start of the transaction. pass the program name and RELID as 'ZZ'.

So when another user tries to run the transaction, the FM throws an error message saying "Lock not possible".

Hope this helps. Reward points if helpful.

Thanks,

Balaji

Use FM ENQUEUE_ESINDX .

Change your program so as to call the above FM before the start of the transaction. pass the program name and RELID as 'ZZ'.

So when another user tries to run the transaction, the FM throws an error message saying "Lock not possible".

Hope this helps. Reward points if helpful.

Thanks,

Balaji

7 REPLIES 7
Read only

Former Member
4,362

Use FM ENQUEUE_ESINDX .

Change your program so as to call the above FM before the start of the transaction. pass the program name and RELID as 'ZZ'.

So when another user tries to run the transaction, the FM throws an error message saying "Lock not possible".

Hope this helps. Reward points if helpful.

Thanks,

Balaji

Read only

0 Likes
4,361

Thank you for the quick answer, one point of clarification though I would to restrict this by user so if I have 15 users in the program at one time that's OK however if I want prevent a single user from have multiple instances of the same program running. Can this be accomodate via this FM?

Read only

0 Likes
4,361

Use FM ENQUEUE_ESINDX .

Change your program so as to call the above FM before the start of the transaction. pass a unique name and RELID as 'ZZ'.

The unique name could be the program name. Since you want to prevent single user having multiple instances of the same program running, pass the unique name (l_var) as something like this:

concatenate <program name> <username> into the l_var.

Pass the l_var to the FM instead of the program name.

Hope this helps. Reward points if helpful

Thanks,

Balaji

Read only

0 Likes
4,361

Balaji - Do you have a small sample of code demonstrating this FM with parameters you mentioned?

Read only

4,361

Check the below code.



CALL FUNCTION 'ENQUEUE_ESINDX'
 EXPORTING
   MODE_INDX            = 'E'
   MANDT                = SY-MANDT
   RELID                = 'ZZ'
   SRTFD                = <unique name>  "In your case it will be username combined with program name
*   SRTF2                =
*   X_RELID              = ' '
*   X_SRTFD              = ' '
*   X_SRTF2              = ' '
*   _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.

Hope this helps. Reward points if helpful.

Thanks,

Balaji

Read only

Former Member
0 Likes
4,361

You can use function 'THUSRINFO', which will bring you the username and the transaction code, among other parameters. Then, before starting the report, you could check with this function if the user is already executing the transaction.

Read only

kan_sasivimolkul
Explorer
0 Likes
4,361

To check if program is running

SELECT COUNT( * )

INTO count

FROM tbtcp AS p INNER JOIN tbtco AS o

ON ojobname = pjobname

AND ojobcount = pjobcount

WHERE p~progname = sy-repid

AND o~delanfrep = space

AND o~status = 'R'.

IF count NE 1 = program is running