VA01/VA02 销售订单行项目调用创建/修改标准BAPI修改税率为'0'

[实例]

SO行项目->销项税MWST条件类型可以配置为手动修改,当通过外部接口调BAPI创建时,因 COND_VALUE 字段为DEC类型,传输税率为'0'时,会自动带出系统配置税率

 因外围系统有传输 '0' 税率的实际情况,所以当BAPI带出配置税率后,清空税率

BAPI:BAPI_SALESORDER_CREATEFROMDAT2->SD_SALESDOCUMENT_CREATE->SD_SALES_DOCU_MAINTAIN->SD_SALES_ITEM_COND_MAINTAIN

->perform vbap_fuellen(SAPFV45P)->PRICING_CHECK(在此BAPI带出配置税率)

 在函数最后,当行项目税率为'0'时,清空~

[创建SO示例代码]

  DATA:ls_bape_vbak  TYPE bape_vbak,
       ls_bape_vbakx TYPE bape_vbakx,
       ls_bape_vbap  TYPE bape_vbap,
       ls_bape_vbapx TYPE bape_vbapx.
  DATA: lv_type TYPE msgty,
        lv_msg  TYPE msgtxt,
        lv_key1 TYPE char255,
        lv_key2 TYPE char255,
        lv_key3 TYPE char255.
  DATA:BEGIN OF ls_so,
         item TYPE kposn,
       END OF ls_so,
       lt_so LIKE TABLE OF ls_so.

  zmac-rfc-log-b.

  IF is_zvbak-zzcontract IS NOT INITIAL.
    ls_bape_vbak-zzcontract = is_zvbak-zzcontract.
    ls_bape_vbakx-zzcontract = 'X'.
  ENDIF.
  IF is_zvbak-zzproject IS NOT INITIAL.
    ls_bape_vbak-zzproject = is_zvbak-zzproject.
    ls_bape_vbakx-zzproject = 'X'.
  ENDIF.
  IF is_zvbak-zzsaleser IS NOT INITIAL.
    ls_bape_vbak-zzsaleser = is_zvbak-zzsaleser.
    ls_bape_vbakx-zzsaleser = 'X'.
  ENDIF.
  IF is_zvbak-zzwerks IS NOT INITIAL.
    ls_bape_vbak-zzwerks = is_zvbak-zzwerks.
    ls_bape_vbakx-zzwerks = 'X'.
  ENDIF.
  IF is_zvbak-zzdelivery IS NOT INITIAL.
    ls_bape_vbak-zzdelivery = is_zvbak-zzdelivery.
    ls_bape_vbakx-zzdelivery = 'X'.
  ENDIF.
  IF is_zvbak-zztradepath IS NOT INITIAL.
    ls_bape_vbak-zztradepath = is_zvbak-zztradepath.
    ls_bape_vbakx-zztradepath = 'X'.
  ENDIF.
  IF is_zvbak-kostl IS NOT INITIAL.
    ls_bape_vbak-kostl = is_zvbak-kostl.
    ls_bape_vbakx-kostl = 'X'.
  ENDIF.
  IF is_zvbak-zzremark IS NOT INITIAL.
    ls_bape_vbak-zzremark = is_zvbak-zzremark.
    ls_bape_vbakx-zzremark = 'X'.
  ENDIF.
  IF is_zvbak-zzsaleser_tel IS NOT INITIAL.
    ls_bape_vbak-zzsaleser_tel = is_zvbak-zzsaleser_tel.
    ls_bape_vbakx-zzsaleser_tel = 'X'.
  ENDIF.
  IF is_zvbak-zzpaymentpercent IS NOT INITIAL.
    ls_bape_vbak-zzpaymentpercent = is_zvbak-zzpaymentpercent.
    ls_bape_vbakx-zzpaymentpercent = 'X'.
  ENDIF.
  IF is_zvbak-zzwarranty_desc IS NOT INITIAL.
    ls_bape_vbak-zzwarranty_desc = is_zvbak-zzwarranty_desc.
    ls_bape_vbakx-zzwarranty_desc = 'X'.
  ENDIF.
  "增强第583位开始,目前一共593位
  IF is_zvbak-zzsalesno IS NOT INITIAL.
    ls_bape_vbak-zzsalesno = is_zvbak-zzsalesno.
    ls_bape_vbakx-zzsalesno = 'X'.
  ENDIF.
  IF is_zvbak-zzfwfsqx IS NOT INITIAL.
    ls_bape_vbak-zzfwfsqx = is_zvbak-zzfwfsqx.
    ls_bape_vbakx-zzfwfsqx = 'X'.
  ENDIF.
  IF is_zvbak-zzfwqxms IS NOT INITIAL.
    ls_bape_vbak-zzfwqxms = is_zvbak-zzfwqxms.
    ls_bape_vbakx-zzfwqxms = 'X'.
  ENDIF.
  IF is_zvbak-zzsjsh IS NOT INITIAL.
    ls_bape_vbak-zzsjsh = is_zvbak-zzsjsh.
    ls_bape_vbakx-zzsjsh = 'X'.
  ENDIF.

  extensionin-structure = 'BAPE_VBAK'.
  extensionin-valuepart1 = ls_bape_vbak(240).
  extensionin-valuepart2 = ls_bape_vbak+240(240).
  extensionin-valuepart3 = ls_bape_vbak+480(223).
  APPEND extensionin.
  CLEAR extensionin.
  extensionin-structure = 'BAPE_VBAKX'.
  extensionin-valuepart1 = ls_bape_vbakx.
  APPEND extensionin.
  CLEAR extensionin.

  LOOP AT it_zvbap.
    ls_bape_vbap-posnr = it_zvbap-posnr.
    ls_bape_vbapx-posnr = it_zvbap-posnr.
    IF it_zvbap-zzcrmitem IS NOT INITIAL.
      ls_bape_vbap-zzcrmitem = it_zvbap-zzcrmitem.
      ls_bape_vbapx-zzcrmitem = 'X'.
    ENDIF.
    IF it_zvbap-zzproduc_name IS NOT INITIAL.
      ls_bape_vbap-zzproduc_name = it_zvbap-zzproduc_name.
      ls_bape_vbapx-zzproduc_name = 'X'.
    ENDIF.
    IF it_zvbap-zzbatch IS NOT INITIAL.
      ls_bape_vbap-zzbatch = it_zvbap-zzbatch.
      ls_bape_vbapx-zzbatch = 'X'.
    ENDIF.
    IF it_zvbap-zzdeliverydatedes IS NOT INITIAL.
      ls_bape_vbap-zzdeliverydatedes = it_zvbap-zzdeliverydatedes.
      ls_bape_vbapx-zzdeliverydatedes = 'X'.
    ENDIF.
    extensionin-structure = 'BAPE_VBAP'.
    extensionin-valuepart1 = ls_bape_vbap(240).
    extensionin-valuepart2 = ls_bape_vbap+240(96).
    APPEND extensionin.
    CLEAR extensionin.
    extensionin-structure = 'BAPE_VBAPX'.
    extensionin-valuepart1 = ls_bape_vbapx.
    APPEND extensionin.
    CLEAR extensionin.
    CLEAR:ls_bape_vbap,ls_bape_vbapx.
  ENDLOOP.

  "因SAP允许BAPI传两行相同的条件类型,所以自己加报错信息,重复税率报错
  DATA(lt_condition) = order_conditions_in[].
  SORT lt_condition BY itm_number cond_type.
  LOOP AT lt_condition ASSIGNING FIELD-SYMBOL(<fs_condition>)
                  GROUP BY ( itm_number = <fs_condition>-itm_number cond_type = <fs_condition>-cond_type size = GROUP SIZE )
                  REFERENCE INTO DATA(lt_group).
    IF lt_group->size > 1.
      return-type = 'E'.
      return-message = '条件类型行重复,请检查数据'.
      APPEND return.
      RETURN.
    ENDIF.
  ENDLOOP.
