<?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 Re: Shared Memory - handling cx_shm_build_failed exception in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/shared-memory-handling-cx-shm-build-failed-exception/m-p/12284853#M1988997</link>
    <description>&lt;P&gt;I went through several SAP standard implementations of the interface IF_SHM_BUILD_INSTANCE. I could not find any common clear pattern in these implementations how to implement the method BUILD in the "right" way. I have noticed though that none of the implementations throw an exception in case the set method is not succesful.&lt;/P&gt;&lt;P&gt;I have modified my implementation in the following way. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;METHOD if_shm_build_instance~build.

* Autoload of SHMO (first time use, after system restart and so on)

  DATA: lcl_ldap TYPE REF TO zcl_ldap,
        lcl_ldap_root TYPE REF TO zcl_ldap_root,
        lx_exception TYPE REF TO cx_root.

  TRY.
      lcl_ldap = zcl_ldap=&amp;gt;attach_for_write( ).
      CREATE OBJECT lcl_ldap_root AREA HANDLE lcl_ldap.
      lcl_ldap-&amp;gt;set_root( lcl_ldap_root ).
    CATCH cx_shm_error
      INTO lx_exception.
      RAISE EXCEPTION TYPE cx_shm_build_failed
        EXPORTING
          previous = lx_exception.
  ENDTRY.

  TRY.
      lcl_ldap_root-&amp;gt;set_staff( ).
  CATCH zcx_ldap_not_reachable.
      lcl_ldap-&amp;gt;detach_rollback( ).
      RETURN.
  ENDTRY.

  TRY .
      lcl_ldap-&amp;gt;detach_commit( ).
    CATCH cx_shm_error INTO lx_exception.
      RAISE EXCEPTION TYPE cx_shm_build_failed
        EXPORTING
          previous = lx_exception.
  ENDTRY.

  IF invocation_mode = cl_shm_area=&amp;gt;invocation_mode_auto_build.
    CALL FUNCTION 'DB_COMMIT'.
  ENDIF.
ENDMETHOD.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am not sure if my implementation is 100% correct but it works - there are no short dumps in ST22 even if the third party system is not reachable.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Nov 2020 09:39:07 GMT</pubDate>
    <dc:creator>jiri_medved</dc:creator>
    <dc:date>2020-11-24T09:39:07Z</dc:date>
    <item>
      <title>Shared Memory - handling cx_shm_build_failed exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/shared-memory-handling-cx-shm-build-failed-exception/m-p/12284849#M1988993</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
  &lt;P&gt;I use shared memory for caching personal data from external system. The build method looks like following&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;METHOD if_shm_build_instance~build.

* Autoload of SHMO (first time use, after system restart and so on)

  DATA: lcl_ldap TYPE REF TO zcl_ldap,
        lcl_ldap_root TYPE REF TO zcl_ldap_root,
        lx_exception TYPE REF TO cx_root.

  TRY.
      lcl_ldap = zcl_ldap=&amp;gt;attach_for_write( ).
    CATCH cx_shm_error INTO lx_exception.
      RAISE EXCEPTION TYPE cx_shm_build_failed
        EXPORTING
          previous = lx_exception.
  ENDTRY.

  TRY.
      CREATE OBJECT lcl_ldap_root AREA HANDLE lcl_ldap.
      lcl_ldap-&amp;gt;set_root( lcl_ldap_root ).
      lcl_ldap_root-&amp;gt;set_staff( ).
      lcl_ldap-&amp;gt;detach_commit( ).
    CATCH cx_shm_error zcx_ldap_not_reachable
      INTO lx_exception.
      RAISE EXCEPTION TYPE cx_shm_build_failed
        EXPORTING
          previous = lx_exception.
  ENDTRY.

  IF invocation_mode = cl_shm_area=&amp;gt;invocation_mode_auto_build.
    CALL FUNCTION 'DB_COMMIT'.
  ENDIF.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;the method set_staff( ) gets the data from an external system and populates the shared memory. It raises ZCX_LDAP_NOT_REACHABLE if calling the external system fails.&lt;/P&gt;
  &lt;P&gt;In the main program I attach the shared memory like following:&lt;/P&gt;
  &lt;PRE&gt;&lt;CODE&gt;...
  DO 10 TIMES.
    TRY.
        lcl_ldap_shmo = zcl_ldap=&amp;gt;attach_for_read( ).
      CATCH cx_shm_inconsistent.
        zcl_ldap=&amp;gt;free_area( ).
      CATCH cx_shm_no_active_version
      cx_shm_read_lock_active
      cx_shm_change_lock_active
      cx_shm_exclusive_lock_active
      INTO lv_exception.
    ENDTRY.

    IF lcl_ldap_shmo IS NOT INITIAL.
      EXIT.
    ENDIF.
    WAIT UP TO 2 SECONDS.
  ENDDO.
