title: How to replace WAIT, to avoid locked error and to free the memory
body: <p>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 <code>WAIT UP TO x SECONDS</code> instruction is now forbidden and not negotiable.</p>
  
  <h1>Issue</h1>
  
  <pre><code>CALL FUNCTION 'ANY_FUNCTION_WITH_LOCK'.
  
  CALL FUNCTION 'ANY_FUNCTION_WITH_LOCK_2'.
  </code></pre>
  
  <p>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).</p>
  
  <p>I can resolve this issue by the usage of <code>WAIT</code>.</p>
  
  <pre><code>CALL FUNCTION 'ANY_FUNCTION_WITH_LOCK'.
  
  WAIT UP TO 5 SECONDS. " or 1, 2, 3, 4, 5, ... seconds &lt;------------
  
  CALL FUNCTION 'ANY_FUNCTION_WITH_LOCK_2'.
  </code></pre>
  
  <p>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.</p>
  
  <blockquote>
    <p>But, If we execute this code inside a loop with a large number of objects, the system can wait during an <em>infinite</em> time until a memory dump.</p>
  </blockquote>
  
  <p>(Impacted functions are related to VL32N, QA11, ... and their objects)</p>
  
  <h1>Need</h1>
  
  <p>The need is <strong>How to replace the WAIT instruction ?</strong>
  We need to find a solution/function that has the same behavior as the <code>WAIT UP TO</code>, but that will not impact (or less) the memory level (dump, excessive consumption of resources, ...)</p>
  
  <p>In fact we need something like the <code>COMMIT WORK AND WAIT</code> but with the result of a function and not the database.</p>
  
  <h1>Solutions ?</h1>
  
  <ul>
  <li><p>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.
  <em>It seems that this solution need the same level of resource as the <code>WAIT</code>.</em></p></li>
  <li><p>ENQUE_SLEEP seems to have the same behavior that WAIT on the memory (<a href="https://stackoverflow.com/questions/396663/how-to-make-an-abap-program-pause">How to make an abap program pause?</a>)</p></li>
  <li><p>Refactor all the code already done, and use synchronous functions.</p></li>
  </ul>
  
  <p>Anything else ? Any idea ? Is it even possible?</p>
  
  <p>Thanks in advance :)</p>