cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI_PO_CHANGE trapping erros

Former Member
0 Kudos

I am calling the BAPI_PO_CHANGE to change the NO_MORE_GR indicator via an ABAP program. After calling the BAPI I would like to trap the error before calling the BAPI_TRANSACTION_COMMIT. Please see code snippet below. When testing the BAPI via the testing module (/nbapi) the return entries show errors but when calling via ABAP the SY-SUBRC always returns a 0. I would like to know if there are other ways of trapping such errors rather than depending on SY-SUBRC.

FORM updatepoitem.

DATA: test TYPE bapiflag-bapiflag,

po_item TYPE TABLE OF bapimepoitem WITH HEADER LINE,

po_itemx TYPE TABLE OF bapimepoitemx WITH HEADER LINE.

DATA:i_msg LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

LOOP AT itab_sel INTO wa_itab .

*Clear the tables.

CLEAR: po_item, po_itemx, t_bapireturn.

REFRESH: po_item, po_itemx, t_bapireturn.

MOVE wa_itab-ebelp TO po_item-po_item.

MOVE wa_itab-ebelp TO po_itemx-po_item.

MOVE 'X' TO po_itemx-no_more_gr.

MOVE 'X' TO po_item-no_more_gr.

APPEND po_item.

APPEND po_itemx.

CALL FUNCTION 'BAPI_PO_CHANGE'

EXPORTING

purchaseorder = wa_itab-ebeln

TABLES

poitem = po_item

poitemx = po_itemx.

IF sy-subrc EQ 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

ENDIF.

ENDLOOP.

ENDFORM.

Many Thanks

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Problem resolved.

Former Member
0 Kudos

The BAPI BAPI_PO_CHANGE has a return table which will return the errors . So before calling the commit bapi , move the retun table into another internal table .

On this internal table write a condition , that if there are not Errors i.e there is no message type E , then call the commit BAPI.

-Hari.

Former Member
0 Kudos

Thanks Hari. I've tried this and it works. Excellent