Application Development and Automation 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: 
Read only

Handling errors in BAPI

Former Member
0 Likes
3,133

Hi frnds i m unable to know the answer for the q?

How do u handle errors in BAPI.

i.e i m using standard BAPI po creation if some errors occurs then how to handle those errors

how can we know the errors.

plz reply me back frnds...

thnks...

9 REPLIES 9
Read only

Former Member
0 Likes
1,433

BAPI_PO_CREATE REturns back a table "RETURN STRUCTURE" which will contain any errors occurred during execution.You can assign any table to this parameter and it should get filled in case of errors.

Read only

0 Likes
1,433

hi ravi i didnt get u...

can u make it more clear plzz...

Read only

0 Likes
1,433

Hi Sanjay,

Call BAPI like this :

data: it_retrun typa table of bapireturn.

CALL FUNCTION 'BAPI_PO_CREATE'

EXPORTING

po_header =

  • PO_HEADER_ADD_DATA =

  • HEADER_ADD_DATA_RELEVANT =

  • PO_ADDRESS =

  • SKIP_ITEMS_WITH_ERROR = 'X'

  • ITEM_ADD_DATA_RELEVANT =

  • HEADER_TECH_FIELDS =

  • IMPORTING

  • PURCHASEORDER =

tables

po_items =

  • PO_ITEM_ADD_DATA =

po_item_schedules =

  • PO_ITEM_ACCOUNT_ASSIGNMENT =

  • PO_ITEM_TEXT =

RETURN = it_return

  • PO_LIMITS =

  • PO_CONTRACT_LIMITS =

  • PO_SERVICES =

  • PO_SRV_ACCASS_VALUES =

  • PO_SERVICES_TEXT =

  • PO_BUSINESS_PARTNER =

  • EXTENSIONIN =

  • POADDRDELIVERY =

IT_RETURN will contains all message returned from BAPI. For error message you can read IT_RETURN table where type = 'E'.

Thanks

Swagatika

.

Read only

0 Likes
1,433

Hi,

please have a look at code.

data po_head type BAPIEKKOC,

it_poitem type table of BAPIEKPOC ,

it_return type table of BAPIRETURN.

CALL FUNCTION 'BAPI_PO_CREATE'

EXPORTING

PO_HEADER = po_head

  • PO_HEADER_ADD_DATA =

  • HEADER_ADD_DATA_RELEVANT =

  • PO_ADDRESS =

  • SKIP_ITEMS_WITH_ERROR = 'X'

  • ITEM_ADD_DATA_RELEVANT =

  • IMPORTING

  • PURCHASEORDER =

TABLES

PO_ITEMS = it_poitem

  • PO_ITEM_ADD_DATA =

  • PO_ITEM_SCHEDULES =

  • PO_ITEM_ACCOUNT_ASSIGNMENT =

  • PO_ITEM_TEXT =

RETURN = it_return

  • PO_LIMITS =

  • PO_CONTRACT_LIMITS =

  • PO_SERVICES =

  • PO_SRV_ACCASS_VALUES =

  • PO_SERVICES_TEXT =

  • PO_BUSINESS_PARTNER =

  • EXTENSIONIN =

  • POADDRDELIVERY =

.

IT_RETURN will have all the messages after executing the bapi.

Regards,

Rahul

Read only

Former Member
0 Likes
1,433

Hi,

BAPIs have standardized interface. Every BAPI will have a RETURN table parameter which contains all the messages that the BAPI gets while during execution.

The messages returned by each BAPI is documented very well. You can check for the RETURN parameter to find out the status of the call.

Regards,

Mustajab

Read only

Former Member
0 Likes
1,433

Hi Sanjay

While we are using the BAPIs,its not like the CALL TRANSACTION where we have to handle all the errors.

Seee i am clearing ur doubts.

BAPIs are function RFC modules where we will passing some values in the import parameters and also in table parameters.If we are passing the wrong values then it will not execute and through the errors which we can view in return parameters by seeing the error descriptions.

This is the main disadvantage of BAPI that we will not be knowing the perticular line where error occured.

Try to pass the correct values in correct format for BAPI_PO_CREATE .U can refer FM documentation for this.

Its better to pass the valus and Debugg the FM and watch where error is occuring.

Regards

Manas Ranjan Panda.

Read only

Former Member
0 Likes
1,433

Hi Sanjay,

you r using BAPI_po_create.

once look at tables interface in BAPI_po_create.

there u find RETURN like BAPIRETURN.

after calling bapi u loop at tha err_tab that of structue BAPIRETURN.

there u search for errors.


loop at itab.
at new xxx.
endat.
....
....
at end of xxx.
call functin 'bapi_po_create'.
clear flag.
loop at err_tab.
if (err_tab-type = 'E') or err_tab-type = 'W'.
flag = 'X'.
endif.

if flag is initial.
  call fuction 'BAPI_TRANSACTION_COMMIT'
                wait = 'X'.
else.
  call fuction 'BAPI_TRANSACTION_ROLLBACK'.
endif.

endat.

Read only

Former Member
0 Likes
1,433

Hi Sanjay,

you r using BAPI_po_create.

once look at tables interface in BAPI_po_create.

there u find RETURN like BAPIRETURN.

after calling bapi u loop at tha err_tab that of structue BAPIRETURN.

there u search for errors.


loop at itab.
at new xxx.
endat.
....
....
at end of xxx.
call functin 'bapi_po_create'.
clear flag.
loop at err_tab.
if (err_tab-type = 'E') or err_tab-type = 'W'.
flag = 'X'.
endif.
endloop.

if flag is initial.
  call fuction 'BAPI_TRANSACTION_COMMIT'
                wait = 'X'.
else.
  call fuction 'BAPI_TRANSACTION_ROLLBACK'.
endif.
endat.
endloop.

Read only

uwe_schieferstein
Active Contributor
0 Likes
1,433

Hello Sanjay

As several other SDN users already have said BAPIs have standardized error handling. They neve throw or raise any exception but return the corresponding messages.

If you simply want to check for success or failure you could use the following coding:

" BAPI returns single message
IF ( return-type CA 'AEX' ).
"... failure -> rollback and exit
ELSE.
"... success -> commit work
ENDIF.

"BAPI returns itab with messages
LOOP AT return TRANSPORTING NO FIELDS
               WHERE ( type CA 'AEX' ).
EXIT.
ENDLOOP.
IF ( syst-subrc = '0' ).
"... failure -> rollback and exit
ELSE.
"... success -> commit work
ENDIF.

Please note that the names of the return parameters may vary between BAPIs.

Regards

Uwe