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: 

error handling in bapi

Former Member
0 Kudos

Hi

how to handles the errors in bapi function modules asa compared to normal function modules

thanks,

kiran.M

5 REPLIES 5

Manohar2u
Active Contributor
0 Kudos

Normally BAPI's will retun you an internal table with RETURN table, which will have the list of message it encountered while processing the BAPI.

Then you need to loop at that internal table to build the messages, you can use messagetextbuild FM to build the messages.

Regds

Manohar

Former Member
0 Kudos

Hi,

Normally u avoid exceptions in BAPI.

Use internal table ; Populate the error if any and return the internal table.

<b>BAPI-step by step</b>

http://www.sapgenie.com/abap/bapi/example.htm

http://www.sappoint.com/abap/bapiintro.pdf

0 Kudos

EXample for error handling in bapi.

Bapi :- BAPI_0035_CHANGE

Tables :- RETURN

Return is a internal table which returns error .

Structure of return table ( BAPIRET2 ).

TYPE

ID

NUMBER

MESSAGE

LOG_NO

LOG_MSG_NO

MESSAGE_V1

MESSAGE_V2

MESSAGE_V3

MESSAGE_V4

PARAMETER

ROW

FIELD

SYSTEM

u append the error in this table.

look at the structure ( BAPIRET2 ) for detail.

Former Member
0 Kudos

Hi Kiran,

There is no explicit condition or any BAPI or FM to handle the errors. It has to be done manually, the same procedure we use in BDC programs after CALL TRNSACTION and getting the messages into the Internal Table.

Assume I am using <b>BAPI_QUOTATION_CREATEFROMDATA2</b> for creating quotations(Transaction VA21).

I called the BAPI and got the following error messges in my <b>RETURN</b> table.


<b>TYPE |ID                  | NUMBER| MESSAGE</b>
E   |VP                  |112   |Please enter sold-to party or ship-to party
E   |V4                  |219   |Sales document  was not changed     

So based on this you have to determine your error handling.

Something like this after calling the BAPI.


  READ TABLE return WITH KEY id     = 'VP'
                             number = '112'.
  IF sy-subrc  = 0.

* Your error handling

  ENDIF.

You can use the BAPI_MESSAGE_GETDETAIL to get the detailed error messages. Refer to the table T100 for exporting parameters.

Regards,

Arun Sambargi.

Former Member
0 Kudos

Hi,

All BAPIs contains Return table as table parameter. This table is populated with error messages/Sucessful messages after BAPI was executed.

Please check this table for any error messages.

Regards,

Ganesh