4 Replies Latest reply: Sep 12, 2009 11:40 PM by Sandeep Poddar RSS

How to handle exceptions in BAPI's and RFC

Digvijay Sharma
Currently Being Moderated

Hi! Gurus,

 

 

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

 

 

regards,

Digvijay

  • Re: How to handle exceptions in BAPI's and RFC
    Shital Phadake
    Currently Being Moderated

    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.
    

     

  • Re: How to handle exceptions in BAPI's and RFC
    Currently Being Moderated

    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

    • Re: How to handle exceptions in BAPI's and RFC
      JAGAN MOHAN
      Currently Being Moderated

      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.

  • Re: How to handle exceptions in BAPI's and RFC
    Sandeep Poddar
    Currently Being Moderated
    • 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

Actions