网上上参考了很多资料,去实现批量修改销售价格,但是一通操作下来发现都有问题,有的是修改不成功,有的是新增了条件类型,有的是只剩下一行条件类型的价格,后来就参照konv表的数据,研究了好久终于修改成功,和原始的定价一样,下面就是具体的思路和代码。
1.变量声明
DATA:order_item_in LIKE bapisditm OCCURS 0 WITH HEADER LINE,
order_item_inx LIKE bapisditmx OCCURS 0 WITH HEADER LINE,
lt_conditions_in LIKE bapicond OCCURS 0 WITH HEADER LINE,
return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
order_header_inx LIKE bapisdh1x,
lt_conditions_inx LIKE bapicondx OCCURS 0 WITH HEADER LINE.
DATA:ls_konv LIKE konv,
lt_konv LIKE TABLE OF konv.
2.通过konv获取价格数据,代码省略
3.给BAPI赋值
给header赋值,定位到Item的信息,修改哪一行的价格就填哪个行项目。
logic_switch-pricing = 'G'."修改就用'G'
order_header_inx-updateflag = 'U'."更新标记
order_item_in-itm_number = gs_dkp-posnr."行项目
APPEND order_item_in.
order_item_inx-itm_number = gs_dkp-posnr.
order_item_inx-updateflag = 'U'."更新标记
APPEND order_item_inx.
给价格数据赋值,本例的价格条件是ZRO1(单价),MWSI(税率),VPRS,NETW,修改之前是自动定价的,如果要修改单价,其他的三个价格条件也要更新,bapi也要进行赋值,否则修改后就只有zr01的价格条件。
"修改ZR01
READ TABLE lt_konv INTO ls_konv WITH KEY kschl = 'ZR01'.
IF sy-subrc = 0.
lt_conditions_in-itm_number = ls_konv-kposn.
lt_conditions_in-cond_st_no = ls_konv-stunr.
lt_conditions_in-cond_count = ls_konv-zaehk.
lt_conditions_in-cond_p_unt = ls_konv-kpein.
lt_conditions_in-cond_type = 'ZR01'.
lt_conditions_in-cond_value = gs_dkp-zkbetr.
lt_conditions_in-currency = ls_konv-waers.
APPEND lt_conditions_in.
CLEAR:lt_conditions_in.
* ls_konv1 = ls_konv.
lt_conditions_inx-itm_number = ls_konv-kposn.
lt_conditions_inx-cond_count = ls_konv-zaehk.
lt_conditions_inx-cond_st_no = ls_konv-stunr.
lt_conditions_inx-cond_type = ls_konv-kschl.
lt_conditions_inx-cond_p_unt = 'X'.
lt_conditions_inx-updateflag = 'U'.
lt_conditions_inx-cond_value = 'X'.
lt_conditions_inx-currency = 'X'.
APPEND lt_conditions_inx.
CLEAR:lt_conditions_inx.
ENDIF.
"修改税率
READ TABLE lt_konv INTO ls_konv WITH KEY kschl = 'MWSI'.
IF sy-subrc = 0.
lt_conditions_in-itm_number = ls_konv-kposn.
lt_conditions_in-cond_st_no = ls_konv-stunr.
lt_conditions_in-cond_count = ls_konv-zaehk.
" lt_conditions_in-cond_p_unt = ls_konv-kpein."税金不用有价格单位
lt_conditions_in-cond_type = ls_konv-kschl.
lt_conditions_in-cond_value = '13'."如果是13%的税率,就赋值13,在konv表现为130
" lt_conditions_in-currency = ls_konv-waers.
APPEND lt_conditions_in.
CLEAR:lt_conditions_in.
lt_conditions_inx-itm_number = ls_konv-kposn.
lt_conditions_inx-cond_count = ls_konv-zaehk.
lt_conditions_inx-cond_st_no = ls_konv-stunr.
lt_conditions_inx-cond_type = ls_konv-kschl.
lt_conditions_inx-cond_p_unt = 'X'.
lt_conditions_inx-updateflag = 'U'.
lt_conditions_inx-cond_value = 'X'.
lt_conditions_inx-currency = 'X'.
APPEND lt_conditions_inx.
CLEAR:lt_conditions_inx.
endif.
"成本
READ TABLE lt_konv INTO ls_konv WITH KEY kschl = 'VPRS'.
IF sy-subrc = 0.
lt_conditions_in-itm_number = ls_konv-kposn.
lt_conditions_in-cond_st_no = ls_konv-stunr.
lt_conditions_in-cond_count = ls_konv-zaehk.
lt_conditions_in-cond_p_unt = ls_konv-kpein.
lt_conditions_in-cond_type = ls_konv-kschl.
" lt_conditions_in-cond_value = '1.3'.
lt_conditions_in-currency = ls_konv-waers.
* lt_conditions_in-condorigin = 'A'.
APPEND lt_conditions_in.
CLEAR:lt_conditions_in.
lt_conditions_inx-itm_number = ls_konv-kposn.
lt_conditions_inx-cond_count = ls_konv-zaehk.
lt_conditions_inx-cond_st_no = ls_konv-stunr.
lt_conditions_inx-cond_type = ls_konv-kschl.
lt_conditions_inx-cond_p_unt = 'X'.
lt_conditions_inx-updateflag = 'U'.
lt_conditions_inx-cond_value = 'X'.
lt_conditions_inx-currency = 'X'.
APPEND lt_conditions_inx.
CLEAR:lt_conditions_inx.
endif.
READ TABLE lt_konv INTO ls_konv WITH KEY kschl = 'NETW'.
IF sy-subrc = 0.
lt_conditions_in-itm_number = ls_konv-kposn.
lt_conditions_in-cond_st_no = ls_konv-stunr.
lt_conditions_in-cond_count = ls_konv-zaehk.
lt_conditions_in-cond_p_unt = ls_konv-kpein.
lt_conditions_in-cond_type = ls_konv-kschl.
lt_conditions_in-currency = ls_konv-waers.
* lt_conditions_in-condorigin = 'A'.
APPEND lt_conditions_in.
CLEAR:lt_conditions_in.
lt_conditions_inx-itm_number = ls_konv-kposn.
lt_conditions_inx-cond_count = ls_konv-zaehk.
lt_conditions_inx-cond_st_no = ls_konv-stunr.
lt_conditions_inx-cond_type = ls_konv-kschl.
lt_conditions_inx-cond_p_unt = 'X'.
lt_conditions_inx-updateflag = 'U'.
lt_conditions_inx-cond_value = 'X'.
lt_conditions_inx-currency = 'X'.
APPEND lt_conditions_inx.
CLEAR:lt_conditions_inx.
endif.
4.调bapi
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = ls_lips-vgbel
order_header_inx = order_header_inx
logic_switch = logic_switch
" logic_switch = logic_switch
TABLES
return = return
order_item_in = order_item_in
order_item_inx = order_item_inx
conditions_in = lt_conditions_in
conditions_inx = lt_conditions_inx.
READ TABLE return WITH KEY
type = 'E'.
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
CONCATENATE gs_dkp-vbeln '价格修改成功' INTO gt_msg-x_msgid.
" gt_msg-x_msgid = ''.
gt_msg-x_msgty = 'S'.
APPEND gt_msg .
CLEAR:gt_msg.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
gt_msg-x_msgid = return-message.
gt_msg-x_msgty = return-type.
APPEND gt_msg .
CLEAR:gt_msg.
ENDIF.