SAP-修改销售订单税额
用户需要通过接口实现,修改行上的MWSI或MWST税额(两个不会同时存在),前台通过事务码
VA02
可以直接修改如图示字段。
观察字段名称,需要修改字段为定价值(KOMV-KWERT),相关字段有条件金额或百分比(KOMV-KBETR),条件基值(KOMV-KAWRT) 。
通过BAPI_SALESORDER_CHANGE修改
首先调用BAPISDORDER_GETDETAILEDLIST
接收lt_item
和lt_cond
。
" 省略MWST的逻辑
READ TABLE lt_cond INTO ls_cond WITH KEY itm_number = ls_item-posnr
cond_type = 'MWSI' .
IF sy-subrc = '0'.
lv_tabix = sy-tabix .
ls_cond-cond_value = ls_item-mwsi .
MODIFY lt_cond FROM ls_cond INDEX lv_tabix.
endif.
CLEAR: ls_condx.
ls_condx-updateflag = 'U' .
ls_condx-itm_number = ls_item-posnr.
ls_condx-cond_st_no = ls_cond-cond_st_no.
ls_condx-cond_count = ls_cond-cond_count.
ls_condx-cond_unit = 'X'.
ls_condx-cond_type = ls_cond-cond_type.
ls_condx-cond_value = 'X'.
ls_condx-currency = 'X'.
ls_condx-cond_count_long = ls_cond-cond_count_long.
ls_condx-varcond = ls_cond-varcond.
APPEND ls_condx TO lt_condx .
...
...
ls_logic-cond_handl = 'X' .
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = lv_vbeln
order_header_inx = ls_header_inx
logic_switch = ls_logic
TABLES
return = lt_return
order_item_in = lt_item_in
order_item_inx = lt_item_inx
partnerchanges = lt_partnr
schedule_lines = lt_schedu
schedule_linesx = lt_schedux
conditions_in = lt_cond
conditions_inx = lt_condx
.
处理若干问题后,发现实际修改的值是条件金额或百分比(KOMV-KBETR),在lt_condx中没有标记定价值(KOMV-KWERT)字段,因此无法修改!!!。
参看网上的资料 CSDN SAP-ABAP-创建销售订单BAPI税额修改增强
最终处理方案
1、程序RV61AFZB隐式增强FORM USEREXIT_XKOMV_BEWERTEN_END。
FORM USEREXIT_XKOMV_BEWERTEN_END.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Form USEREXIT_XKOMV_BEWERTEN_END, Anfang A
*$*$-Start: (1)---------------------------------------------------------------------------------$*$*
ENHANCEMENT 1 ZEI_RV61AFZB. "active version
TYPES: BEGIN OF l_tax,
knumv TYPE knumv,
posnr TYPE kposn,
stunr TYPE stunr,
cond_type TYPE kscha,
kwert TYPE komv-kwert,
kawrt TYPE komv-kawrt,
END OF l_tax .
DATA: lt_tax TYPE TABLE OF l_tax,
ls_tax TYPE l_tax.
" `SAPLZFG_SD013`为函数组名称
ASSIGN ('(SAPLZFG_SD013)GT_TAX') TO FIELD-SYMBOL(<ft_tax>) .
IF <ft_tax> IS NOT ASSIGNED OR <ft_tax> IS INITIAL.
RETURN .
ENDIF.
MOVE-CORRESPONDING <ft_tax> TO lt_tax.
FIELD-SYMBOLS: <fs_xkomv> LIKE komv_index.
LOOP AT lt_tax INTO ls_tax.
READ TABLE xkomv ASSIGNING <fs_xkomv>
WITH KEY knumv = ls_tax-knumv
kposn = ls_tax-posnr
stunr = ls_tax-stunr
kschl = ls_tax-cond_type.
IF sy-subrc = '0'.
<fs_xkomv>-kwert = ls_tax-kwert.
<fs_xkomv>-ksteu = 'E'.
ENDIF.
ENDLOOP.
ENDENHANCEMENT.
*$*$-End: (1)---------------------------------------------------------------------------------$*$*
ENDFORM.
2、函数组LZFG_SD013TOP声明全局变量
TYPES: BEGIN OF l_tax,
knumv TYPE knumv,
posnr TYPE kposn,
stunr TYPE stunr,
cond_type TYPE kscha,
kwert TYPE komv-kwert,
kawrt TYPE komv-kawrt,
END OF l_tax .
DATA: gt_tax TYPE TABLE OF l_tax .
3、给全局变量 gt_tax 赋值
SELECT SINGLE knumv
INTO @data(lv_knumv)
FROM vbak
WHERE vbeln = @lv_vbeln .
IF ls_item-mwsi IS NOT INITIAL.
READ TABLE lt_cond INTO ls_cond WITH KEY itm_number = ls_item-posnr
cond_type = 'MWST' .
IF sy-subrc = '0'.
" DENK965851 在程序 RV61AFZB 隐式增强 FORM USEREXIT_XKOMV_BEWERTEN_END
gt_tax = VALUE #( BASE gt_tax
( knumv = lv_knumv
posnr = ls_cond-itm_number
stunr = ls_cond-cond_st_no
cond_type = ls_cond-cond_type
kwert = ls_item-mwsi
) .
) .
ENDIF.
ENDIF.