*&---------------------------------------------------------------------*
*& Report ZDEMO_CLOSE_PO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zdemo_close_po.
PARAMETERS p_so TYPE vbak-vbeln.
DATA: ls_order_header_in LIKE bapisdh1,
ls_order_header_inx LIKE bapisdh1x.
DATA:lt_return LIKE TABLE OF bapiret2.
DATA:ls_return LIKE LINE OF lt_return.
DATA:lt_order_item_in LIKE TABLE OF bapisditm,
lt_order_item_inx LIKE TABLE OF bapisditmx.
DATA:ls_order_item_in LIKE LINE OF lt_order_item_in.
DATA:ls_order_item_inx LIKE LINE OF lt_order_item_inx.
ls_order_header_in-req_date_h = sy-datum.
ls_order_header_inx-updateflag = 'U'.
ls_order_header_inx-req_date_h = 'X'.
ls_order_item_in-itm_number = 10.
ls_order_item_in-reason_rej = 'Z3'. "关闭原因
APPEND ls_order_item_in TO lt_order_item_in.
ls_order_item_inx-itm_number = 10.
ls_order_item_inx-updateflag = 'U'.
ls_order_item_inx-reason_rej = 'X'.
APPEND ls_order_item_inx TO lt_order_item_inx.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = p_so
order_header_in = ls_order_header_in
order_header_inx = ls_order_header_inx
TABLES
return = lt_return
order_item_in = lt_order_item_in
order_item_inx = lt_order_item_inx.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.