cancel
Showing results for 
Search instead for 
Did you mean: 

How to return error msg in odata

Former Member
0 Kudos

I am passing values from Front end to odata service for creation of PM Order Confirmation . if that bapi is returning any error message how to pass those error messages to front end.

Accepted Solutions (1)

Accepted Solutions (1)

gregorw
Active Contributor

You have to check the BAPI return table for errors, add them to a message container and use that to throw the exception:

      DATA: lt_errors TYPE STANDARD TABLE OF bapiret2.

      " Collect Errors
      LOOP AT lt_return ASSIGNING FIELD-SYMBOL(<fs_return>) WHERE type = 'E'.
        APPEND <fs_return> TO lt_errors.
      ENDLOOP.


      IF lt_errors IS NOT INITIAL.
        DATA(lr_msg_cont) = /iwbep/cl_mgw_msg_container=>get_mgw_msg_container( ).


        lr_msg_cont->add_messages_from_bapi(
          EXPORTING
            it_bapi_messages          = lt_errors    " Return parameter table
        ).
        RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
          EXPORTING
            message_container = lr_msg_cont.
      ENDIF.

Andre_Fischer
Product and Topic Expert
Product and Topic Expert

It is recommended to use your own exception class that inherits from /iwbep/cx_mgw_busi_exception. This way it is more clear that your exceptions stem from your application rather than from the SAP Gateway framework.

CLASS zcx_zdx271_busi_exception DEFINITION
  PUBLIC
  INHERITING FROM /iwbep/cx_mgw_busi_exception
  FINAL
  CREATE PUBLIC .


  PUBLIC SECTION.


    METHODS constructor
      IMPORTING
        !textid                 LIKE if_t100_message=>t100key OPTIONAL
        !previous               LIKE previous OPTIONAL
        !message_container      TYPE REF TO /iwbep/if_message_container OPTIONAL
        !http_status_code       TYPE /iwbep/mgw_http_status_code DEFAULT gcs_http_status_codes-bad_request
        !http_header_parameters TYPE /iwbep/t_mgw_name_value_pair OPTIONAL
        !sap_note_id            TYPE /iwbep/mgw_sap_note_id OPTIONAL
        !msg_code               TYPE string OPTIONAL
        !entity_type            TYPE string OPTIONAL
        !message                TYPE bapi_msg OPTIONAL
        !message_unlimited      TYPE string OPTIONAL
        !filter_param           TYPE string OPTIONAL
        !operation_no           TYPE i OPTIONAL .
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.






CLASS zcx_zdx271_busi_exception IMPLEMENTATION.




  METHOD constructor 
    CALL METHOD super->constructor
      EXPORTING
        previous               = previous
        message_container      = message_container
        http_status_code       = http_status_code
        http_header_parameters = http_header_parameters
        sap_note_id            = sap_note_id
        msg_code               = msg_code
        entity_type            = entity_type
        message                = message
        message_unlimited      = message_unlimited
        filter_param           = filter_param
        operation_no           = operation_no.
    CLEAR me->textid.
    IF textid IS INITIAL.
      if_t100_message~t100key = if_t100_message=>default_textid.
    ELSE.
      if_t100_message~t100key = textid.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

former_member185414
Active Contributor
0 Kudos

To further augment Andre's saying an example can be found here

0 Kudos

andre.fischer

As per my experiment this cannot be implemented in RAP programming .

When we are using IF_RAP_QUERY_PROVIDER (not behavior implementation ) .

I mean when we are using the below way of implementing RAP in BTP ,

Whenever we use /iwbep/cl_mgw_msg_container it says , usage is not allowed .

Is my understanding right

Answers (0)