"将税率为'0'的行项目传输内存
  LOOP AT lt_condition INTO DATA(ls_condition) WHERE cond_type = 'MWST' AND cond_value IS INITIAL.
    ls_so-item = ls_condition-itm_number.
    APPEND ls_so TO lt_so.
    CLEAR:ls_so.
  ENDLOOP.
  EXPORT name1 = lt_so TO MEMORY ID 'ZFMSD_CREATE_SO'."PRICING_CHECK

  CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
    EXPORTING
      salesdocumentin         = salesdocumentin
      order_header_in         = order_header_in
      order_header_inx        = order_header_inx
      sender                  = sender
      binary_relationshiptype = binary_relationshiptype
      int_number_assignment   = int_number_assignment
      behave_when_error       = behave_when_error
      logic_switch            = logic_switch
      testrun                 = testrun
      convert                 = convert
    IMPORTING
      salesdocument           = salesdocument
    TABLES
      return                  = return
      order_items_in          = order_items_in
      order_items_inx         = order_items_inx
      order_partners          = order_partners
      order_schedules_in      = order_schedules_in
      order_schedules_inx     = order_schedules_inx
      order_conditions_in     = order_conditions_in
      order_conditions_inx    = order_conditions_inx
      order_cfgs_ref          = order_cfgs_ref
      order_cfgs_inst         = order_cfgs_inst
      order_cfgs_part_of      = order_cfgs_part_of
      order_cfgs_value        = order_cfgs_value
      order_cfgs_blob         = order_cfgs_blob
      order_cfgs_vk           = order_cfgs_vk
      order_cfgs_refinst      = order_cfgs_refinst
      order_ccard             = order_ccard
      order_text              = order_text
      order_keys              = order_keys
      extensionin             = extensionin
      partneraddresses        = partneraddresses
      extensionex             = extensionex
      nfmetallitms            = nfmetallitms.

  LOOP AT return INTO DATA(ls_return) WHERE type CA 'AEX'.
  ENDLOOP.

  FREE MEMORY ID 'ZFMSD_CREATE_SO'.

  lv_key1 = order_header_in-doc_type.
  LOOP AT order_items_in.
    lv_key2 = lv_key2 && order_items_in-itm_number.
    lv_key3 = lv_key3 && order_items_in-material.
    CLEAR:order_items_in.
  ENDLOOP.
  lv_type = return-type.
  lv_msg = return-message.
  zmac-rfc-log-e lv_type lv_msg lv_key1 lv_key2 lv_key3."日志记录结束
