TABLES : ekko,ekpo,marc.
DATA : BEGIN OF itab OCCURS 0,
aedat TYPE erdat,
lifnr TYPE lifnr,
emlif TYPE emlif,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
menge TYPE menge_d, "po qty
wemng TYPE menge_d, "gr qty
END OF itab.
DATA : stab LIKE itab.
DATA : gv_purchaseorder LIKE ekko-ebeln. "Purchase order
DATA : gs_poheader LIKE bapimepoheader, "Header Data
gs_poheaderx LIKE bapimepoheaderx, "Header Data(Change Toolbar)
gt_poitem LIKE bapimepoitem OCCURS 0 WITH HEADER LINE,
gt_poitemx LIKE bapimepoitemx OCCURS 0 WITH HEADER LINE,
gt_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
gs_expheader LIKE bapimepoheader. "Header Data(Return)
CLEAR itab[].
SELECT ekko~aedat AS aedat
ekko~lifnr AS lifnr
ekpo~emlif AS emlif
ekpo~ebeln AS ebeln
ekpo~ebelp AS ebelp
eket~menge AS menge
eket~wemng AS wemng
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ekko
INNER JOIN ekpo
ON ekko~ebeln = ekpo~ebeln
INNER JOIN eket
ON ekpo~ebeln = eket~ebeln
AND ekpo~ebelp = eket~ebelp
WHERE ekko~bstyp = 'F'
AND ekko~loekz = ''
AND ekpo~loekz = ''
AND ekpo~elikz = ''
AND ekpo~lblkz = 'X'
AND ekko~lifnr = '001000772'
AND ekpo~werks = '1000'
AND eket~wemng = 0
AND ekko~lifnr = ( SELECT po~emlif
FROM ekpo AS po
WHERE po~ebeln = ekpo~ebeln
AND po~ebelp = ekpo~ebelp ).
IF itab[] IS INITIAL.
MESSAGE s899(mm) WITH 'no data found'.
LEAVE LIST-PROCESSING.
ENDIF.
SORT itab BY aedat lifnr ebeln ebelp.
LOOP AT itab.
MOVE-CORRESPONDING itab TO stab.
AT NEW ebeln.
CLEAR : gv_purchaseorder, gs_poheader, gs_poheaderx.
gv_purchaseorder = stab-ebeln.
gs_poheader-po_number = stab-ebeln.
gs_poheaderx-po_number = 'X'.
ENDAT.
gt_poitem-po_item = stab-ebelp.
gt_poitem-delete_ind = 'L'.
APPEND gt_poitem.
gt_poitemx-po_item = stab-ebelp.
gt_poitemx-po_itemx = 'X'.
gt_poitemx-delete_ind = 'X'.
APPEND gt_poitemx.
AT END OF ebeln.
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
purchaseorder = gv_purchaseorder
poheader = gs_poheader
poheaderx = gs_poheaderx
IMPORTING
expheader = gs_expheader
TABLES
return = gt_return
poitem = gt_poitem
poitemx = gt_poitemx.
READ TABLE gt_return WITH KEY type = 'S' number = '023'.
IF sy-subrc IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
CLEAR : gv_purchaseorder,
gs_expheader,
gs_poheader,
gs_poheaderx,
gt_poitem[],
gt_poitemx[],
gt_return[].
ENDAT.
ENDLOOP.
와우~ 정말 도움 많이 됐어요. 감사합니당 ^^