Exception handing in OData
SAP provided below 2 Interfaces and 2 Classes to handle the exceptions in OData.
/IWBEP/IF_MESSAGE_CONTAINER
/IWBEP/IF_MGW_CONTEXT
/IWBEP/CX_MGW_BUSI_EXCEPTION
/IWBEP/CX_MGW_TECH_EXCEPTION
/IWBEP/IF_MGW_CONTEXT
/IWBEP/CX_MGW_BUSI_EXCEPTION
/IWBEP/CX_MGW_TECH_EXCEPTION
Example:
DATA(lo_msg_container) = mo_context->get_message_container( ).
SELECT SINGLE * FROM qals INTO @DATA(ls_qals) WHERE prueflos EQ @iv_prueflos.
IF sy-subrc NE 0.
SELECT SINGLE * FROM qals INTO @DATA(ls_qals) WHERE prueflos EQ @iv_prueflos.
IF sy-subrc NE 0.
METOD 1: Just raise an exception but don't handle it (no parameters)
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception.
The output will be as follows:
Method 2: Using Message Container
raising and handling the exceptions using the interface reference as importing parameter.
lo_msg_container->add_message_text_only(
EXPORTING
iv_msg_type = 'E'
iv_msg_text = |Inspection Lot { iv_prueflos } is invalid| ).
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
EXPORTING
message_container = lo_msg_container.
ENDIF.
lo_msg_container->add_message_text_only(
EXPORTING
iv_msg_type = 'E'
iv_msg_text = |Inspection Lot { iv_prueflos } is invalid| ).
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
EXPORTING
message_container = lo_msg_container.
ENDIF.
Method 3: BUSINESS_ERROR
Raising and handling the exception using constructor parameters
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
EXPORTING
textid = /iwbep/cx_mgw_busi_exception=>business_error
message = |Not authorized to access the data|.
EXPORTING
textid = /iwbep/cx_mgw_busi_exception=>business_error
message = |Not authorized to access the data|.
Method 4: Textid using /iwbep/cx_mgw_tech_exception class
RAISE EXCEPTION TYPE /iwbep/cx_mgw_tech_exception
EXPORTING
textid = /iwbep/cx_mgw_busi_exception=>business_error .
EXPORTING
textid = /iwbep/cx_mgw_busi_exception=>business_error .
Comments
Post a Comment