cancel
Showing results for 
Search instead for 
Did you mean: 

how to capture Exception error message in Odata ?

velsankar_sundar
Participant
0 Kudos

Hi,

  I am new to sap gateway. Currently i am creating a Odata Service through the transaction SEGW. In the query i have mapped a RFC. When i execute the service sometimes the RFC throws exception like 'No data Found'. But i dont know how to capture the exception returned from the RFC.

I read some threads which says use

RAISE EXCEPTION TYPE /IWBEP/CX_MGW_BUSI_EXCEPTION

      EXPORTING
        textid            = /iwbep/cx_mgw_busi_exception=>business_error
        message       lv_text
        message_container = io_message_container.



My doubt is since i have not done any code in the DPC method. As said in many threads should i go to DPC_EXT method and redefine the method or how to capture the exception.


Kindly advise. Thanks in advance

Accepted Solutions (1)

Accepted Solutions (1)

AshwinDutt
Active Contributor

Hello Velsankar,


You need not to capture the error messages explicitly by writing custom code in you DPC_EXT if you are using service builder when the return error message table is of type BAPIRET2.

GW itself will handle and return the error messages.

If at all the return error message table is of different type , i mean to say if it is not of type BAPIRET2 then you need to capture explicitly.

The below is the code you need to write in DPC_EXT to capture.

DATA: LO_MECO TYPE REF TO /IWBEP/IF_MESSAGE_CONTAINER.

DATA: LX_BUSI_EXC TYPE REF TO /IWBEP/CX_MGW_BUSI_EXCEPTION.

        LO_MECO = MO_CONTEXT->GET_MESSAGE_CONTAINER( ).

         LO_MECO->ADD_MESSAGES_FROM_BAPI( IT_BAPI_MESSAGES = LT_ERR_RET_TAB ).

         CREATE OBJECT LX_BUSI_EXC

           EXPORTING

             MESSAGE_CONTAINER = LO_MECO.

         RAISE EXCEPTION LX_BUSI_EXC.


Note : where LT_ERR_RET_TAB is your internal table where you would have captured all the error messages.


That is it. You will be able to see the messages .


Regards,

Ashwin

velsankar_sundar
Participant
0 Kudos

Thanks guys . it is working

chauhanmadhav17
Explorer
0 Kudos

In which method of DPC_EXT class, we have to write the above code.?

Answers (3)

Answers (3)

0 Kudos

Hi,

You need not to capture the messages explicitly by writing custom code in you DPC_EXT class, refer below code,

login page example,

"" Message container declaration.
DATA: LO_MESSAGE_CONTAINER TYPE REF TO /IWBEP/IF_MESSAGE_CONTAINER.

""If login successful, success message will be displayed.

IF ER_ENTITY IS NOT INITIAL.
CALL METHOD ME->/IWBEP/IF_MGW_CONV_SRV_RUNTIME~GET_MESSAGE_CONTAINER
RECEIVING
RO_MESSAGE_CONTAINER = LO_MESSAGE_CONTAINER. " Message Container Interface

CALL METHOD LO_MESSAGE_CONTAINER->ADD_MESSAGE
EXPORTING
IV_MSG_TYPE = /IWBEP/CL_COS_LOGGER=>SUCCESS " Message Type
IV_MSG_ID = 'ZVIT_LOGIN' " Message Class
IV_MSG_NUMBER = '001' " Message Number
IV_ADD_TO_RESPONSE_HEADER = ABAP_TRUE. " Flag for adding or not the message to the response header

""""""If login failed error message will displayed.
ELSE.

CALL METHOD ME->/IWBEP/IF_MGW_CONV_SRV_RUNTIME~GET_MESSAGE_CONTAINER
RECEIVING
RO_MESSAGE_CONTAINER = LO_MESSAGE_CONTAINER. " Message Container Interface

CALL METHOD LO_MESSAGE_CONTAINER->ADD_MESSAGE
EXPORTING
IV_MSG_TYPE = /IWBEP/CL_COS_LOGGER=>ERROR " Message Type
IV_MSG_ID = 'ZVIT_LOGIN' " Message Class
IV_MSG_NUMBER = '002' " Message Number
IV_ADD_TO_RESPONSE_HEADER = ABAP_TRUE. " Flag for adding or not the message to the response header
ENDIF.

former_member195242
Active Participant
0 Kudos

Hi Velsankar,

If you want to handle something which has not been done in the generated DPC class, then you can go to DPC_EXT class, redefine and copy the whole implementation that was in DPC and modify/change what you need to.

Best regards,

Aakash

ChandraMahajan
Active Contributor
0 Kudos

Hi,

refer this thread

refer my blog which help you understand how to write code in DPC_EXT class methods.

Regards,

Chandra