REPORT zdemo_va01.
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 'TEST99'.
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 = 'ZDJX'."订单类型
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'.
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'.
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 = 'ZPR0'. "定价条件
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 = 'ZPR0'. "定价条件
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 '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.