用BAPI_SALESORDER_CREATEFROMDAT2创建销售订单,始终不能将选配件加上,如下是网上找到的代码,现急用,请朋友们帮忙看看,谢谢!<br>
<br>
<br>
<br>
&----
<br>
*& Report ZTEST07<br>
*&<br>
&----
<br>
*&<br>
*&<br>
&----
<br>
<br>
REPORT ZTEST07.<br>
<br>
DATA:ORDER_HEADER_IN LIKE BAPISDHD1,<br>
ORDER_ITEMS_IN LIKE BAPISDITM OCCURS 0 WITH HEADER LINE,<br>
order_items_inx LIKE bapisditmx OCCURS 0 WITH HEADER LINE,<br>
ORDER_PARTNERS LIKE BAPIPARNR OCCURS 0 WITH HEADER LINE,<br>
ORDER_SCHEDULES_IN LIKE BAPISCHDL OCCURS 0 WITH HEADER LINE,<br>
ORDER_CONDITIONS_IN LIKE BAPICOND OCCURS 0 WITH HEADER LINE,<br>
ORDER_CONDITIONS_INX LIKE BAPICONDX OCCURS 0 WITH HEADER LINE,<br>
ORDER_TEXT LIKE BAPISDTEXT OCCURS 0 WITH HEADER LINE,<br>
RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,<br>
order_cfgs_ref like bapicucfg OCCURS 0 WITH HEADER LINE, "bapicucfgbapicuref<br>
order_cfgs_value like bapicuval OCCURS 0 WITH HEADER LINE,<br>
WK_FLAG TYPE C,<br>
WK_VBELN LIKE VBAK-VBELN.<br>
<br>
<br>
<br>
REFRESH: ORDER_PARTNERS,ORDER_SCHEDULES_IN,<br>
ORDER_CONDITIONS_IN,ORDER_ITEMS_IN.<br>
<br>
ORDER_HEADER_IN-DOC_TYPE = 'ZORA'. "订单类型<br>
ORDER_HEADER_IN-SALES_ORG = '1100'. "销售组织<br>
ORDER_HEADER_IN-DISTR_CHAN = '11'. "分销渠道<br>
ORDER_HEADER_IN-DIVISION = '10'. "产品住<br>
*ORDER_HEADER_IN-SALES_GRP = '001'. "销售组<br>
*ORDER_HEADER_IN-SALES_OFF = '1000'. "销售部门<br>
ORDER_HEADER_IN-PURCH_NO_C = '测试订单'. "采购订单编号<br>
*ORDER_HEADER_IN-ORD_REASON = 'test'. "订单原因<br>
<br>
<br>
ORDER_HEADER_IN-REQ_DATE_H = '20101021'.<br>
ORDER_HEADER_IN-PURCH_DATE = '20101021'.<br>
<br>
<br>
ORDER_HEADER_IN-PMNTTRMS = 'D001'."付款条件<br>
ORDER_HEADER_IN-INCOTERMS1 = 'FOB'."国际贸易条件 CIF<br>
ORDER_HEADER_IN-INCOTERMS2 = 'SHENZHEN'."国际贸易条件 CIF<br>
<br>
<br>
ORDER_PARTNERS-PARTN_ROLE = 'AG'.<br>
ORDER_PARTNERS-PARTN_NUMB = '0000100009'.<br>
APPEND ORDER_PARTNERS.<br>
<br>
ORDER_PARTNERS-PARTN_ROLE = 'WE'.<br>
ORDER_PARTNERS-PARTN_NUMB = '0000100009'.<br>
APPEND ORDER_PARTNERS.<br>
<br>
ORDER_PARTNERS-PARTN_ROLE = 'RG'.<br>
ORDER_PARTNERS-PARTN_NUMB = '0000100009'.<br>
APPEND ORDER_PARTNERS.<br>
<br>
ORDER_ITEMS_IN-ITM_NUMBER = '000010'. "行项目<br>
ORDER_ITEMS_IN-MATERIAL = '000000001030000468'. "物料号<br>
ORDER_ITEMS_IN-PLANT = '1000'. "工厂<br>
*ORDER_ITEMS_IN-CUST_MAT35 = '232'. "客户物料编号<br>
ORDER_ITEMS_IN-CURRENCY = 'USD'.<br>
*ORDER_ITEMS_IN-STORE_LOC = ''. 仓库.<br>
ORDER_ITEMS_IN-ITEM_CATEG = 'ZTA1'.<br>
ORDER_ITEMS_IN-PO_ITM_NO = '000010'.<br>
<br>
APPEND ORDER_ITEMS_IN.<br>
<br>
<br>
*ORDER_ITEMS_IN-ITM_NUMBER = '000020'. "行项目<br>
*ORDER_ITEMS_IN-MATERIAL = '000000001030005926'. "物料号<br>
*ORDER_ITEMS_IN-PLANT = '1000'. "工厂<br>
**ORDER_ITEMS_IN-CUST_MAT35 = '232'. "客户物料编号<br>
*ORDER_ITEMS_IN-CURRENCY = 'USD'.<br>
**ORDER_ITEMS_IN-STORE_LOC = '<br>
*ORDER_ITEMS_IN-ITEM_CATEG = 'ZTA1'.<br>
**ORDER_ITEMS_IN-PRICE_LIST = '33'.<br>
**ORDER_ITEMS_IN-PRICE_GRP = 'ZP01'.<br>
**ORDER_ITEMS_IN-S_PROC_IND = '1'.<br>
*APPEND ORDER_ITEMS_IN.<br>
*<br>
<br>
order_items_inx-itm_number = '000010'.<br>
order_items_inx-material = 'X'.<br>
order_items_inx-updateflag = 'I'.<br>
order_items_inx-po_itm_no = 'X'.<br>
order_items_inx-ITEM_CATEG ='X'.<br>
APPEND order_items_inx .<br>
<br>
*order_items_inx-itm_number = '000020'.<br>
order_items_inx-material = 'X'.<br>
order_items_inx-updateflag = 'I'.<br>
order_items_inx-po_itm_no = 'X'.<br>
order_items_inx-ITEM_CATEG ='X'.<br>
APPEND order_items_inx .<br>
*<br>
<br>
ORDER_SCHEDULES_IN-ITM_NUMBER = '000010'. "销售凭证项目<br>
ORDER_SCHEDULES_IN-SCHED_LINE = '0001'. "交货计划行号<br>
ORDER_SCHEDULES_IN-REQ_DATE = '20100909'. "计划行日期<br>
ORDER_SCHEDULES_IN-req_qty = '7'. "以销售单位计的订单数量<br>
APPEND ORDER_SCHEDULES_IN.<br>
<br>
<br>
<br>
*ORDER_SCHEDULES_IN-ITM_NUMBER = '000020'. "销售凭证项目<br>
*ORDER_SCHEDULES_IN-SCHED_LINE = '0020'. "交货计划行号<br>
*ORDER_SCHEDULES_IN-REQ_DATE = '20100902'. "计划行日期<br>
*ORDER_SCHEDULES_IN-req_qty = '9'. "以销售单位计的订单数量<br>
*APPEND ORDER_SCHEDULES_IN.<br>
*<br>
<br>
<br>
<br>
ORDER_CONDITIONS_IN-ITM_NUMBER = '000010'. "条件项目号<br>
ORDER_CONDITIONS_IN-COND_TYPE = 'ZR01'. "条件类型<br>
ORDER_CONDITIONS_IN-COND_VALUE = '27'. "定价比率 价格<br>
order_conditions_in-currency = 'USD'. "两个地方都必须配置货币名, 非常重要要不价格会变为十倍<br>
**order_conditions_in-applicatio = 'V'.<br>
**order_conditions_in-conpricdat = '20070506'.<br>
**order_conditions_in-calctypcon = 'C'.<br>
*order_conditions_in-conbas = '1'.<br>
*order_conditions_in-conexchrat = '1'.<br>
*order_conditions_in-numconvert = '1'.<br>
*order_conditions_in-denominato = '1'.<br>
*order_conditions_in-cond_value = '20'.<br>
*order_conditions_in-cond_unit = 'PCS'.<br>
*order_conditions_in-cond_p_unt = '1'.<br>
**order_conditions_in-condvalue = '20'.<br>
APPEND ORDER_CONDITIONS_IN.<br>
<br>
<br>
<br>
ORDER_CONDITIONS_INX-ITM_NUMBER = '000010'. "条件项目号<br>
ORDER_CONDITIONS_INX-COND_TYPE = 'X'. "条件类型<br>
ORDER_CONDITIONS_INX-COND_VALUE = 'X'. "定价比率 价格<br>
APPEND ORDER_CONDITIONS_INX.<br>
<br>
<br>
<br>
<br>
*表頭內文**********<br>
order_text-doc_number = p_vbeln.<br>
<br>
order_text-text_id = 'Z201'.<br>
order_text-langu = '1'. "'M'<br>
order_text-langu_iso = 'ZH'."'ZF'.<br>
order_text-format_col = '*'.<br>
order_text-text_line = '中文 line 1'.<br>
*order_text-FUNCTION<br>
APPEND order_text.<br>
order_text-text_line = 'text line 2'.<br>
APPEND order_text.<br>
order_text-text_line = 'text line 3'.<br>
APPEND order_text.<br>
order_text-text_line = 'text line 4'.<br>
APPEND order_text.<br>
<br>
**項目內文***********<br>
order_text-doc_number = p_vbeln.<br>
order_text-itm_number = '000010'.<br>
order_text-text_id = 'Z251'.<br>
order_text-langu = '1'.<br>
order_text-langu_iso = 'ZH'.<br>
order_text-format_col = '*'.<br>
order_text-text_line = 'item text'.<br>
APPEND order_text.<br>
<br>
<br>
<br>
**組態資料************************<br>
order_cfgs_ref-posex = '000010'.<br>
order_cfgs_ref-config_id = '000001'.<br>
order_cfgs_ref-root_id = '00000001'.<br>
APPEND order_cfgs_ref.<br>
<br>
order_cfgs_value-config_id = '000010'."'000001'.<br>
order_cfgs_value-inst_id = '000010'."'00000001'.<br>
order_cfgs_value-charc = 'A1030004311'. "特性,不知这直接用ct04的特性有没有错<br>
order_cfgs_value-value = '01'. "特性值<br>
APPEND order_cfgs_value.<br>
<br>
<br>
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'<br>
EXPORTING<br>
ORDER_HEADER_IN = ORDER_HEADER_IN<br>
IMPORTING<br>
SALESDOCUMENT = WK_VBELN<br>
TABLES<br>
RETURN = RETURN<br>
ORDER_ITEMS_IN = ORDER_ITEMS_IN<br>
order_items_inx = order_items_inx<br>
ORDER_PARTNERS = ORDER_PARTNERS<br>
ORDER_SCHEDULES_IN = ORDER_SCHEDULES_IN<br>
ORDER_CONDITIONS_IN = ORDER_CONDITIONS_IN<br>
ORDER_CONDITIONS_INX = ORDER_CONDITIONS_INx<br>
order_cfgs_ref = order_cfgs_ref "<br>
order_cfgs_inst = order_cfgs_inst<br>
order_cfgs_part_of = order_cfgs_part_of<br>
order_cfgs_value = order_cfgs_value<br>
order_text = order_text.<br>
WK_FLAG = ''.<br>
LOOP AT RETURN.<br>
IF RETURN-TYPE = 'E' OR RETURN-TYPE = 'A'.<br>
WK_FLAG = 'X'.<br>
ENDIF.<br>
ENDLOOP.<br>
*下面的COMMIT是非常重要的, 不然不会产生订单, 系统会产生空号.<br>
*( 即系统在NUMBER RANGE层面上产生了增号, 但在实际上没有生成该订单号 )<br>
IF WK_FLAG = 'X'.<br>
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.<br>
<br>
WRITE:/ RETURN-MESSAGE COLOR 6.<br>
ELSE.<br>
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' .<br>
WRITE:/(10) WK_VBELN COLOR 5.<br>
<br>
ENDIF.<br><br>
Edited by: Sheng Qiang on Jun 18, 2010 3:00 PM