於是在改用了BAPI_SALESORDER_CREATEFROMDAT2
這部份在Schedule Line 與 Condition有很好的控制
回傳值的部份也比 BAPI_SALESORDER_CREATEFROMDATA 清楚的很多
運用上還可以把長文的部份輸入在內...
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
ORDER_HEADER_IN = ORDER_HEADER_IN
ORDER_HEADER_INX = ORDER_HEADER_INX
SALESDOCUMENTIN = L_SALESDOCUMENT
* testrun = 'X'
IMPORTING
SALESDOCUMENT = L_VBELN
TABLES
RETURN = LI_RETURN
ORDER_ITEMS_IN = ORDER_ITEMS_IN
ORDER_ITEMS_INX = ORDER_ITEMS_INX
ORDER_SCHEDULES_IN = ORDER_SCHEDULES_IN
ORDER_SCHEDULES_INX = ORDER_SCHEDULES_INX
ORDER_PARTNERS = ORDER_PARTNERS
ORDER_CONDITIONS_IN = ORDER_CONDITIONS_IN.
ORDER_CONDITIONS_INX = ORDER_CONDITIONS_INX.
<code>
但真正控制還是把正確的資訊傳達給 BAPI_SALESORDER_CREATEFROMDAT2
重點分為五項:header、item、Schedule、Condition、Pantner
* Sales document type
ORDER_HEADER_IN-DOC_TYPE = WA_OPENSO-AUART.
ORDER_HEADER_IN-SALES_ORG = WA_OPENSO-VKORG.
ORDER_HEADER_IN-DISTR_CHAN = WA_OPENSO-VTWEG.
ORDER_HEADER_IN-DIVISION = WA_OPENSO-SPART.
ORDER_HEADER_IN-SALES_GRP = WA_OPENSO-VKGRP.
ORDER_HEADER_IN-SALES_OFF = WA_OPENSO-VKBUR.
ORDER_HEADER_IN-REQ_DATE_H = WA_OPENSO-VDATU.
ORDER_HEADER_IN-PURCH_NO_C = WA_OPENSO-BSTNK.
ORDER_HEADER_IN-CURRENCY = WA_OPENSO-WAERK.
ORDER_HEADER_IN-PMTGAR_PRO = WA_OPENSO-PMTGAR_PRO.
ORDER_HEADER_IN-DOC_NUM_FI = WA_OPENSO-DOC_NUM_FI.
ORDER_HEADER_IN-INCOTERMS1 = WA_OPENSO-INCO1.
ORDER_HEADER_IN-INCOTERMS2 = WA_OPENSO-INCO2.
APPEND ORDER_HEADER_IN.
****項目資料***************************
ORDER_ITEMS_IN-ITM_NUMBER = WA_OPENSO-POSNR.
ORDER_ITEMS_IN-MATERIAL = WA_OPENSO-MATNR.
ORDER_ITEMS_IN-BATCH = WA_OPENSO-CHARG.
ORDER_ITEMS_IN-PLANT = WA_OPENSO-WERKS.
ORDER_ITEMS_IN-STORE_LOC = WA_OPENSO-LGORT.
ORDER_ITEMS_IN-PURCH_NO_C = WA_OPENSO-PURCH_NO_C.
ORDER_ITEMS_IN-DLVSCHDUSE = WA_OPENSO-DLVSCHDUSE.
APPEND ORDER_ITEMS_IN.
****Schedule Line資料***************************
ORDER_SCHEDULES_IN-ITM_NUMBER = WA_OPENSO-POSNR.
ORDER_SCHEDULES_IN-REQ_DATE = WA_OPENSO-REQ_DATE.
ORDER_SCHEDULES_IN-REQ_QTY = WA_OPENSO-KWMENG.
APPEND ORDER_SCHEDULES_IN.
****CONDITIONS資料***************************
ORDER_CONDITIONS_IN-ITM_NUMBER = WA_OPENSO-POSNR.
ORDER_CONDITIONS_IN-COND_TYPE = 'ZPR0'.
ORDER_CONDITIONS_IN-COND_VALUE = WA_OPENSO-KBETR.
APPEND ORDER_CONDITIONS_IN.
****Partner資料***************************
**賣方 SP
CLEAR ORDER_PARTNERS.
ORDER_PARTNERS-PARTN_ROLE = 'AG'.
ORDER_PARTNERS-PARTN_NUMB = WA_OPENSO-KUNAG.
APPEND ORDER_PARTNERS .
*出貨對象 SH
CLEAR ORDER_PARTNERS.
ORDER_PARTNERS-PARTN_ROLE = 'WE'.
ORDER_PARTNERS-PARTN_NUMB = WA_OPENSO-KUNWE.
APPEND ORDER_PARTNERS.
*"發票收受人 RE
CLEAR ORDER_PARTNERS.
ORDER_PARTNERS-PARTN_ROLE = 'RE'.
ORDER_PARTNERS-PARTN_NUMB = WA_OPENSO-KUNWE.
APPEND ORDER_PARTNERS.
*付款方 PY
CLEAR ORDER_PARTNERS.
ORDER_PARTNERS-PARTN_ROLE = 'RG'.
ORDER_PARTNERS-PARTN_NUMB = WA_OPENSO-KUNRG.
APPEND ORDER_PARTNERS.
*End Customer Z1
CLEAR ORDER_PARTNERS.
ORDER_PARTNERS-PARTN_ROLE = 'Z1'.
ORDER_PARTNERS-PARTN_NUMB = WA_OPENSO-KUNZ1.
APPEND ORDER_PARTNERS.