cancel
Showing results for 
Search instead for 
Did you mean: 

How to raise business exception, /IWBEP/CX_MGW_BUSI_EXCEPTION?

Former Member
0 Kudos

I have to rasie exception /IWBEP/CX_MGW_BUSI_EXCEPTION within a backend method, which will be called by the GET_ENTITY method.

I have caught the exception into a reference LR_BUSINESS_EXCEPTION.

lr_exception is the importing parameter for the backend method called.

Should I use the following code

Or should I raise the exceptionas per the below code

In this case how should I populate IIO_MESSAGE_CONTAINER based on the reference LR_BUSINESS_EXCEPTION.

Please advice.

Accepted Solutions (0)

Answers (3)

Answers (3)

prabhu_04
Explorer
0 Kudos

Hi,

Just you have to raise the Business Exception

  MO_CONTEXT->GET_MESSAGE_CONTAINER( )->ADD_MESSAGE(
  exporting
    IV_MSG_TYPE               =  /iwbep/cl_cos_logger=>WARNING   " Message Type
    IV_MSG_ID                 =  ' '   " Message Class
    IV_MSG_NUMBER             =  ' '   " Message Number
    IV_ADD_TO_RESPONSE_HEADER = ABAP_TRUE     "Response to the Header
).

RAISE EXCEPTION TYPE /IWBEP/CX_MGW_BUSI_EXCEPTION
  exporting
    MESSAGE_CONTAINER      = MO_CONTEXT->GET_MESSAGE_CONTAINER( ).
kammaje_cis
Active Contributor
0 Kudos

Vivek,

Exceptions should not be used as import/export parameters. Business exception will be caught by the Gateway framework and the error message within it will be displayed. You just have to raise the Business exception.

regards

Krishna

Former Member
0 Kudos

Hi,

Besides raising the exception i had to sent a mail based on the exception.

So I addded both in a single method and called the method in alll my service implementations.

with reference variable of type cx_root as the inmporting parameter.


Regards,

Vivek.

AshwinDutt
Active Contributor
0 Kudos

Hello Vivek,

To return a message ->

lo_message_container  TYPE REF TO /iwbep/if_message_container.

lo_message_container = mo_context->get_message_container( ).

   IF lt_error_out[] IS INITIAL.
        lv_msg_text = 'Sales Order not found.'.
        CALL METHOD lo_message_container->add_message_text_only
          EXPORTING
            iv_msg_type = 'E'
            iv_msg_text = lv_msg_text.

        RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
          EXPORTING
            message_container = lo_message_container.
    ENDIF.

Please check the below which will help you to return back table of messages which comes from Back End.

Regards,

Ashwin

Former Member
0 Kudos

I did check this, its case in whcih we get the error messages as table of BAPIRETURN2.

Vivek.

Former Member
0 Kudos

This method is generic ,and I cannot hardcode messages as mentioned in your code.

The exception raised by a backend method will be caught into lr_business_exception.

Can I go with the first method mentioned in my post.

AshwinDutt
Active Contributor
0 Kudos

If the error/message table which returned by your FM is of type BAPIRET2 then you can directly send as below :

Here BAPIRET2 is the standard structure which will be available and that is the reason we can send directly send as below.


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.


where LT_ERR_RET_TAB is your internal table where you would have captured all the error messages and which is of type BAPIRET2.


If the error/message table which returned by your FM is not of type BAPIRET2 ( i.e., custom error table ) then you cannot directly send as shown above.


Your custom error table is not a standard and will not be available in all the systems and hence you need to send back table of messages in a table which is of type BAPIRET2.


You need to get all the necessary details from the custom error table returned by your FM and then populate to a internal table which is of type BAPIRET2 and then send as shown above.


Regards,

Ashwin

AshwinDutt
Active Contributor
0 Kudos

I am not suggesting to hard code the error message.

Its just a code snippet for your reference.