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 the program

Former Member
0 Likes
3,148

Hi All,

Is there any way that i can make the program run at a time only once, so that if one instance of it is running it should give a message to others saying program is already running.

Let me know is there any other way of doing it..

Thank You,

Suresh

1 ACCEPTED SOLUTION
Read only

abdul_hakim
Active Contributor
0 Likes
2,720

hi babu,

create a z table (for eg,zvalidate) with a field (for eg,flag)of length 1 and type char.

in the program you can check

select single * from zvalidate into wa where flag = space.

if sy-subrc ne 0 .

<throw error message?

else.

<your report's executable statements>

UPDATE zvalidate set flag = 'X'.

endif.

Cheers,

Abdul Hakim

27 REPLIES 27
Read only

Former Member
0 Likes
2,720

You can import a variable intially and if it is set to X, do NOT execute the program and exit. Export a different value at the end of the program to that variable.

Regards,

Ravi

Read only

0 Likes
2,720

Hi Ravi,

Your solution seems to be quite interesting, can you please explain it more clearly ? Please attach the piece of code if available .

Regards,

Varun .

Read only

ferry_lianto
Active Contributor
0 Likes
2,720

Hi,

Please check this sample code from other thread.

  • Make sure that no one else is running this program

  • This is the locking mechanism for this program.

PROGRAM_NAME = SY-REPID.  
CALL FUNCTION 'ENQUEUE_ESINDX'       
  EXPORTING            
    SRTFD          = PROGRAM_NAME            
    SRTF2          = 0            
    _WAIT          = 2       
  EXCEPTIONS            
    FOREIGN_LOCK   = 1            
    SYSTEM_FAILURE = 2.  

IF SY-SUBRC <> 0.
*Give message that someone is running the program  
ENDIF.

Hope this will help.

Regards,

Ferry Lianto

Read only

Manohar2u
Active Contributor
0 Likes
2,720

Depends on whether it should be a userspecific or across the system.

If across the system then you need to flag in Z table at initial event start-of-selection and clear the flag at end of the program.

If with in the user's sessions use SET Parameter option.

Regds

Manohar

Read only

Former Member
0 Likes
2,720

hi suresh,

check this thread..

hope this helps,

do reward if it helps,

priya.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,720

You can use a lock object for the program.



report zrich_0001.


parameters: p_check.

at selection-screen output.

data: program type sy-repid.

program = sy-repid.
call function 'ENQUEUE_EPROG'
  exporting
   mode_trdir           = 'E'
   programm             = program
*   X_PROGRAMM           = ' '
*   _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.

Regards,

Rich Heilman

Read only

abdul_hakim
Active Contributor
0 Likes
2,721

hi babu,

create a z table (for eg,zvalidate) with a field (for eg,flag)of length 1 and type char.

in the program you can check

select single * from zvalidate into wa where flag = space.

if sy-subrc ne 0 .

<throw error message?

else.

<your report's executable statements>

UPDATE zvalidate set flag = 'X'.

endif.

Cheers,

Abdul Hakim

Read only

0 Likes
2,720

Hi All,

I want the program not to be executed by others when some body else is already running or using the program.

I tried doing all the solutions.. given by you all... but its not working for me..

i am working in 4.0 B version of SAP..FYI.

thank you,

Suresh

Read only

0 Likes
2,720

If you implement my sample program above, it is not working? Run it and allow to sit on the selection screen, now run it in another session, do you not get an error message saying that the program is already in use?

REgards,

Rich Heilman

Read only

0 Likes
2,720

when i write the code its stopping the control from not editing the program.. but not executing the program..

Read only

0 Likes
2,720

Copy and paste the program code that I've provided, activate the program, now back out of the editor and run it directly from the first screen of SE38. Leave it on the selection screen. Open another session and run the program again. Since the other session is currently running the program, you should get a message right away when running the program in the other session. Is this not happening?

Regards,

Rich Heilman

Read only

0 Likes
2,720

NO it is not working

Read only

0 Likes
2,720

I want no body else to run the program when.. for eg: i am running it..

Read only

0 Likes
2,720

Suresh, this is exactly how my example program works in my r/3 system. It will not allow me to run it while its being ran in another session. Not sure why its not working for you. Are you sure that the lock is being applied. Run the program and let it sit on the selecition screen, now go to another session and go to SM12. Check to see if a lock exists.

Regards,

Rich Heilman

Read only

0 Likes
2,720

Sorry.. i didnt tell u this before..

There is no function module ENQUEUE_EPROG in 4.0 B, i am using ENQUEUE_ES_PROG.

Pls suggest.

Suresh

Read only

0 Likes
2,720

Ahhh......

Regards,

Rich Heilman

Read only

0 Likes
2,720

Please try this example. This works good in my system.



report zrich_0001.

data: program type sy-repid.

parameters: p_check.

load-of-program.

  program = sy-repid.

  call function 'ENQUEUE_ES_PROG'
   exporting
*    MODE_TRDIR           = 'E'
     name                 = program
*    X_NAME               = ' '
*    _SCOPE               = '2'
*    _WAIT                = ' '
*    _COLLECT             = ' '
   exceptions
     foreign_lock         = 1
     system_failure       = 2
     others               = 3
            .

  if sy-subrc <> 0.
    message e001(00) with 'Program currently in use'.
  endif.

Regards,

Rich Heilman

Read only

0 Likes
2,720

Hi Rich,

It is working now.. but when the message is displayed i dont see the selection screen contents.. on the screen..

if sy-subrc <> 0.

set cursor field 'P_FL_UNX'.

set screen 0.

message e009(zmd) with 'Program is in use by other user'.

leave to list-processing.

endif.

though i used the above code it still not showing up the values..

any help on this...

Suresh

Read only

0 Likes
2,720

You still want to show the selection screen if the program is being run by another user?

Regards,

Rich Heilman

Read only

0 Likes
2,720

YES..

Read only

0 Likes
2,720

If so, try doing the lock in the start-of-selection instead.




report zrich_0001.

data: program type sy-repid.

parameters: p_check.

<b>start-of-selection.</b>

  program = sy-repid.

  call function 'ENQUEUE_ES_PROG'
   exporting
*    MODE_TRDIR           = 'E'
     name                 = program
*    X_NAME               = ' '
*    _SCOPE               = '2'
*    _WAIT                = ' '
*    _COLLECT             = ' '
   exceptions
     foreign_lock         = 1
     system_failure       = 2
     others               = 3
            .

  if sy-subrc <> 0.
    message e001(00) with 'Program currently in use'.
    exit.
  endif.



This will before the lock only when the user executes from selection screen.

Regards,

Rich Heilman

Read only

0 Likes
2,720

It is giving me the message in a blank screen.. not in the same screen as selection screen

Read only

0 Likes
2,720

Ok, how about in the AT SELECTION-SCREEN event.

change START-OF-SELECTION to AT SELECTION-SCREEN and try again.

Regards,

Rich Heilman

Read only

0 Likes
2,720

Thank You for all the help.. it worked..

Read only

0 Likes
2,720

Wooohooo!!! Now I can got to bed. Glad that it worked out for ya.

Regards,

Rich Heilman

Read only

0 Likes
2,720

It did.. Sorry for holding you up.. )))

Read only

0 Likes
2,720

No problem, that's ok. Glad to help.

Regards,

Rich Heilman