• April 2, 2026
  • Kishore Thutaram
  • 0

ODATA Error Handling: Update HTTP Status Codes with /iwbep/cx_mgw_busi_exception

Business requirement – Update the URL status code to error when a soft error message is captured.

Example ODTA method – IWBEP/IF_MGW_APPL_SRV_RUNTIME~CREATE_DEEP_ENTITY

This is common logic for handling errors in any OData method.

Implement the code below


READ TABLE lt_log_data INTO DATA(ls_etlog) WITH KEY type = ‘E’.
        IF sy-subrc EQ 0.
*–*Process Error message by throwing an exception at gateway
          LOOP AT  lt_log_data INTO DATA(ls_log) WHERE type = ‘E’.
            lv_msgnum = ls_log-number.
            mo_context->get_message_container( )->add_message(
              EXPORTING
                iv_msg_type              =  /iwbep/cl_cos_logger=>error  ” Message Type
                iv_msg_id                =  ls_log-id       ” Message Class
                iv_msg_number            =  lv_msgnum   ” Message Number
                iv_msg_text              = ls_log-message   “Message
                iv_msg_v1                = ls_log-message_v1
                iv_msg_v2                = ls_log-message_v2
                iv_msg_v3                = ls_log-message_v3
                iv_msg_v4                = ls_log-message_v4
                iv_add_to_response_header = abap_true     “Response to the Header
            ).
          ENDLOOP.
          RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
            EXPORTING
              message_container = mo_context->get_message_container( ).

        ENDIF.
   
    

Kishore Thutaram

SAP Solution Architect | 16+ Years' Experience in SAP | Sharing Practical SAP Knowledge | Engineering Graduate with Expertise in SAP Architecture

https://fiowelt.com