Skip to Content

How to return error msg in odata

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    May 04 at 09:10 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded