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: 

Bapi Return Parameter

former_member764673
Participant
0 Kudos
538

Hi,

I know that exceptions are handled in BAPI using Return parameter but i want to know how to handle this,i.e if i am calling a bapi function module and suppose it throws some errors and this will be available in Return parameter ,what is the next step , can anyone give a sample code explaining this.

Thanks & Regards,

Rajanidhi Rajasekeran

4 REPLIES 4

Former Member
0 Kudos
211

Hi Rajanidhi,

what is to be done with the entries of the return table is something that is usually dependent on the application. some applications ahve a central log maintained and some other just choose to issue the messages.

So it largely depends on the requirement what has to be done.

Refer also to this link in the documentation - http://help.sap.com/saphelp_47x200/helpdata/en/a5/3ec9f74ac011d1894e0000e829fbbd/frameset.htm.

Regards,

Anand Mandalika.

Former Member
0 Kudos
211

Hi,

Handling of BAPI return parameters depends on the BAPI in question.

In general, a message of type "E" means there has been a serious problem and the BAPI must be rolled back.

Determining if the call was successful is another matter. Some BAPIs return a success message (type "S"), others simply return nothing (i. e. an empty table). Sometimes there will be warnings and/or information messages. In my experience, you have to use trial and error.

Regards, Joerg

Former Member
0 Kudos
211

Hi Rajanidhi,

In general you can simply scan the return table. See following sample code:

REPORT Z_SAMPLE_019 .
* Sample program template 019
*
DATA: it_salesorder  TYPE BAPIACSO00 OCCURS 0,
      it_salesamount TYPE BAPIACCRSO OCCURS 0,
      it_return      TYPE BAPIRET2   OCCURS 0,
      wa_return      TYPE bapiret2.

* Do your thing to fill it_salesorder and it_salesamount
*
  ...

* Call to BAPI
*
CALL FUNCTION 'BAPI_ACC_SALES_ORDER_CHECK'
  TABLES
    salesorder  = it_salesorder
    salesamount = it_salesamount
    return      = it_return.

* Error check
*
LOOP AT it_return INTO wa_return
                 WHERE type EQ 'E'
                    OR type EQ 'A'.
*   Give message
*
    MESSAGE ID wa_return-id
          TYPE wa_return-type
        NUMBER wa_return-number
          WITH wa_return-message_v1
               wa_return-message_v2
               wa_return-message_v3
               wa_return-message_v4.
ENDLOOP.

Hope this helps you,

Regards,

Rob.

Former Member
0 Kudos
211

Hi,

What you are asking is a basic question about how to handle errors. This is always unique to the implementation. There are standards everywhere as to how one wants to handle errors. Error handling consists of a couple of things:

Who should be notified?(Users, functional, technical support etc)

When should they be notified?(batch, immediately)

How they should be notified?(Job Spool, email, paging etc)

What is the mechanism for reprocessing? Do we store the error record(s) in a file or a table or just throw it away? Do we keep them in an IDOC format or a batch input session, if those options are available for the transaction you are using?

Apart from these aspects, most BAPIs require an explicit commit after the BAPI call. So depending on the success or failure of the BAPI call you either call BAPI_COMMIT_TRANSACTION or BAPI_ROLLBACK_TRANSACTION.

Hope this helps,

Srinivas