先附上代码
FUNCTION ZBAPI_SALESORDER_CREATE_SO_084.
*"----------------------------------------------------------------------
*"*"本地接口:
*" EXPORTING
*" REFERENCE(ET_TRET) TYPE /EACC/T_BAPIRET2
*" TABLES
*" IT_TAB STRUCTURE ZSSO_CODE
*"----------------------------------------------------------------------
DATA:
* 抬头
lv_header TYPE bapisdhd1, "表头
lv_headerx TYPE bapisdhd1x, "表头标志
lv_partner TYPE bapiparnr, "业务伙伴
lv_logic_switch TYPE bapisdls , "s OCCURS 0 WITH HEADER LINE,
* 行项目
lv_item TYPE bapisditm, "行项目
lv_itemx TYPE bapisditmx,
lt_item TYPE STANDARD TABLE OF bapisditm, "行项目
lt_itemx TYPE STANDARD TABLE OF bapisditmx,
* 计划行
lv_cond TYPE bapicond, "价格条件
lv_condx TYPE bapicondx,
lv_schdl TYPE bapischdl, "交付计划
lv_schdlx TYPE bapischdlx,
lv_return TYPE bapiret2.
* 文本字段
DATA:
gt_text TYPE TABLE OF tline WITH HEADER LINE,
g_fname TYPE thead-tdname,
g_status TYPE c.
DATA: lv_order_conditions_in TYPE bapicond,
lv_order_conditions_inx TYPE bapicondx.
DATA: lt_order_conditions_in TYPE TABLE OF bapicond,
lt_order_conditions_inx TYPE TABLE OF bapicondx,
l_cond_type TYPE bapicondx-cond_type.
DATA: l_posnr TYPE vbap-posnr.
DATA: lt_vbap TYPE TABLE OF vbap,
ls_vbap TYPE vbap.
DATA: ls_tidnr TYPE ty_tidnr,
lt_tidnr TYPE TABLE OF ty_tidnr.
DATA:
lt_partner TYPE STANDARD TABLE OF bapiparnr,
lt_schdl TYPE STANDARD TABLE OF bapischdl,
lt_schdlx TYPE STANDARD TABLE OF bapischdlx,
lt_return TYPE STANDARD TABLE OF bapiret2,
lt_text LIKE STANDARD TABLE OF bapisdtext.
DATA: l_vbeln TYPE bapivbeln-vbeln,
l_msg TYPE bapi_msg,
s_msg TYPE bapi_msg.
DATA: p_et_tret TYPE bapiret2.
FIELD-SYMBOLS: <item> TYPE zsso_code.
TYPES:BEGIN OF gty_s_mem,
knumv TYPE knumv,
posnr TYPE kposn,
stunr TYPE stunr,
cond_type TYPE kscha,
value TYPE kwert.
TYPES: END OF gty_s_mem.
TYPES: gty_t_mem TYPE STANDARD TABLE OF gty_s_mem.
DATA lT_mem TYPE gty_t_mem.
DATA ls_mem TYPE gty_s_mem.
TYPES:BEGIN OF gty_s_JZ,
knumv TYPE knumv,
posnr TYPE kposn,
stunr TYPE stunr,
cond_type TYPE kscha,
value TYPE kwert,
JZvalue TYPE KAWRT.
TYPES: END OF gty_s_JZ.
TYPES: gty_t_JZ TYPE STANDARD TABLE OF gty_s_JZ.
DATA lT_JZ TYPE gty_t_JZ.
DATA ls_JZ TYPE gty_s_JZ.
IF it_tab[] IS INITIAL.
p_et_tret-type = 'E'.
p_et_tret-message = '传入参数不能为空!'.
APPEND p_et_tret TO et_tret.
RETURN.
ENDIF.
CALL FUNCTION 'SD_SALES_DOCUMENT_INIT'.
* lv_logic_switch-pricing = 'B'.
* lv_logic_switch-cond_handl = 'X'.
CLEAR: lv_header,lt_tidnr, lv_partner, lv_item, lv_itemx, lt_item, lt_itemx, lv_cond, lv_condx, lv_schdl, lv_schdlx, lv_return,lt_vbap.
*add by zhangsheng 20200920
DATA:lv_kwmeng TYPE zsso_code-kwmeng.
CLEAR lv_kwmeng.
DATA:it_head TYPE TABLE OF zsso_code.
it_head[] = it_tab[].
SORT it_head BY z_son.
DELETE ADJACENT DUPLICATES FROM it_head COMPARING z_son.
LOOP AT it_head ASSIGNING <item>.
CLEAR lv_kwmeng.
LOOP AT it_tab ASSIGNING FIELD-SYMBOL(<is_head>) WHERE z_son = <item>-z_son.
lv_kwmeng = lv_kwmeng + <is_head>-kwmeng.
ENDLOOP.
*add by zhangsheng 20200920
* partners
CLEAR: lv_partner, lt_partner[].
lv_partner-partn_role = 'AG'. "售达方
lv_partner-partn_numb = <item>-kunnr.
APPEND lv_partner TO lt_partner.
IF <item>-kunwe IS NOT INITIAL .
PERFORM frm_convexit_alpha_input CHANGING <item>-kunwe.
CLEAR lv_partner.
lv_partner-partn_role = 'WE'. "送达方
lv_partner-partn_numb = <item>-kunwe.
APPEND lv_partner TO lt_partner.
ENDIF.
* 抬头
lv_header-doc_type = <item>-auart. " 订单类型
lv_header-sales_org = <item>-vkorg. " 销售组织
lv_header-distr_chan = <item>-vtweg. " 分销渠道
lv_header-division = <item>-spart. " 产品组
lv_header-sales_off = <item>-vkbur. " 销售小组
lv_header-sales_grp = <item>-vkgrp. " 销售员
lv_header-purch_no_c = <item>-bstnk. " 客户参考
lv_header-ord_reason = <item>-augru. " 订货原因
lv_header-purch_no_c = <item>-bstkd. " 业务编号(结算单)
lv_header-req_date_h = <item>-ketdat. " 交货日期
* lv_header-created_by = <item>-bname. " 创建人
lv_header-name = <item>-bname. " 创建人
lv_header-dun_date = <item>-mahdt. " 创建日期
lv_header-collect_no = <item>-sysid. " 汇总号
* 修改标记
* lv_headerx-updateflag = 'I'. " 订单类型
lv_headerx-doc_type = 'X'. " 订单类型
lv_headerx-sales_org = 'X'. " 销售组织
lv_headerx-distr_chan = 'X'. " 分销渠道
lv_headerx-division = 'X'. " 产品组
lv_headerx-sales_off = 'X'. " 销售员
lv_headerx-sales_grp = 'X'. " 销售小组
lv_headerx-ord_reason = 'X'. " 订货原因
lv_headerx-purch_no_c = 'X'. " 客户参考
lv_headerx-req_date_h = 'X'. " 交货日期
lv_headerx-name = 'X'. " 创建人
lv_headerx-dun_date = 'X'. " 创建日期
lv_headerx-collect_no = 'X'. " 汇总号
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = <item>-matnr
IMPORTING
output = <item>-matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
* 行项目
l_posnr = l_posnr + 10.
CLEAR lv_item.
lv_item-itm_number = l_posnr. " 行项目
lv_item-material = <item>-matnr. " 物料
lv_item-plant = <item>-werks. " 工厂
lv_item-store_loc = <item>-lgort. " 库存地点
lv_item-target_qty = lv_kwmeng." <item>-kwmeng. " 订单数量 add by zhangsheng 20200920
lv_item-purch_no_c = <item>-bstkd. " 业务编号(结算单)
lv_item-purch_no_s = <item>-z_son. " SON号
IF <item>-zrsv011 IS NOT INITIAL.
lv_item-short_text = <item>-zrsv011. "物料行项目描述
ENDIF.
APPEND lv_item TO lt_item.
* 明细行标识
CLEAR lv_itemx.
lv_itemx-itm_number = l_posnr. " 行项目
lv_itemx-material = 'X'. " 物料
lv_itemx-plant = 'X'. " 工厂
lv_itemx-store_loc = 'X'. " 库存地点
lv_itemx-target_qty = 'X'. " 订单数量
lv_itemx-purch_no_c = 'X'. " 业务编号(结算单)
lv_itemx-purch_no_s = 'X'. " SON号
* lv_itemx-updateflag = 'I'.
IF <item>-zrsv011 IS NOT INITIAL.
lv_itemx-short_text = 'X'. "物料行项目描述
ENDIF.
APPEND lv_itemx TO lt_itemx.
* " 定价conditions
IF <item>-kbetr NE 0 .
lv_order_conditions_in-itm_number = l_posnr. "itm_number
lv_order_conditions_in-cond_type = 'ZPR0'.
lv_order_conditions_in-cond_st_no = '010'.
lv_order_conditions_in-cond_count_long = '001'.
lv_order_conditions_in-cond_count = '01'.
IF <item>-kpein IS NOT INITIAL .
lv_order_conditions_in-cond_p_unt = <item>-kpein.
ENDIF.
lv_order_conditions_in-cond_value = <item>-kbetr .
lv_order_conditions_in-currency = <item>-waerk.
APPEND lv_order_conditions_in TO lt_order_conditions_in.
CLEAR lv_order_conditions_inx.
lv_order_conditions_inx-itm_number = l_posnr.
lv_order_conditions_inx-cond_type = 'ZPR0'.
lv_order_conditions_inx-cond_st_no = '010'.
lv_order_conditions_inx-cond_count_long = '001'.
lv_order_conditions_inx-cond_count = '01'.
IF <item>-kpein IS NOT INITIAL .
lv_order_conditions_inx-cond_p_unt = 'X'.
ENDIF.
lv_order_conditions_inx-cond_value = 'X'.
lv_order_conditions_inx-currency = 'X'.
lv_order_conditions_inx-updateflag = 'U' .
APPEND lv_order_conditions_inx TO lt_order_conditions_inx.
ENDIF.
* "判断折扣:
IF <item>-z_deduct NE ''.
CLEAR lv_order_conditions_in.
lv_order_conditions_in-itm_number = l_posnr. "itm_number
lv_order_conditions_in-cond_p_unt = '1'.
lv_order_conditions_in-cond_type = 'ZK00'.
lv_order_conditions_in-cond_st_no = '050'.
lv_order_conditions_in-cond_count_long = '001'.
lv_order_conditions_in-cond_value = <item>-z_deduct.
* lv_order_conditions_in-cond_value = <item>-z_deduct / 10.
lv_order_conditions_in-currency = <item>-waerk.
APPEND lv_order_conditions_in TO lt_order_conditions_in.
CLEAR lv_order_conditions_inx.
lv_order_conditions_inx-itm_number = l_posnr.
lv_order_conditions_inx-cond_type = 'ZK00'.
lv_order_conditions_inx-cond_st_no = '050'.
lv_order_conditions_inx-cond_count_long = '001'.
lv_order_conditions_inx-cond_p_unt = 'X'.
lv_order_conditions_inx-cond_value = 'X'.
lv_order_conditions_inx-currency = 'X'.
lv_order_conditions_inx-updateflag = 'U' .
APPEND lv_order_conditions_inx TO lt_order_conditions_inx.
ENDIF.
""ADD BY LIQ 20220714 税处理新增ZWST税额取接口数据,走增强修改 增强点:程序RV61AFZB 增强名称:ZEH_EHN_CONDVALUE
"税额值修改
DATA lv_memory_id TYPE char20.
CLEAR ls_mem.
ls_mem-knumv = ''.
ls_mem-posnr = l_posnr.
ls_mem-stunr = '200'.
ls_mem-cond_type = 'ZWST'.
ls_mem-value = <item>-z_tax .
APPEND ls_mem TO lT_mem[].
lv_memory_id = sy-uname && 'ZSDR070'.
FREE MEMORY ID lv_memory_id.
EXPORT lt_mem TO MEMORY ID lv_memory_id.
"基准值修改
DATA lv_memojz_id TYPE char20.
CLEAR ls_mem.
ls_JZ-knumv = ''.
ls_JZ-posnr = l_posnr.
ls_JZ-stunr = '200'.
ls_JZ-cond_type = 'ZWST'.
ls_JZ-value = <item>-z_tax .
ls_JZ-jzvalue = <item>-Z_NETAMT * <item>-KWMENG / <item>-KPEIN.
APPEND ls_JZ TO lt_JZ[].
lv_memojz_id = sy-uname && 'CREATR_SO_084'.
FREE MEMORY ID lv_memojz_id.
EXPORT lt_JZ TO MEMORY ID lv_memojz_id.
""END ADD .
"交货计划
CLEAR lv_schdl.
lv_schdl-itm_number = l_posnr. "行项目
lv_schdl-req_qty = lv_kwmeng." <item>-kwmeng. " 订单数量 add by zhangsheng 20200920
APPEND lv_schdl TO lt_schdl.
CLEAR lv_schdlx.
lv_schdlx-itm_number = l_posnr. "行项目
lv_schdlx-updateflag = 'I'.
lv_schdlx-req_qty = 'X'.
APPEND lv_schdlx TO lt_schdlx.
"序列号
IF <item>-tidnr IS NOT INITIAL.
ls_tidnr-posnr = l_posnr .
ls_tidnr-tidnr = <item>-tidnr .
APPEND ls_tidnr TO lt_tidnr .
CLEAR ls_tidnr.
ENDIF.
ENDLOOP.
UNASSIGN <item>.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in = lv_header
order_header_inx = lv_headerx
logic_switch = lv_logic_switch
IMPORTING
salesdocument = l_vbeln
TABLES
return = lt_return
order_items_in = lt_item
order_items_inx = lt_itemx
order_partners = lt_partner
************21.07.2020 18:26:22***mark*************start
order_conditions_in = lt_order_conditions_in
order_conditions_inx = lt_order_conditions_inx
************21.07.2020 18:26:22*******************end
order_schedules_in = lt_schdl
order_schedules_inx = lt_schdlx.
* extensionin = lt_extensionin.
* 查找错误信息
PERFORM frm_get_bapi_error USING lt_return CHANGING l_msg.
IF l_msg IS INITIAL. "成功
PERFORM frm_get_deliveryno USING lt_return CHANGING s_msg.
et_tret[] = lt_return[].
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
*增加修改抬头文本逻辑: Z_TEXT1
READ TABLE it_tab ASSIGNING <item> INDEX 1.
IF sy-subrc = 0.
IF <item>-z_text1 IS NOT INITIAL .
PERFORM write_text TABLES et_tret[] USING l_vbeln <item>-z_text1 .
ENDIF.
ENDIF.
ELSE. "失败
et_tret[] = lt_return .
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
CLEAR:
lt_partner[],
lt_item[],
lt_itemx[],
lv_header,
lv_headerx,
lt_order_conditions_in[],
lt_order_conditions_inx[],
lt_schdl[],
lt_schdlx[],
l_posnr,
lt_return[].
ENDFUNCTION.
重点修改ZWST的税额计算的代码是下图,构造好数据之后传隐式增强修改税额数据
增强代码如下
TYPES:BEGIN OF gty_s_mem,
KNUMV TYPE KNUMV,
posnr TYPE kposn,
STUNR TYPE STUNR,
cond_type TYPE kscha,
VALUE TYPE KWERT.
TYPES: END OF gty_s_mem.
TYPES: gty_t_mem TYPE STANDARD TABLE OF gty_s_mem.
DATA lt_memory TYPE gty_t_mem.
DATA LS_MEMORY TYPE gty_s_mem.
DATA lv_memory_id TYPE CHAR20.
* IF SY-CPROG = 'ZSDR070' or SY-CPROG = 'ZSDR070_REPAIRE'.
lv_memory_id = sy-uname && 'ZSDR070'.
CLEAR lt_memory.
IMPORT lt_mem TO lt_memory FROM MEMORY ID lv_memory_id.
* FREE MEMORY ID lv_memory_id.
if lt_memory IS NOT INITIAL.
LOOP AT lt_memory INTO LS_MEMORY.
* READ TABLE XKOMV[] ASSIGNING FIELD-SYMBOL(<FS_XKOMV>) WITH KEY KNUMV = LS_MEMORY-KNUMV KPOSN = LS_MEMORY-POSNR STUNR = LS_MEMORY-STUNR KSCHL = LS_MEMORY-COND_TYPE .
READ TABLE XKOMV[] ASSIGNING FIELD-SYMBOL(<FS_XKOMV>)
WITH KEY KNUMV = LS_MEMORY-KNUMV
KPOSN = LS_MEMORY-POSNR
STUNR = LS_MEMORY-STUNR
KSCHL = LS_MEMORY-COND_TYPE .
IF SY-SUBRC = 0.
<FS_XKOMV>-KWERT = LS_MEMORY-VALUE.
<FS_XKOMV>-KSTEU = 'E'.
ENDIF.
ENDLOOP.
"wanwgei 20201022
* LOOP AT XKOMV ASSIGNING FIELD-SYMBOL(<FS_XKOMV>) WHERE KSCHL = 'ZJS1'.
* <FS_XKOMV>-MWSK1 = 'X7'.
* ENDLOOP.
endif.
* ENDIF.
""""""ADD BY LIQ 20220714 创建时新增ZWST税额固定数据赋值和 基准值赋值
TYPES:BEGIN OF gty_s_JZ,
knumv TYPE knumv,
posnr TYPE kposn,
stunr TYPE stunr,
cond_type TYPE kscha,
value TYPE kwert,
JZvalue TYPE KAWRT.
TYPES: END OF gty_s_JZ.
TYPES: gty_t_JZ TYPE STANDARD TABLE OF gty_s_JZ.
DATA lt_memoryJZ TYPE gty_t_JZ.
DATA lS_memoryJZ TYPE gty_s_JZ.
DATA lv_memojz_id TYPE char20.
lv_memojz_id = sy-uname && 'CREATR_SO_084'.
CLEAR lt_memoryJZ.
IMPORT lt_JZ TO lt_memoryJZ FROM MEMORY ID lv_memojz_id.
if lt_memoryJZ IS NOT INITIAL.
LOOP AT lt_memoryJZ INTO lS_memoryJZ.
READ TABLE XKOMV[] ASSIGNING <FS_XKOMV>
WITH KEY KNUMV = LS_MEMORY-KNUMV
KPOSN = LS_MEMORY-POSNR
STUNR = LS_MEMORY-STUNR
KSCHL = LS_MEMORY-COND_TYPE .
IF SY-SUBRC = 0.
<FS_XKOMV>-KWERT = lS_memoryJZ-VALUE.
<FS_XKOMV>-KSTEU = 'E'.
<FS_XKOMV>-KAWRT = lS_memoryJZ-JZvalue.
ENDIF.
ENDLOOP.
endif.
""""END ADD LIQ 20220714
增强位置是