<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: How to Lock/Enqueue objects and keep it locked until we  explicitly dequeue it. in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/how-to-lock-enqueue-objects-and-keep-it-locked-until-we-explicitly-dequeue/qaa-p/12448231#M4661985</link>
    <description>&lt;P&gt;Scope '3' should do the trick, but I have experienced similar problems. Is your program executing without GUI context, e.g. as a web service implementation or in a background job?&lt;/P&gt;</description>
    <pubDate>Wed, 26 May 2021 11:50:26 GMT</pubDate>
    <dc:creator>KjetilKilhavn</dc:creator>
    <dc:date>2021-05-26T11:50:26Z</dc:date>
    <item>
      <title>How to Lock/Enqueue objects and keep it locked until we  explicitly dequeue it.</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-lock-enqueue-objects-and-keep-it-locked-until-we-explicitly-dequeue/qaq-p/12448227</link>
      <description>&lt;P&gt;What is the best way to lock/enqueue an object even after the code that created the lock ends. Only an explicit dequeue call on that object should be able to unlock/dequeue that object.&lt;/P&gt;
  &lt;P&gt;I want to dequeue only if the transaction is completed. Currently my code is working in the case when we are in the process of&lt;/P&gt;
  &lt;P&gt;Any idea or solution would be greatly appreciated.&lt;/P&gt;
  &lt;P&gt;here is my code..&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;CALL FUNCTION 'ENQUEUE_READ'
  EXPORTING
*       GCLIENT               = SY-MANDT
    gname                 = 'ISEG'
*       GARG                  = ' '
*        guname                = sy-uname
*       LOCAL                 = ' '
*       FAST                  = ' '
*       GARGNOWC              = ' '
* IMPORTING
*       NUMBER                =
*       SUBRC                 = '0'
  TABLES
    enq                   = enq
  EXCEPTIONS
    communication_failure = 1
    system_failure        = 2
    OTHERS                = 3.
  IF sy-subrc &amp;lt;&amp;gt; 0.
** Implement suitable error handling here
  ENDIF.
  IF enq is INITIAL.

    CALL FUNCTION 'ENQUEUE_EZTESTLOCK'
      EXPORTING
       MODE_ISEG      = 'X'
       MANDT          = SY-MANDT
        iblnr          = lv_iblnr
        gjahr          = lv_gjahr
*       X_IBLNR        = ' '
*       X_GJAHR        = ' '
        _scope         = '3'
*       _WAIT          = ' '
*       _COLLECT       = ' '
      EXCEPTIONS
        foreign_lock   = 1
        system_failure = 2
        OTHERS         = 3.
    IF sy-subrc &amp;lt;&amp;gt; 0.
* Implement suitable error handling here
    ENDIF.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*     EXPORTING
*       WAIT          =
*     IMPORTING
*       RETURN        =
              .
    ELSE.
    CONCATENATE  iblnr lv_gjahr   INTO ld_garg SEPARATED BY space.
    LOOP AT enq INTO wa_enq WHERE garg CS ld_garg.
      EXIT.
    ENDLOOP.
    CHECK sy-subrc EQ 0.
    IF wa_enq-guname EQ sy-uname.
      ls_entityset-zmessage = |User | &amp;amp;&amp;amp; sy-uname &amp;amp;&amp;amp; | blocks physical inventory document | &amp;amp;&amp;amp; ld_garg .
      APPEND ls_entityset TO et_entityset.
      ENDIF.
***************OPTIONAL
    EXIT.

************End Enque

ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 May 2021 10:38:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-lock-enqueue-objects-and-keep-it-locked-until-we-explicitly-dequeue/qaq-p/12448227</guid>
      <dc:creator>nandini_borse</dc:creator>
      <dc:date>2021-05-21T10:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to Lock/Enqueue objects and keep it locked until we  explicitly dequeue it.</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-lock-enqueue-objects-and-keep-it-locked-until-we-explicitly-dequeue/qaa-p/12448228#M4661982</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;Do you mean you want to be able to lock an object with some code you run on say Monday and then unlock it with some other code you run on Wednesday, in theory? (As far as I know, you won't be able to do that with ordinary locking. I would go for some kind of custom status mechanism for that...)&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 12:08:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-lock-enqueue-objects-and-keep-it-locked-until-we-explicitly-dequeue/qaa-p/12448228#M4661982</guid>
      <dc:creator>joltdx</dc:creator>
      <dc:date>2021-05-21T12:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to Lock/Enqueue objects and keep it locked until we  explicitly dequeue it.</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-lock-enqueue-objects-and-keep-it-locked-until-we-explicitly-dequeue/qaa-p/12448229#M4661983</link>
      <description>&lt;P&gt;I guess you can do it with _scope         = '1' (ends with explicit dequeue or end of internal session)&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 14:15:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-lock-enqueue-objects-and-keep-it-locked-until-we-explicitly-dequeue/qaa-p/12448229#M4661983</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2021-05-21T14:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to Lock/Enqueue objects and keep it locked until we  explicitly dequeue it.</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-lock-enqueue-objects-and-keep-it-locked-until-we-explicitly-dequeue/qaa-p/12448230#M4661984</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;bear in mind(Joergen's comment) that the SAP locking tables grow significantly in size over time, and imagine what happens if multiple users leave such long-term persisted locks in the system. Even if it is possible to achieve such locks, the proper pattern is to have status handling, and indicate the status 'Locked' in a database field, the most SAP products have a similar concept...&lt;/P&gt;</description>
      <pubDate>Tue, 25 May 2021 09:27:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-lock-enqueue-objects-and-keep-it-locked-until-we-explicitly-dequeue/qaa-p/12448230#M4661984</guid>
      <dc:creator>former_member660513</dc:creator>
      <dc:date>2021-05-25T09:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to Lock/Enqueue objects and keep it locked until we  explicitly dequeue it.</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-lock-enqueue-objects-and-keep-it-locked-until-we-explicitly-dequeue/qaa-p/12448231#M4661985</link>
      <description>&lt;P&gt;Scope '3' should do the trick, but I have experienced similar problems. Is your program executing without GUI context, e.g. as a web service implementation or in a background job?&lt;/P&gt;</description>
      <pubDate>Wed, 26 May 2021 11:50:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-lock-enqueue-objects-and-keep-it-locked-until-we-explicitly-dequeue/qaa-p/12448231#M4661985</guid>
      <dc:creator>KjetilKilhavn</dc:creator>
      <dc:date>2021-05-26T11:50:26Z</dc:date>
    </item>
  </channel>
</rss>

