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

Locking one program if another is running ....

Former Member
0 Likes
1,775

Hi experts,

I have came across a situation, before executing one program, i have to check weather other program is running or not.

Lets say I have 2 programs, program 1 and program 2.

1. If I want to run the pg 1, in foreground, I have to check weather prg 2 is running either in foreground or in background. If it is running in both the conditions, I have to raise an error message at the time of execution of prg 1 itself.

2. If I want to scedule the prg 1. At the time of its execution in background, it should check that prg 2 is not running at all (neither foreground nor background). If the prg 2 is running, prg 1 should, either wait till prg 2 gets executed or get rescheduled.

Please provide me your valuable suggestions.

Regards,

Ganesh V Khumse.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,304

I think you have to use

CALL FUNCTION 'ENQUEUE_ESINDX'

twice. i.e. in prog1 with the progname prog1 and in prog2 with same progname i.e. prog1.

i.e. use same coding in two prog with same progname.

now when prog1 is running you can not run prog2.

check it may work.

regards

shiba dutta

7 REPLIES 7
Read only

Former Member
0 Likes
1,304

Hi Ganesh,

For all these below problems we have to use function module <b>'ENQUEUE_ESINDX'</b>, pass program name; if sy-subrc ne 0 then someone is running the program.

Below is sample code.

CALL FUNCTION 'ENQUEUE_ESINDX'

EXPORTING

MODE_INDX = 'E'

MANDT = SY-MANDT

SRTFD = 'program name'

EXCEPTIONS

FOREIGN_LOCK = 1

SYSTEM_FAILURE = 2

OTHERS = 3.

Hope it will solve ur problem.

Regards

Krishnendu

Read only

0 Likes
1,304

Hi Krishnendu Laha,

Thanks for the reply. When I tried to use this FM, the FM is taking only that program itself into consideration.

for Ex.

I passed the PRG 2 to the Function module, run the PRG 2 and after that I run the PRG 1 in which I am calling that FM. Even the PRG2 was running it was not giving the SY-SUBRC <> 0.

Interestingly for the same coding as above, when I run the PRG 1 and after that again I run the PRG 1. Now the FM is working properly.

That means this FM is only for the same program and not for the other program. I need to chcek the other program running or not.

Or is there something we are not passing to the FM and because of which we are getting this situation.

Please help.

Ganesh

Read only

hymavathi_oruganti
Active Contributor
0 Likes
1,304

call function 'ENQUEUE_READ'

exporting

gclient = gclient

guname = guname

gname = gname

garg = garg

importing

subrc = subrc

tables

enq = enq

exceptions

others = 1.

the above fn module helps to read the lock entries

Read only

Former Member
0 Likes
1,305

I think you have to use

CALL FUNCTION 'ENQUEUE_ESINDX'

twice. i.e. in prog1 with the progname prog1 and in prog2 with same progname i.e. prog1.

i.e. use same coding in two prog with same progname.

now when prog1 is running you can not run prog2.

check it may work.

regards

shiba dutta

Read only

0 Likes
1,304

Hi Shiba,

I think it is working now. Thanks ..... but can you give me a favor and explain it why it is happening like that.

Things are working but I didn't get the exact logic behind it.

Once again thanks.

Ganesh

Read only

0 Likes
1,304

I think when you are locking the prog1 by enque fm then it will not release the lock until it process completely. So if in prog2 again you are trying to lock it it will return the sy-subrc ne 0. But you can face some problem when prog2 will also run then you cant run prog1 also. Because in prog2 also you are locking the prog1 as well.

regards

shiba dutta

Read only

0 Likes
1,304

Hi Shiba,

Things are clear now. Thanks for your replay and anyway I think I willl not get any probelm, because I have to it like that only, I mean if prg 1 is running it should not run prg2 and VICE VERSA.

So it is working for me!

Thanks a lot,

Ganesh