Application Development 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: 

Is it possible to have Exclusive code execution

Former Member
0 Kudos

I want to make sure that a particular function module or a piece of code cannot be executed by two programs (run by the same user or different users) at the same time. And if two programs attempt to execute that function module or piece of code simultaneously. They are queued so that one get executed only after the other is finished.

1 ACCEPTED SOLUTION

nkr1shna
Contributor
0 Kudos

Hi Srikrishna,

You can achieve this by creating events (the ones you will be use/create for workflows). You can create event when your function module starts, which should also check whether event already exists and avoid multiple users launching the function module.

Let me know what is your opinion on this.

Regards

Krishna

3 REPLIES 3

Former Member
0 Kudos

Can you tell us what would you like to achieve by doing so ? Are you updating any database table inside this function ? If yes, then you can lock the table update the database and then unlock the table again.

regards,

Advait

former_member156446
Active Contributor
0 Kudos

Hi there to lock a program


When you create a lock object System automatically creates two function module.
1. ENQUEUE_<Lockobject name>. to insert the object in a queue.
2. DEQUEUE_<Lockobject name>. To remove the object is being queued through above FM.


call function 'ENQUEUE_E_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.
endif.

[More info|https://forums.sdn.sap.com/click.jspa?searchID=19841120&messageID=6452619]

nkr1shna
Contributor
0 Kudos

Hi Srikrishna,

You can achieve this by creating events (the ones you will be use/create for workflows). You can create event when your function module starts, which should also check whether event already exists and avoid multiple users launching the function module.

Let me know what is your opinion on this.

Regards

Krishna