ENDFUNCTION.

 还有一种一代增强->RV61AFZB->出口:USEREXIT_XKOMV_BEWERTEN_END 里,符合条件清空,断点会走到这里,但实际使用时在这里清空无效,不知具体原因,遂使用上述方法

修改销售订单

1.修改定价条件时

①CONDITION_IN传值,必须传入原条件类型对应的字段值cond_st_no 和cond_count,否则会新增一行

②LOGIC_SWITCH-cond_handl = 'X' 更改,否则 condx-updateflag = 'U'也不行

③即便只修改价格,lt_cond的单位还是要传,否则价格会增加10倍

④当使用创建BAPI手动传入MWST税率行后,PRCD底表会出现两行税率行,一行生效,一行不生效,所以修改时要注意,读取cond_st_no 和cond_count 时,读取 ondisacti = ' ' (PRCD底表字段为 KINAK = ' ') 的,就是生效的那一行,修改BAPI可直接传输税率为'0',不需要做增强

2.修改时增强字段记得传销售订单号以及行项目号,不然会报错 '未输入凭证编号'

 [修改SO示例代码]

  DATA:is_view TYPE order_view,
       lt_no   TYPE STANDARD TABLE OF sales_key WITH HEADER LINE,
       lt_con  TYPE STANDARD TABLE OF bapisdcond.
  DATA:ls_bape_vbak  TYPE bape_vbak,
       ls_bape_vbakx TYPE bape_vbakx,
       ls_bape_vbap  TYPE bape_vbap,
       ls_bape_vbapx TYPE bape_vbapx.

  IF is_zvbak-vbeln IS NOT INITIAL.
    ls_bape_vbak-vbeln = is_zvbak-vbeln.
    ls_bape_vbakx-vbeln = 'X'.
  ENDIF.
  IF is_zvbak-zzcontract IS NOT INITIAL.
    ls_bape_vbak-zzcontract = is_zvbak-zzcontract.
    ls_bape_vbakx-zzcontract = 'X'.
  ENDIF.
  IF is_zvbak-zzproject IS NOT INITIAL.
    ls_bape_vbak-zzproject = is_zvbak-zzproject.
    ls_bape_vbakx-zzproject = 'X'.
  ENDIF.
  IF is_zvbak-zzsaleser IS NOT INITIAL.
    ls_bape_vbak-zzsaleser = is_zvbak-zzsaleser.
    ls_bape_vbakx-zzsaleser = 'X'.
  ENDIF.
  IF is_zvbak-zzwerks IS NOT INITIAL.
    ls_bape_vbak-zzwerks = is_zvbak-zzwerks.
    ls_bape_vbakx-zzwerks = 'X'.
  ENDIF.
  IF is_zvbak-zzdelivery IS NOT INITIAL.
    ls_bape_vbak-zzdelivery = is_zvbak-zzdelivery.
    ls_bape_vbakx-zzdelivery = 'X'.
  ENDIF.
  IF is_zvbak-zztradepath IS NOT INITIAL.
    ls_bape_vbak-zztradepath = is_zvbak-zztradepath.
    ls_bape_vbakx-zztradepath = 'X'.
  ENDIF.
  IF is_zvbak-kostl IS NOT INITIAL.
    ls_bape_vbak-kostl = is_zvbak-kostl.
    ls_bape_vbakx-kostl = 'X'.
  ENDIF.
  IF is_zvbak-zzremark IS NOT INITIAL.
    ls_bape_vbak-zzremark = is_zvbak-zzremark.
    ls_bape_vbakx-zzremark = 'X'.
  ENDIF.
  IF is_zvbak-zzsaleser_tel IS NOT INITIAL.
    ls_bape_vbak-zzsaleser_tel = is_zvbak-zzsaleser_tel.
    ls_bape_vbakx-zzsaleser_tel = 'X'.
  ENDIF.
  IF is_zvbak-zzpaymentpercent IS NOT INITIAL.
    ls_bape_vbak-zzpaymentpercent = is_zvbak-zzpaymentpercent.
    ls_bape_vbakx-zzpaymentpercent = 'X'.
  ENDIF.
  IF is_zvbak-zzwarranty_desc IS NOT INITIAL.
    ls_bape_vbak-zzwarranty_desc = is_zvbak-zzwarranty_desc.
    ls_bape_vbakx-zzwarranty_desc = 'X'.
  ENDIF.
  IF is_zvbak-zzsalesno IS NOT INITIAL.
    ls_bape_vbak-zzsalesno = is_zvbak-zzsalesno.
    ls_bape_vbakx-zzsalesno = 'X'.
  ENDIF.
  IF is_zvbak-zzfwfsqx IS NOT INITIAL.
    ls_bape_vbak-zzfwfsqx = is_zvbak-zzfwfsqx.
    ls_bape_vbakx-zzfwfsqx = 'X'.
  ENDIF.
  IF is_zvbak-zzfwqxms IS NOT INITIAL.
    ls_bape_vbak-zzfwqxms = is_zvbak-zzfwqxms.
    ls_bape_vbakx-zzfwqxms = 'X'.
  ENDIF.
  IF is_zvbak-zzsjsh IS NOT INITIAL.
    ls_bape_vbak-zzsjsh = is_zvbak-zzsjsh.
    ls_bape_vbakx-zzsjsh = 'X'.
  ENDIF.

  extensionin-structure = 'BAPE_VBAK'.
  extensionin-valuepart1 = ls_bape_vbak(240).
  extensionin-valuepart2 = ls_bape_vbak+240(240).
  extensionin-valuepart3 = ls_bape_vbak+480(223).
  APPEND extensionin.
  CLEAR extensionin.
  extensionin-structure = 'BAPE_VBAKX'.
  extensionin-valuepart1 = ls_bape_vbakx.
  APPEND extensionin.
  CLEAR extensionin.

  LOOP AT it_zvbap.
    ls_bape_vbap-vbeln = it_zvbap-vbeln.
    ls_bape_vbapx-vbeln = it_zvbap-vbeln.
    ls_bape_vbap-posnr = it_zvbap-posnr.
    ls_bape_vbapx-posnr = it_zvbap-posnr.
    IF it_zvbap-zzcrmitem IS NOT INITIAL.
      ls_bape_vbap-zzcrmitem = it_zvbap-zzcrmitem.
      ls_bape_vbapx-zzcrmitem = 'X'.
    ENDIF.
    IF it_zvbap-zzproduc_name IS NOT INITIAL.
      ls_bape_vbap-zzproduc_name = it_zvbap-zzproduc_name.
      ls_bape_vbapx-zzproduc_name = 'X'.
    ENDIF.
    IF it_zvbap-zzbatch IS NOT INITIAL.
      ls_bape_vbap-zzbatch = it_zvbap-zzbatch.
      ls_bape_vbapx-zzbatch = 'X'.
    ENDIF.
    IF it_zvbap-zzdeliverydatedes IS NOT INITIAL.
      ls_bape_vbap-zzdeliverydatedes = it_zvbap-zzdeliverydatedes.
      ls_bape_vbapx-zzdeliverydatedes = 'X'.
    ENDIF.
    extensionin-structure = 'BAPE_VBAP'.
    extensionin-valuepart1 = ls_bape_vbap(240).
    extensionin-valuepart2 = ls_bape_vbap+240(96).
    APPEND extensionin.
    CLEAR extensionin.
    extensionin-structure = 'BAPE_VBAPX'.
    extensionin-valuepart1 = ls_bape_vbapx.
    APPEND extensionin.
    CLEAR extensionin.
    CLEAR:ls_bape_vbap,ls_bape_vbapx.
  ENDLOOP.

  lt_no-vbeln = salesdocument.
  APPEND lt_no.
  is_view-sdcond = 'X'.
  CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
    EXPORTING
      i_bapi_view          = is_view
    TABLES
      sales_documents      = lt_no
      order_conditions_out = lt_con.

  LOOP AT conditions_in.
    READ TABLE lt_con INTO DATA(ls_con) WITH KEY itm_number = conditions_in-itm_number
                                                  cond_type = conditions_in-cond_type
                                                  condisacti = ''.
    IF sy-subrc = 0.
      conditions_in-cond_st_no = ls_con-cond_st_no.
      conditions_in-cond_count = ls_con-cond_count.
      MODIFY conditions_in.
    ENDIF.
  ENDLOOP.
  LOOP AT conditions_inx.
    READ TABLE lt_con INTO ls_con WITH KEY itm_number = conditions_inx-itm_number
                                           cond_type = conditions_inx-cond_type
                                           condisacti = ''.
    IF sy-subrc = 0.
      conditions_inx-cond_st_no = ls_con-cond_st_no.
      conditions_inx-cond_count = ls_con-cond_count.
      MODIFY conditions_inx.
    ENDIF.
  ENDLOOP.

  CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
    EXPORTING
      salesdocument         = salesdocument
      order_header_in       = order_header_in
      order_header_inx      = order_header_inx
      simulation            = simulation
      behave_when_error     = behave_when_error
      int_number_assignment = int_number_assignment
      logic_switch          = logic_switch
      no_status_buf_init    = no_status_buf_init
    TABLES
      return                = return
      order_item_in         = order_item_in
      order_item_inx        = order_item_inx
      partners              = partners
      partnerchanges        = partnerchanges
      partneraddresses      = partneraddresses
      order_cfgs_ref        = order_cfgs_ref
      order_cfgs_inst       = order_cfgs_inst
      order_cfgs_part_of    = order_cfgs_part_of
      order_cfgs_value      = order_cfgs_value
      order_cfgs_blob       = order_cfgs_blob
      order_cfgs_vk         = order_cfgs_vk
      order_cfgs_refinst    = order_cfgs_refinst
      schedule_lines        = schedule_lines
      schedule_linesx       = schedule_linesx
      order_text            = order_text
      order_keys            = order_keys
      conditions_in         = conditions_in
      conditions_inx        = conditions_inx
      extensionin           = extensionin
      extensionex           = extensionex
      nfmetallitms          = nfmetallitms.

  LOOP AT return INTO DATA(ls_return) WHERE type CA 'AEX'.
  ENDLOOP.
ENDFUNCTION.

 

posted @ 2024-11-18 20:21  小胖噜噜仔仔  阅读(7)  评论(0编辑  收藏  举报