Skip to Content
0
Oct 02, 2016 at 01:45 PM

Bapi to update field in purchase requisition

2787 Views

Hi experts,

I have developed program to update field EBAKZ in purchase requisition by using BAPI but uable to update.The code which i have written is as below.Kindly do the needful .

DATA : LT_EBAN TYPE STANDARD TABLE OF EBAN.
FIELD-SYMBOLS <FS_EBAN> TYPE EBAN.
DATA : LW_ORDER TYPE TY_EBAN,
LT_ORDER TYPE STANDARD TABLE OF TY_EBAN,
LW_ITEM TYPE BAPIMEREQITEM,
LW_ITEMX TYPE BAPIMEREQITEMX,
LT_ITEM TYPE STANDARD TABLE OF BAPIMEREQITEM,
LT_ITEMX TYPE STANDARD TABLE OF BAPIMEREQITEMX,
LW_HEADERX TYPE BAPIMEREQHEADERX ,
LW_HEADER TYPE BAPIMEREQHEADER,
LW_RET TYPE BAPIRET2,
* ty_try type bapiebanv,
LT_RET TYPE STANDARD TABLE OF BAPIRET2.

LT_ORDER[] = IT_EBAN[].
SORT LT_ORDER BY BANFN ASCENDING.
DELETE ADJACENT DUPLICATES FROM LT_ORDER
COMPARING BANFN.

LW_HEADERX-PARK_COMPLETE = 'X'.
LOOP AT LT_ORDER INTO LW_ORDER.
CLEAR WA_FINAL.
MOVE-CORRESPONDING LW_ORDER TO WA_FINAL.
REFRESH : LT_ITEM,LT_ITEMX."LT_TEXT.

LOOP AT IT_EBAN INTO WA_EBAN
WHERE BANFN = LW_ORDER-BANFN.

READ TABLE IT_FILE INTO WA_FILE
WITH KEY BANFN = WA_EBAN-BANFN
BNFPO = WA_EBAN-BNFPO.

CLEAR LW_ITEM.
LW_ITEM-PREQ_ITEM = WA_EBAN-BNFPO.
LW_ITEM-CLOSED = WA_FILE-EBAKZ.
APPEND LW_ITEM TO LT_ITEM.

CLEAR LW_ITEM.
LW_ITEMX-PREQ_ITEM = WA_EBAN-BNFPO.
* LW_ITEMX-PARK_COMPLETE = 'X'.
LW_ITEMX-CLOSED = 'X'.
APPEND LW_ITEMX TO LT_ITEMX.

ENDLOOP.

CALL FUNCTION 'BAPI_PR_CHANGE' "Change Enjoy Purchase Requisition
EXPORTING
number = lw_order-banfn
prheader = lw_header
prheaderx = lw_headerx
* testrun =
* IMPORTING
* prheaderexp =
TABLES
return = lt_ret "
pritem = lt_item
pritemx = lt_itemx.

READ TABLE LT_RET INTO LW_RET WITH KEY TYPE = 'S'
NUMBER = '311'.


IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
* IMPORTING
* RETURN =

WA_FINAL-STATUS = LW_RET-MESSAGE.
ELSE.
READ TABLE LT_RET INTO LW_RET WITH KEY TYPE = 'E'.
IF SY-SUBRC = 0.
WA_FINAL-STATUS = LW_RET-MESSAGE.
ENDIF.
ENDIF.
LOOP AT IT_EBAN INTO WA_EBAN
WHERE BANFN = WA_FINAL-BANFN.
MOVE-CORRESPONDING WA_EBAN TO WA_FINAL.
READ TABLE IT_FILE INTO WA_FILE
WITH KEY BANFN = WA_EBAN-BANFN
BNFPO = WA_EBAN-BNFPO.
IF SY-SUBRC = 0.
WA_FINAL-EBAKZ = WA_FILE-EBAKZ.
ENDIF.
APPEND WA_FINAL TO IT_FINAL.
ENDLOOP.

ENDLOOP.