<?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>topic Transactional BGRFC Delay Method in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/transactional-bgrfc-delay-method/m-p/12210341#M1982728</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;
  &lt;P&gt;I work as an ABAPer but don't have a lot of experience with BGRFCs.&lt;/P&gt;
  &lt;U&gt;Requirement&lt;/U&gt;
  &lt;STRONG&gt;: -&lt;/STRONG&gt;
  &lt;BR /&gt;
  &lt;OL&gt;
   &lt;LI&gt;The user makes amendments in a document called &lt;STRONG&gt;'Trading Contract'&lt;/STRONG&gt; and clicks on the &lt;STRONG&gt;'Save'&lt;/STRONG&gt; button to save them.&lt;/LI&gt;
   &lt;LI&gt;When the save button is clicked, a BGRFC is executed to transition (via a BAPI) the contract from its existing status to a new status ('Awaiting Amendment Approval'). A BGRFC is being used because this can't be done in the same LUW because of technical reasons.&lt;/LI&gt;
  &lt;/OL&gt;
  &lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Program snippet&lt;/U&gt;&lt;/STRONG&gt;: -&lt;/P&gt;
  &lt;P&gt;....&lt;BR /&gt; lv_dest_name = '/ACCGO/AMEND'.&lt;BR /&gt;lo_destination = cl_bgrfc_destination_inbound=&amp;gt;create( lv_dest_name ).&lt;BR /&gt;lo_unit = lo_destination-&amp;gt;create_trfc_unit( ).&lt;BR /&gt;&lt;BR /&gt;CALL FUNCTION '/ACCGO/CTR_TC_STATUS_CHANGE' IN BACKGROUND UNIT lo_unit&lt;BR /&gt; EXPORTING&lt;BR /&gt; iv_tkonn = iv_contract_num&lt;BR /&gt; iv_btbsta = lv_unapp_amend_status.&lt;BR /&gt;&lt;BR /&gt;CALL METHOD lo_unit=&amp;gt;delay(5).&lt;BR /&gt;....&lt;BR /&gt;....&lt;BR /&gt;COMMIT statement is somewhere later in the code.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;U&gt;Issue&lt;/U&gt;&lt;/STRONG&gt;: - &lt;/P&gt;
  &lt;P&gt;After the COMMIT, it sometimes takes some time for the lock on the trading contract to get released. If the BGRFC gets immediately executed (after execution of the COMMIT), and if the lock is not released, the BGRFC will not be able to do its job. I introduced the DELAY statement above hoping that it will reduce the chances of this happening. But, as a result of the DELAY, it seems that the unit simply does not get executed...it remains locked (as seen in SBGRFCMON) even after the 5 seconds are over. Could anyone help me out here?&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jun 2020 11:44:26 GMT</pubDate>
    <dc:creator>former_member202335</dc:creator>
    <dc:date>2020-06-09T11:44:26Z</dc:date>
    <item>
      <title>Transactional BGRFC Delay Method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/transactional-bgrfc-delay-method/m-p/12210341#M1982728</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;
  &lt;P&gt;I work as an ABAPer but don't have a lot of experience with BGRFCs.&lt;/P&gt;
  &lt;U&gt;Requirement&lt;/U&gt;
  &lt;STRONG&gt;: -&lt;/STRONG&gt;
  &lt;BR /&gt;
  &lt;OL&gt;
   &lt;LI&gt;The user makes amendments in a document called &lt;STRONG&gt;'Trading Contract'&lt;/STRONG&gt; and clicks on the &lt;STRONG&gt;'Save'&lt;/STRONG&gt; button to save them.&lt;/LI&gt;
   &lt;LI&gt;When the save button is clicked, a BGRFC is executed to transition (via a BAPI) the contract from its existing status to a new status ('Awaiting Amendment Approval'). A BGRFC is being used because this can't be done in the same LUW because of technical reasons.&lt;/LI&gt;
  &lt;/OL&gt;
  &lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Program snippet&lt;/U&gt;&lt;/STRONG&gt;: -&lt;/P&gt;
  &lt;P&gt;....&lt;BR /&gt; lv_dest_name = '/ACCGO/AMEND'.&lt;BR /&gt;lo_destination = cl_bgrfc_destination_inbound=&amp;gt;create( lv_dest_name ).&lt;BR /&gt;lo_unit = lo_destination-&amp;gt;create_trfc_unit( ).&lt;BR /&gt;&lt;BR /&gt;CALL FUNCTION '/ACCGO/CTR_TC_STATUS_CHANGE' IN BACKGROUND UNIT lo_unit&lt;BR /&gt; EXPORTING&lt;BR /&gt; iv_tkonn = iv_contract_num&lt;BR /&gt; iv_btbsta = lv_unapp_amend_status.&lt;BR /&gt;&lt;BR /&gt;CALL METHOD lo_unit=&amp;gt;delay(5).&lt;BR /&gt;....&lt;BR /&gt;....&lt;BR /&gt;COMMIT statement is somewhere later in the code.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;U&gt;Issue&lt;/U&gt;&lt;/STRONG&gt;: - &lt;/P&gt;
  &lt;P&gt;After the COMMIT, it sometimes takes some time for the lock on the trading contract to get released. If the BGRFC gets immediately executed (after execution of the COMMIT), and if the lock is not released, the BGRFC will not be able to do its job. I introduced the DELAY statement above hoping that it will reduce the chances of this happening. But, as a result of the DELAY, it seems that the unit simply does not get executed...it remains locked (as seen in SBGRFCMON) even after the 5 seconds are over. Could anyone help me out here?&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2020 11:44:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/transactional-bgrfc-delay-method/m-p/12210341#M1982728</guid>
      <dc:creator>former_member202335</dc:creator>
      <dc:date>2020-06-09T11:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: Transactional BGRFC Delay Method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/transactional-bgrfc-delay-method/m-p/12210342#M1982729</link>
      <description>&lt;P&gt;Why don't you start your RFC function at the end of the update task to minimize the chance of being locked? (you do this by creating an update function module, and running it after all other update function modules, and your update function module starts the RFC).&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2020 12:45:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/transactional-bgrfc-delay-method/m-p/12210342#M1982729</guid>
      <dc:creator>Sandra_Rossi</dc:creator>
      <dc:date>2020-06-09T12:45:53Z</dc:date>
    </item>
    <item>
      <title>Re: Transactional BGRFC Delay Method</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/transactional-bgrfc-delay-method/m-p/12210343#M1982730</link>
      <description>&lt;P&gt;I had exact same problem and realized there's no way to ensure data is unlocked, so what I did is try to acquire the lock for 200 seconds (that is enough for my project) and if that fails I crash the unit with an error (just throw an exception). This allows a human being to look at it and restart it in &lt;STRONG&gt;SBGRFCMON&lt;/STRONG&gt;. Units can also be restarted through code (like dedicated programs).&lt;/P&gt;&lt;P&gt;This code is written within a bgRFC function. I launch the unit and let it wait for locks with some delays. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;while lo_obj-&amp;gt;is_locked = abap_false         &amp;lt;br&amp;gt;   and lv_lock_attempts &amp;lt; 100. "Limit attempts count to prevent lockups
  try.
      add 1 to lv_lock_attempts.
      lo_obj-&amp;gt;lock( ). "Throws exception if lock fails
    catch zcx_lock.
        call function 'ENQUE_SLEEP' 
           exporting
             seconds = 2.
  endtry.
endwhile.
...
if lo_obj-&amp;gt;is_locked = abap_false.
  raise object_locked. "Crashes the unit
endif.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Note: I also call this unit within the same LUW where unlock is supposed to happen to minimize the  time window that people have to manually lock the data. You might also want to use &lt;STRONG&gt;unit-&amp;gt;delay( )&lt;/STRONG&gt; if you know for a fact that data will stay locked for at least a specific amount of time.&lt;/P&gt;</description>
      <pubDate>Mon, 10 May 2021 08:05:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/transactional-bgrfc-delay-method/m-p/12210343#M1982730</guid>
      <dc:creator>ldaunys</dc:creator>
      <dc:date>2021-05-10T08:05:51Z</dc:date>
    </item>
  </channel>
</rss>

