0

I have today a question about the usage of the WAIT. I work with an internal source code quality team, in charge of reviewing your code and approve it. Unfortunately, the usage of WAIT UP TO x SECONDS instruction is now forbidden and not negotiable.

Issue

CALL FUNCTION 'ANY_FUNCTION_WITH_LOCK'.

CALL FUNCTION 'ANY_FUNCTION_WITH_LOCK_2'.

If I execute this pseudo-code, I will have an error (locked object) because I use shared objects (I use function modules without sync/async mode).

I can resolve this issue by the usage of WAIT.

CALL FUNCTION 'ANY_FUNCTION_WITH_LOCK'.

WAIT UP TO 5 SECONDS. " or 1, 2, 3, 4, 5, ... seconds <------------

CALL FUNCTION 'ANY_FUNCTION_WITH_LOCK_2'.

With this method (and std functions), the system will stop and wait for a specific time. But, sometime the system need 1 second ... or more. We can't know the exact time needed.

But, If we execute this code inside a loop with a large number of objects, the system can wait during an infinite time until a memory dump.

(Impacted functions are related to VL32N, QA11, ... and their objects)

Need

The need is How to replace the WAIT instruction ? We need to find a solution/function that has the same behavior as the WAIT UP TO, but that will not impact (or less) the memory level (dump, excessive consumption of resources, ...)

In fact we need something like the COMMIT WORK AND WAIT but with the result of a function and not the database.

Solutions ?

  • Use a loop with timestamp comparaison and use ENQUEUE_READ to get the list of locked objects and check if the needed object is in this list, until X secondes. It seems that this solution need the same level of resource as the WAIT.

  • ENQUE_SLEEP seems to have the same behavior that WAIT on the memory (How to make an abap program pause?)

  • Refactor all the code already done, and use synchronous functions.

Anything else ? Any idea ? Is it even possible?

Thanks in advance :)

Community
  • 1
  • 1
Georges O.
  • 972
  • 1
  • 9
  • 21
  • Are those both functions asynchronous RFC or do they use `UPDATE TASK`? First of all I would focus on why was was the `WAIT UP TO 5 SECONDS` introduced in the first place and there is nothing about it in your question. Getting rid of `WAIT UP TO x SECONDS` would rather mean that you want at least the first function module to be synchronous and the only reasonable solution from my point of view would be to make it synchronous. The other solution would be to introduce a retry counter but without `WAIT UP TO` and retry till the lock is released or the counter is up. – Jagger Apr 05 '17 at 14:06
  • You wanna say that program falls to dumb because of this `WAIT` statement? That's why you wanna remove them? – Suncatcher Apr 06 '17 at 11:05
  • Are these standard FMs? Is there a BAPI that can be used in place of the FMs? – Brian Apr 06 '17 at 15:26

2 Answers2

1

Why not just put a check for the lock in between the two function modules? You could put that inside of a loop and exit the loop as soon as the lock is cleared from FM 1.

Bryan Cain
  • 1,736
  • 9
  • 17
  • You would need a limit on the number of loop passes. The limit would depend on what exactly you're doing - some processes might tolerate a longer wait than others. – Bryan Cain Apr 06 '17 at 14:36
0

I use ENQUE_SLEEP when I want to wait for a specified amount of time and then recheck something. For example you could wait 5 seconds and then check for the existence of the locks. If the objects are no longer locked, then proceed. If the locks are still there, sleep again. To avoid an infinite loop, you must have some limit on the number of times you are willing to sleep before you give up and log some kind of an error.

The problem with WAIT is it triggers an implicit commit. ENQUE_SLEEP will not do that.

JDC
  • 21
  • 6