ERPClimb logoERPClimb
OData Gateway
Architect / Cross-trackadvanced 9 min read

OData Gateway Part 9: Error Handling and the Message Container

Preview · a free account unlocks the full lesson

Key takeaway

Return meaningful errors from Gateway services: business vs technical exceptions and their HTTP status codes, the message container for BAPI and T100 messages, leading messages and error details, success and warning messages in the sap-message header, and what Fiori shows to the user.

In this lessonShow sections

Visual overview

OData Gateway Part 9: Error Handling and the Message Container — learning sheetFlow: Create message class ZSALES with messages for validation errors → In CREATE_ENTITY, call a BAPI and pass its RETURN to the container on error → On success, add a success message to the response header → Test in /IWFND/GW_CLIENT: look at the response body and the sap-message header. Key ideas: EXCEPTION TYPES; MESSAGE CONTAINER; RESPONSE STRUCTURE (JSON); SUCCESS AND WARNING MESSAGES. Watch out: Swallowing BAPI errors (ignoring RETURN) or raising a generic "Error occurred" makes the app useless to users and support — always pass the real message through.ERPClimb.com / ARCH / LESSON 9/10 / LEARNING SHEETOData Gateway Part 9: Error Handling and the MessageContainer1 · HOW IT FLOWS1Create messageclass ZSALESwith messages…2InCREATE_ENTITY,call a BAPI and…3On success, adda successmessage to the…4Test in/IWFND/GW_CLIENTlook at the responsebody and the sap-message…2 · KEY IDEAS EXPLAINEDException TypesBusiness: validation failed, record locked, notfound (textid resource_not_found → 404), noauthorization.Technical: unexpected state, RFC failure,programming errors.Message Containerlo_msg = mo_context->get_message_container( ).add_messages_from_bapi( it_bapi_messages =lt_return … ) — all BAPIRET2 lines.Response Structure (JSON)error.code (message class/number),error.message.value (leading text),error.innererror.errordetails[] (all messages with…Fiori shows the leading message and details in themessage popover.Success And Warning MessagesAdd messages with iv_add_to_response_header =abap_true and do not raise; they appear in thesap-message header.Example: "Order 4711 saved" or"Credit limit almost reached".3 · REMEMBER · WATCH OUTRemember/IWBEP/CX_MGW_BUSI_EXCEPTION = business error the user can fix(default HTTP 400); /IWBEP/CX_MGW_TECH_EXCEPTION = technical failure…The message container (mo_context->get_message_container( ))collects T100/BAPI messages; raising the exception with…Success and warning messages without an error can be sent in thesap-message HTTP header (iv_add_to_response_header = abap_true); Fiori…!Watch outSwallowing BAPI errors (ignoringRETURN) or raising a generic"Error occurred" makes theapp useless to users and support —always pass the real messagethrough.4 · IN A REAL PROJECTUsers of a Fiori order app saw only "An error occurred" when saving. Support had to reproduce everycase in VA01 to find the reason, typically a missing partner function or blocked material. The DPC_EXT codechecked RETURN but raised a busi exception with a fixed text. The developer replaced it with…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 8 covered changing data; now errors need to reach the user clearly. /IWBEP/CX_MGW_BUSI_EXCEPTION represents a business error the user can actually fix, defaulting to HTTP 400, while /IWBEP/CX_MGW_TECH_EXCEPTION represents a technical failure, defaulting to HTTP 500.

Business exceptions cover things like a failed validation, a locked record, a record not found (using textid resource_not_found, which maps to 404), or missing authorization, while technical exceptions cover unexpected states, RFC failures, and programming errors; either can take an optional http_status_code parameter to set something more specific, such as 409 for conflict or 403 for forbidden.

The message container, obtained via mo_context->get_message_container( ), collects messages from T100 or BAPI sources: add_messages_from_bapi( it_bapi_messages = lt_return ... ) takes all the BAPIRET2 lines, add_message( iv_msg_type, iv_msg_id, iv_msg_number, iv_msg_v1 ... ) adds a specific T100 message, and add_message_text_only( iv_msg_type = 'E' iv_msg_text = ... ) adds free text. Raising the exception together with this message container returns the messages as error details in the response; the first or most important error becomes the leading message, with the rest going into innererror/errordetails.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

Keep exploring

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.