Skip to Content
Technical Articles

ABAP Exception Class ZCX_RETURN3 – Catch code templates

This blog post contains code templates for quickly adding code for catching ZCX_RETURN3 exceptions.

For more information on exception class ZCX_RETURN3, see blog post:
https://blogs.sap.com/2020/06/01/abap-exception-class-zcx_return3/

Overview

ZEXC_CATCH_OO – Catch in OO method

    TRY.

        "Execute methods
        "...

        "Commit
        "zca_db_transaction->commit( ).

      CATCH zcx_return3 INTO DATA(lx_return).

        "zca_db_transaction->roll_back( ).

        "Handle exception lx_return
        RAISE EXCEPTION lx_return.

    ENDTRY.

 

ZEXC_CATCH_GATEWAY – Catch in SAP Gateway (SEGW)

    TRY.

        "...instiantiate object and call methods

        "Commit work (if needed)
        "zca_db_transaction->commit( ).

      CATCH zcx_return3 INTO DATA(lx_return).

        "Roll back (if needed)
        "zca_db_transaction->rollback( ).

        "Handle exception
        DATA(ls_return) = lx_return->get_bapiret2_struc( ).

        DATA(ls_message) = VALUE scx_t100key(
          msgid = ls_return-id
          msgno = ls_return-number
          attr1 = ls_return-message_v1
          attr2 = ls_return-message_v2
          attr3 = ls_return-message_v3
          attr4 = ls_return-message_v4 ).

        RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
          EXPORTING
            textid = ls_message.

    ENDTRY.

ZEXC_CATCH_ABAP_PROX – Catch in ABAP Proxy

    TRY.

        "...

        "Commit work (if needed)
        "zca_db_transaction->commit( ).

      CATCH zcx_return3 INTO DATA(lx_return).

        "Roll back (if needed)
        "zca_db_transaction->rollback( ).

        "Fill proxy exception message
        DATA(lt_bapiret2) = lx_return->get_bapiret2_table( ).

        cl_proxy_fault=>raise(
          EXPORTING
            exception_class_name = 'ZWMSCX_EXCHANGE_FAULT3'  "Change
            bapireturn_tab       = lt_bapiret2 ).

    ENDTRY.

ZEXC_CATCH_RFC – Catch in RFC Function Module

    TRY.

        "...instiantiate object and call methods

        "Commit work (if needed)
        "zca_db_transaction->commit( ).

      CATCH zcx_return3 INTO DATA(lx_return).

        "Roll back (if needed)
        "zca_db_transaction->rollback( ).

        DATA(ls_return) = lx_return->get_bapiret2_struc( ).

        MESSAGE
          ID      ls_return-id
          TYPE    ls_return-type
          NUMBER  ls_return-number
          RAISING error
          WITH    ls_return-message_v1
                  ls_return-message_v2
                  ls_return-message_v3
                  ls_return-message_v4.

    ENDTRY.

ZEXC_CATCH_BAPI – Catch in BAPI

    TRY.

        "...

        "Commit work (if needed)
        "zca_db_transaction->commit( ).

      CATCH zcx_return3 INTO DATA(lx_return).

        "Roll back (if needed)
        "zca_db_transaction->rollback( ).

        "Fill return table
        et_return = lx_return->get_bapiret2_table( ).

    ENDTRY.

ZEXC_CATCH_MESSAGE – Catch, raise by MESSAGE statement

    TRY.

        "...

      CATCH zcx_return3 INTO DATA(lx_return).

        DATA(ls_return) = lx_return->get_bapiret2_struc( ).

        MESSAGE
          ID      ls_return-id
          TYPE    ls_return-type
          NUMBER  ls_return-number
          WITH    ls_return-message_v1
                  ls_return-message_v2
                  ls_return-message_v3
                  ls_return-message_v4.

    ENDTRY.

ZEXC_CATCH_OLD_RETUR – Convert old RETURN exception to new RETURN exception

    TRY.

        "...

      CATCH zcx_return3 INTO DATA(lx_return_old). "TODO: rename zcx_return3

        DATA(lx_return) = NEW zcx_return3( ).
        lx_return->add_bapiret2_table(
          lx_return_old->get_bapiret2_table( )  ).

        RAISE EXCEPTION lx_return.

    ENDTRY.
Be the first to leave a comment
You must be Logged on to comment or reply to a post.