Change类的BAPI都差不多,改行项目的某个字段时,只需在lt_item的某个字段给值,然后再lt_itemx结构中的对应字段打上’X’,另外记得updateflag字段给’U’表示Update.
最后记得调用commit,一般都没什么问题。
示例代码:
DATA: lv_vbeln TYPE bapivbeln-vbeln,
ls_headrx TYPE bapisdh1x,
lt_return TYPE TABLE OF bapiret2 WITH HEADER LINE,
lt_item TYPE TABLE OF bapisditm WITH HEADER LINE,
lt_itemx TYPE TABLE OF bapisditmx WITH HEADER LINE.
DATA: lv_message TYPE string.
DATA: ls_zsd_up_dr_log TYPE zsd_up_dr_log.
DATA: lt_zsd_up_dr_log TYPE TABLE OF zsd_up_dr_log.
lv_vbeln = p_vbeln .
ls_headrx-updateflag = 'U'.
LOOP AT gt_change INTO gs_change.
lt_item-itm_number = gs_change-posnr.
* lt_item-material = gs_change-matnr.
lt_item-dlv_prio = gs_change-lprio.
APPEND lt_item.
lt_itemx-itm_number = gs_change-posnr.
lt_itemx-updateflag = 'U'.
lt_itemx-dlv_prio = 'X'.
APPEND lt_itemx.
ls_zsd_up_dr_log-vbeln = p_vbeln.
ls_zsd_up_dr_log-posnr = gs_change-posnr.
ls_zsd_up_dr_log-erdat = sy-datum.
APPEND ls_zsd_up_dr_log TO lt_zsd_up_dr_log.
ENDLOOP.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = lv_vbeln
* ORDER_HEADER_IN =
order_header_inx = ls_headrx
* SIMULATION =
* BEHAVE_WHEN_ERROR = ' '
* INT_NUMBER_ASSIGNMENT = ' '
* LOGIC_SWITCH =
* NO_STATUS_BUF_INIT = ' '
TABLES
return = lt_return
order_item_in = lt_item
order_item_inx = lt_itemx
* PARTNERS =
* PARTNERCHANGES =
* PARTNERADDRESSES =
* ORDER_CFGS_REF =
* ORDER_CFGS_INST =
* ORDER_CFGS_PART_OF =
* ORDER_CFGS_VALUE =
* ORDER_CFGS_BLOB =
* ORDER_CFGS_VK =
* ORDER_CFGS_REFINST =
* SCHEDULE_LINES =
* SCHEDULE_LINESX =
* ORDER_TEXT =
* ORDER_KEYS =
* CONDITIONS_IN =
* CONDITIONS_INX =
* EXTENSIONIN =
.
LOOP AT lt_return WHERE type = 'E' OR type = 'A'.
CONCATENATE lt_return-message ';' lv_message INTO lv_message. ENDLOOP.
IF sy-subrc ne 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.