Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to handle exceptions in BAPI's and RFC

Former Member
0 Kudos

Hi! Gurus,

Please help me why we cant raise exceptions in RFC or Badi and hw to handle them further..

regards,

Digvijay

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You can handle the exceptions by using a structure BAPIE1RET2 which returns the messages captured in BAPI. In Tables parameter of your BAPI, you can create a structure as of type BAPIE1RET2 so that you can capture the return parameters from BAPI.

Thanks and Regards,

Vimala P

4 REPLIES 4

Former Member
0 Kudos

while defining the exceptions you have to add them under 'Exception" tab in SE37.

In code you need to raise the exception on specific condition.

You will handle this exception once its returned in FM call


    CALL FUNCTION 'Z_FM_NAME'
      EXPORTING
         f_objid                    = p0001-orgeh
              = '01'
      IMPORTING
         f_hco_id                   = int_hist-comp
      EXCEPTIONS
         error_obj_org_not_found    = 1
         error_invalid_org          = 2
         error_parent_org_not_found = 3
         OTHERS                     = 4.

Former Member
0 Kudos

Hi,

You can handle the exceptions by using a structure BAPIE1RET2 which returns the messages captured in BAPI. In Tables parameter of your BAPI, you can create a structure as of type BAPIE1RET2 so that you can capture the return parameters from BAPI.

Thanks and Regards,

Vimala P

0 Kudos

Hi,

to handle the Exceptions,

1. You have to declare the exceptions in Exceptions section in SE37.

2. Use Raise statement to raise the exception When the particular condition reached.

Eg: when you are dividing A with B,

if B = 0.

Raise B_Zero [With message I001(ZZZ)]

endif.

3. When you call this function module you have to assign some value in exceptions section.

Eg: Call function 'ZDIVIDE'

exporting

a = a

b = b

importing

result = r

exceptions

B_Zero = 1

others = 99.

4. If you dont specify message extension in Raise statement, then you should use the code like this

if Sy-subrc = 1.

message E001(00) with 'Should not divide with zero'.

endif.

Regards,

Jagan.

Former Member
0 Kudos
  • Why can't we use exceptions in BAPI and RFC ?

The reason is that raising exceptions is a feature handled by SAP internally. When dealing with RFCs and BAPIs, you have to keep in mind that these are used by external applications also, which cannot handle exceptions raised in SAP.

That is the reason you need to return the messages in RETURN parameter, which can be a table (for multiple messages) or a structure.

Cheers!!!

Sandeep