ABAP顾问
分类:
2010-11-02 20:36:42
REPORT z_barry_test LINE-SIZE 140 NO STANDARD PAGE HEADING .
DATA :return TYPE bapiret2 OCCURS 0 WITH HEADER LINE,
poschedule TYPE bapimeposchedule OCCURS 0 WITH HEADER LINE,
poschedulex TYPE bapimeposchedulx OCCURS 0 WITH HEADER LINE,
pocomponents LIKE bapimepocomponent OCCURS 0 WITH HEADER LINE,
pocomponentsx LIKE bapimepocomponentx OCCURS 0 WITH HEADER LINE.
PARAMETERS p_ebeln LIKE ekko-ebeln.
START-OF-SELECTION.
CALL FUNCTION 'BAPI_PO_GETDETAIL1'
EXPORTING
purchaseorder = p_ebeln
TABLES
return = return
pocomponents = pocomponents
poschedule = poschedule.
READ TABLE poschedule INDEX 1.
CLEAR poschedule[].
poschedule-quantity = poschedule-quantity - 1 .
APPEND poschedule.
poschedulex-po_item = poschedule-po_item.
poschedulex-sched_line = poschedule-sched_line .
poschedulex-quantity = 'X'.
APPEND poschedulex TO poschedulex.
READ TABLE pocomponents WITH KEY po_item = poschedule-po_item
sched_line = poschedule-sched_line.
DELETE pocomponents WHERE po_item = poschedule-po_item AND
sched_line = poschedule-sched_line .
pocomponents-entry_quantity = pocomponents-entry_quantity - 1 .
pocomponents-change_id = 'U'.
APPEND pocomponents .
pocomponentsx-po_item = pocomponents-po_item .
pocomponentsx-sched_line = pocomponents-sched_line .
pocomponentsx-item_no = pocomponents-item_no .
pocomponentsx-entry_quantity = 'X'.
pocomponentsx-change_id = 'X'.
APPEND pocomponentsx.
poschedule-sched_line = poschedule-sched_line + 1 .
poschedule-delivery_date = '2010.11.11'.
poschedule-quantity = 1.
APPEND poschedule.
poschedulex-po_item = poschedule-po_item.
poschedulex-sched_line = poschedule-sched_line .
poschedulex-quantity = 'X'.
poschedulex-delivery_date = 'X'.
APPEND poschedulex TO poschedulex.
READ TABLE pocomponents WITH KEY po_item = poschedule-po_item
sched_line = poschedule-sched_line.
DELETE pocomponents WHERE po_item = poschedule-po_item AND
sched_line = poschedule-sched_line .
pocomponents-entry_quantity = 1 .
pocomponents-sched_line = pocomponents-sched_line + 1 .
pocomponents-change_id = 'I'.
APPEND pocomponents .
pocomponentsx-po_item = pocomponents-po_item .
pocomponentsx-sched_line = pocomponents-sched_line .
pocomponentsx-item_no = pocomponents-item_no .
pocomponentsx-entry_quantity = 'X'.
pocomponentsx-material = 'X'.
pocomponentsx-change_id = 'X'.
APPEND pocomponentsx.
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
purchaseorder = p_ebeln
TABLES
return = return
poschedule = poschedule
poschedulex = poschedulex
pocomponents = pocomponents
pocomponentsx = pocomponentsx.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
WRITE 'OK'.