‎2007 Aug 06 3:54 PM
Hello,
There is a scenario, where user calls a function module via RFC.
The requirement is to avoid the user from running the function module parallely twice or more because it may lead to dead lock problems.
To realize this creation of a new enqueue object and set up of enqueue of this object in the function is suggested.
If the object is blocked (which means the function is already being
running by the sorter), it should go out of the function.
Can i get help in locking this function module during execution.
With Best Regards,
Adarsh.
‎2007 Aug 06 9:15 PM
Hello Adarsh
If the RFC calls all come from the same system (= calling system) then I would recommend to create a simple "lock structure" containing only a single field for the function module name.
Use this structure to create a lock object. The lock entry simply contains the called function module.
Your program could contain the following logic (pseudo coding):
IF ( <lock entry for function module exists already> ).
MESSAGE 'No parallel processing of fm ...' TYPE 'S'.
ELSE.
CALL FUNCTION '<enqueue function module>' " set lock
EXPORTING
funcname = '<name of function module'
... .
IF ( syst-subrc = 0 ). " lock could be set
CALL FUNCTION '<name of function module>
DESTINATION '<rfc destination>'
... .
CALL FUNCTION '<dequeue function module>' " remove lock
EXPORTING
funcname = '<name of function module'
... .
ELSE.
" error message in case of lock failure
ENDIF.
ENDIF.If the lock has to be user specific simply add a username field to your lock structure.
If the RFC-enabled function module can be called from different systems then you could place the locking logic into the called function module. Obviously, the locking structure must then be created on the remote system.
Regards
Uwe
‎2007 Aug 06 9:15 PM
Hello Adarsh
If the RFC calls all come from the same system (= calling system) then I would recommend to create a simple "lock structure" containing only a single field for the function module name.
Use this structure to create a lock object. The lock entry simply contains the called function module.
Your program could contain the following logic (pseudo coding):
IF ( <lock entry for function module exists already> ).
MESSAGE 'No parallel processing of fm ...' TYPE 'S'.
ELSE.
CALL FUNCTION '<enqueue function module>' " set lock
EXPORTING
funcname = '<name of function module'
... .
IF ( syst-subrc = 0 ). " lock could be set
CALL FUNCTION '<name of function module>
DESTINATION '<rfc destination>'
... .
CALL FUNCTION '<dequeue function module>' " remove lock
EXPORTING
funcname = '<name of function module'
... .
ELSE.
" error message in case of lock failure
ENDIF.
ENDIF.If the lock has to be user specific simply add a username field to your lock structure.
If the RFC-enabled function module can be called from different systems then you could place the locking logic into the called function module. Obviously, the locking structure must then be created on the remote system.
Regards
Uwe
‎2007 Aug 07 6:20 AM
Hello Uwe,
Thanks for your reply. The RFC-enabled function module can be called from different systems, so as suggested by you the locking logic could be placed into the called function module.
But I don't have access or to the calling remote system, to create a locking structure on it.
And I also need help in creating the locking structure, as I have not created any such locking structure before.
Can u brief me further on this issue.
With Best Regards,
Adarsh.
‎2007 Aug 07 7:20 AM
Here's a sample of how you might do this - see comments in code for explanation.. run the program in two differ SAPGui sessions to see the effect.
report zlocal_jc_tfdir_lock.
start-of-selection.
perform set_and_check_lock.
form set_and_check_lock.
*" Use SAP enqueue to prevent multiple RFC calls of same object
data:
l_object like tfdir-funcname.
*" Build some name that is specific to your needs
*" Include sy-uname in key if lock is per user, not for process
concatenate '#Z LOCK:' sy-uname into l_object.
*" and enqueue
call function 'ENQUEUE_ESFUNCTION'
exporting
funcname = l_object
exceptions
foreign_lock = 1
system_failure = 2
others = 3.
if not sy-subrc is initial.
message e398(00)
with
l_object 'is held by' sy-msgv1 space.
else.
write: / l_object, 'is now locked - check sm12 for proof'.
endif.
endform.
‎2007 Aug 07 12:18 PM
Thank you <b>Jonathan Coleman</b> and <b>Uwe Schieferstein</b>.
<i><b>Uwe</b></i>, thanks for providing the essential basic approach to this issue, which was very useful.
<b><i>Jonathan</i></b>, thanks for your elaborate suggestion, which ultimately lead to solving the issue.
With Best Regards,
Adarsh.
‎2007 Aug 07 12:22 PM
‎2007 Aug 13 12:52 PM