...&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;It works fine if no exception is raised in the set_staff() method.&lt;/P&gt;
  &lt;P&gt;But if ZCX_LDAP_NOT_REACHABLE is raised the ATTACH_FOR_READ method raises CX_SHM_NO_ACTIVE_VERSION exception and there is a short dump of uncaught exception CX_SHM_BUILD_FAILED in ST22. &lt;/P&gt;
  &lt;P&gt;How can I catch the exception in order to avoid the short dump?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 16:10:08 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/shared-memory-handling-cx-shm-build-failed-exception/m-p/12284849#M1988993</guid>
      <dc:creator>jiri_medved</dc:creator>
      <dc:date>2020-11-23T16:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: Shared Memory - handling cx_shm_build_failed exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/shared-memory-handling-cx-shm-build-failed-exception/m-p/12284850#M1988994</link>
      <description>&lt;P&gt;Add the exception ZCX_LDAP_NOT_REACHABLE to the CATCH block.&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;    TRY.
        lcl_ldap_shmo = zcl_ldap=&amp;gt;attach_for_read( ).
      CATCH cx_shm_inconsistent.
        zcl_ldap=&amp;gt;free_area( ).
      CATCH cx_shm_no_active_version
      cx_shm_read_lock_active
      cx_shm_change_lock_active
      cx_shm_exclusive_lock_active 
      zcx_ldap_not_reachable " &amp;lt;--- Exception added
      INTO lv_exception.
    ENDTRY.
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Nov 2020 17:49:32 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/shared-memory-handling-cx-shm-build-failed-exception/m-p/12284850#M1988994</guid>
      <dc:creator>nmirandaghn</dc:creator>
      <dc:date>2020-11-23T17:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: Shared Memory - handling cx_shm_build_failed exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/shared-memory-handling-cx-shm-build-failed-exception/m-p/12284851#M1988995</link>
      <description>&lt;P&gt;Unfortunately that does not work.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 17:55:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/shared-memory-handling-cx-shm-build-failed-exception/m-p/12284851#M1988995</guid>
      <dc:creator>jiri_medved</dc:creator>
      <dc:date>2020-11-23T17:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Shared Memory - handling cx_shm_build_failed exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/shared-memory-handling-cx-shm-build-failed-exception/m-p/12284852#M1988996</link>
      <description>&lt;P&gt;What about if you add CX_ROOT exception to the CATCH block?&lt;/P&gt;&lt;P&gt;This exception will catch any exception.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 18:02:45 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/shared-memory-handling-cx-shm-build-failed-exception/m-p/12284852#M1988996</guid>
      <dc:creator>nmirandaghn</dc:creator>
      <dc:date>2020-11-23T18:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: Shared Memory - handling cx_shm_build_failed exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/shared-memory-handling-cx-shm-build-failed-exception/m-p/12284853#M1988997</link>
      <description>&lt;P&gt;I went through several SAP standard implementations of the interface IF_SHM_BUILD_INSTANCE. I could not find any common clear pattern in these implementations how to implement the method BUILD in the "right" way. I have noticed though that none of the implementations throw an exception in case the set method is not succesful.&lt;/P&gt;&lt;P&gt;I have modified my implementation in the following way. &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;METHOD if_shm_build_instance~build.

* Autoload of SHMO (first time use, after system restart and so on)

  DATA: lcl_ldap TYPE REF TO zcl_ldap,
        lcl_ldap_root TYPE REF TO zcl_ldap_root,
        lx_exception TYPE REF TO cx_root.

  TRY.
      lcl_ldap = zcl_ldap=&amp;gt;attach_for_write( ).
      CREATE OBJECT lcl_ldap_root AREA HANDLE lcl_ldap.
      lcl_ldap-&amp;gt;set_root( lcl_ldap_root ).
    CATCH cx_shm_error
      INTO lx_exception.
      RAISE EXCEPTION TYPE cx_shm_build_failed
        EXPORTING
          previous = lx_exception.
  ENDTRY.

  TRY.
      lcl_ldap_root-&amp;gt;set_staff( ).
  CATCH zcx_ldap_not_reachable.
      lcl_ldap-&amp;gt;detach_rollback( ).
      RETURN.
  ENDTRY.

  TRY .
      lcl_ldap-&amp;gt;detach_commit( ).
    CATCH cx_shm_error INTO lx_exception.
      RAISE EXCEPTION TYPE cx_shm_build_failed
        EXPORTING
          previous = lx_exception.
  ENDTRY.

  IF invocation_mode = cl_shm_area=&amp;gt;invocation_mode_auto_build.
    CALL FUNCTION 'DB_COMMIT'.
  ENDIF.
ENDMETHOD.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am not sure if my implementation is 100% correct but it works - there are no short dumps in ST22 even if the third party system is not reachable.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2020 09:39:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/shared-memory-handling-cx-shm-build-failed-exception/m-p/12284853#M1988997</guid>
      <dc:creator>jiri_medved</dc:creator>
      <dc:date>2020-11-24T09:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Shared Memory - handling cx_shm_build_failed exception</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/shared-memory-handling-cx-shm-build-failed-exception/m-p/12284854#M1988998</link>
      <description>&lt;P&gt;I can catch the exception cx_shm_no_active_version. But there is always short dump in ST22. The auto build of the shared memory is executed in a separate thread and the exception is not propagated to the calling thread.&lt;/P&gt;&lt;P&gt;I have found a workable solution - see my answer. Any comments highly welcomed.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Nov 2020 09:44:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/shared-memory-handling-cx-shm-build-failed-exception/m-p/12284854#M1988998</guid>
      <dc:creator>jiri_medved</dc:creator>
      <dc:date>2020-11-24T09:44:16Z</dc:date>
    </item>
  </channel>
</rss>

