货铺QQ群号:834508274
进群统一修改群名片,例如BJ_ABAP_森林木。群内禁止发广告及其他一切无关链接,小程序等,进群看公告,谢谢配合
不修改昵称会被不定期踢除,谢谢配合
如果使用 BAPI_SALESORDER_CREATEFROMDAT2 创建,报错:
不允许业务对象 BUS2032 和销售凭证类别 K 的组合
需要使用
SD_SALESDOCUMENT_CREATE
贷项凭证 发票过账日期
如果VF01 如果不输入日期,默认是读取订单上的开票日期。
*&---------------------------------------------------------------------*
*& Report ZDEMO_VA01_D
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zdemo_va01_d.
PARAMETERS p_kunnr TYPE kunnr DEFAULT '1004615'.
PARAMETERS p_vkorg TYPE vkorg DEFAULT 'S600'.
PARAMETERS p_vtweg TYPE vtweg DEFAULT '10'.
PARAMETERS p_spart TYPE spart DEFAULT '00'.
PARAMETERS p_werks TYPE werks_d DEFAULT 'S600'.
PARAMETERS p_lgort TYPE lgort_d DEFAULT '6001'.
PARAMETERS p_vstel TYPE vstel DEFAULT 'S600'.
PARAMETERS p_matnr TYPE matnr DEFAULT 'XSWPTEST'.
DATA:ls_order_header_in LIKE bapisdhd1.
DATA:ls_order_header_inx LIKE bapisdhd1x.
DATA:lt_order_items_in LIKE TABLE OF bapisditm.
DATA:lt_order_items_inx LIKE TABLE OF bapisditmx.
DATA:ls_order_items_in LIKE bapisditm.
DATA:ls_order_items_inx LIKE bapisditmx.
DATA:lt_order_partners LIKE TABLE OF bapiparnr.
DATA:ls_order_partners LIKE LINE OF lt_order_partners.
DATA:lt_schedules_in LIKE TABLE OF bapischdl .
DATA:lt_schedules_inx LIKE TABLE OF bapischdlx .
DATA:ls_schedules_in LIKE bapischdl .
DATA:ls_schedules_inx LIKE bapischdlx .
DATA:lt_order_conditions_in LIKE TABLE OF bapicond .
DATA:lt_order_conditions_inx LIKE TABLE OF bapicondx .
DATA:ls_order_conditions_in LIKE bapicond .
DATA:ls_order_conditions_inx LIKE bapicondx .
DATA: lt_return LIKE TABLE OF bapiret2.
DATA: ls_return LIKE bapiret2.
DATA:lv_salesdocument LIKE bapivbeln-vbeln.
CLEAR ls_order_header_in.
ls_order_header_in-doc_type = 'ZDCR'."订单类型
ls_order_header_in-sales_org = p_vkorg.
ls_order_header_in-distr_chan = p_vtweg."分销渠道
ls_order_header_in-division = p_spart."产品组
* ls_order_header_in-sales_off = . "销售部门
ls_order_header_in-purch_no_c = 'test'.
ls_order_header_in-bill_date = '20181220'."开具发票日期
CLEAR ls_order_header_inx.
ls_order_header_inx-doc_type = 'X'.
ls_order_header_inx-sales_org = 'X'.
ls_order_header_inx-distr_chan = 'X'.
ls_order_header_inx-division = 'X'.
*ls_order_header_inx-sales_off = 'X'.
ls_order_header_inx-ass_number = 'X'.
ls_order_header_inx-updateflag = '1'.
ls_order_header_inx-purch_no_c = 'X'.
ls_order_header_inx-bill_date = 'X'.
CLEAR ls_order_items_in.
CLEAR lt_order_items_in[].
ls_order_items_in-itm_number = '10'."只有一个行项目
ls_order_items_in-material = p_matnr.
ls_order_items_in-plant = p_werks.
ls_order_items_in-store_loc = p_lgort.
ls_order_items_in-target_qty = 1.
ls_order_items_in-ship_point = p_vstel."装运点
ls_order_items_in-target_qu = 'EA'.
ls_order_items_in-sales_unit = 'EA'.
APPEND ls_order_items_in TO lt_order_items_in.
CLEAR lt_schedules_in[].
CLEAR ls_schedules_in.
ls_schedules_in-itm_number = '10'."只有一个行项目
ls_schedules_in-req_qty = 1.
APPEND ls_schedules_in TO lt_schedules_in.
CLEAR ls_schedules_inx.
CLEAR lt_schedules_inx[].
ls_schedules_inx-updateflag = 'X'.
ls_schedules_inx-itm_number = 'X'.
ls_schedules_inx-req_qty = 'X'.
APPEND ls_schedules_inx TO lt_schedules_inx.
"售达方默认
CLEAR ls_order_partners.
ls_order_partners-partn_role = 'AG'.
ls_order_partners-partn_numb = p_kunnr.
APPEND ls_order_partners TO lt_order_partners.
*&-------------------------------------
"送达方 使用一次性客户
*&-------------------------------------
CLEAR ls_order_partners.
*ls_order_partners-partn_role = 'WE'.
*ls_order_partners-partn_numb = '1'.
*
*CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
* EXPORTING
* input = ls_order_partners-partn_numb
* IMPORTING
* output = ls_order_partners-partn_numb.
*
*ls_order_partners-name = '一次性客户测试'.
*ls_order_partners-country = 'CN'.
*APPEND ls_order_partners TO lt_order_partners.
"送达方
CLEAR ls_order_partners.
ls_order_partners-partn_role = 'WE'.
ls_order_partners-partn_numb = p_kunnr.
APPEND ls_order_partners TO lt_order_partners.
*&---------------------------------------------------------------
"付款方
CLEAR ls_order_partners.
ls_order_partners-partn_role = 'RE'.
ls_order_partners-partn_numb = p_kunnr.
APPEND ls_order_partners TO lt_order_partners.
"收票方
CLEAR ls_order_partners.
ls_order_partners-partn_role = 'RG'.
ls_order_partners-partn_numb = p_kunnr.
APPEND ls_order_partners TO lt_order_partners.
CLEAR lt_order_conditions_in[].
CLEAR lt_order_conditions_inx[].
CLEAR ls_order_conditions_in.
ls_order_conditions_in-itm_number = '10'.
ls_order_conditions_in-cond_st_no = ''.
ls_order_conditions_in-cond_count = ''.
ls_order_conditions_in-cond_type = 'ZP32'. "定价条件
ls_order_conditions_in-cond_value = 1000.
ls_order_conditions_in-currency = 'RMB'. "币别
APPEND ls_order_conditions_in TO lt_order_conditions_in.
CLEAR ls_order_conditions_inx.
ls_order_conditions_inx-itm_number = '10'.
ls_order_conditions_inx-cond_st_no = ''.
ls_order_conditions_inx-cond_count = ''.
ls_order_conditions_inx-updateflag = 'X'.
ls_order_conditions_inx-cond_type = 'ZP32'. "定价条件
ls_order_conditions_inx-cond_value = 'X'. "价格
IF ls_order_conditions_in-currency IS NOT INITIAL.
ls_order_conditions_inx-currency = 'X'. "币别
ENDIF.
APPEND ls_order_conditions_inx TO lt_order_conditions_inx.
CLEAR lv_salesdocument.
CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
EXPORTING
sales_header_in = ls_order_header_in
sales_header_inx = ls_order_header_inx
IMPORTING
salesdocument_ex = lv_salesdocument
TABLES
return = lt_return
sales_items_in = lt_order_items_in
sales_items_inx = lt_order_items_inx
sales_partners = lt_order_partners
sales_schedules_in = lt_schedules_in
sales_schedules_inx = lt_schedules_inx
sales_conditions_in = lt_order_conditions_in
sales_conditions_inx = lt_order_conditions_inx.
**&不能使用 BAPI_SALESORDER_CREATEFROMDAT2
*CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
* EXPORTING
* order_header_in = ls_order_header_in
* order_header_inx = ls_order_header_inx
* IMPORTING
* salesdocument = lv_salesdocument
* TABLES
* return = lt_return
* order_items_in = lt_order_items_in
* order_items_inx = lt_order_items_inx
* order_partners = lt_order_partners
* order_schedules_in = lt_schedules_in
* order_schedules_inx = lt_schedules_inx
* order_conditions_in = lt_order_conditions_in
* order_conditions_inx = lt_order_conditions_inx.
IF lv_salesdocument IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
WRITE lv_salesdocument.