Create sales scheduling agreement with FM
FORM frm_create_salesorder TABLES tp_item STRUCTURE zrmxsds001
tp_cond STRUCTURE zrmxsds002
tp_message STRUCTURE zifsret01
USING up_head LIKE zrmxsds000
CHANGING cp_eind TYPE c.
DATA: ls_item LIKE zrmxsds001,
ls_cond LIKE zrmxsds002,
ls_msg LIKE zifsret01.
DATA: wa_header TYPE bapisdhd1, "表頭
wa_headerx TYPE bapisdhd1x, "表頭標誌
wa_partner TYPE bapiparnr, "業務夥伴
wa_item TYPE bapisditm, "行專案
wa_itemx TYPE bapisditmx,
wa_cond TYPE bapicond, "價格條件
wa_condx TYPE bapicondx,
wa_schdl TYPE bapischdl, "交付計劃
wa_schdlx TYPE bapischdlx,
wa_return TYPE bapiret2,
wa_text TYPE bapisdtext. "文字
DATA:
lt_partner TYPE STANDARD TABLE OF bapiparnr,
lt_item TYPE STANDARD TABLE OF bapisditm,
lt_itemx TYPE STANDARD TABLE OF bapisditmx,
lt_schdl TYPE STANDARD TABLE OF bapischdl,
lt_schdlx TYPE STANDARD TABLE OF bapischdlx,
lt_cond TYPE STANDARD TABLE OF bapicond,
lt_condx TYPE STANDARD TABLE OF bapicondx,
lt_return TYPE STANDARD TABLE OF bapiret2,
lt_text LIKE STANDARD TABLE OF bapisdtext.
DATA: lt_sokey TYPE STANDARD TABLE OF zrmxsds015,
ls_sokey TYPE zrmxsds015.
* Header
CLEAR wa_header.
wa_header-doc_type = up_head-auart. "銷售憑證型別
wa_header-sales_org = up_head-vkorg. "銷售組織
wa_header-distr_chan = up_head-vtweg. "分銷渠道
wa_header-division = up_head-spart. "產品組
wa_header-sales_off = up_head-vkbur. "銷售部門
wa_header-sales_dist = up_head-bzirk. "銷售地區
wa_header-incoterms1 = up_head-inco1. "國際貿易條件
wa_header-incoterms2 = up_head-inco2. "國際貿易條件
wa_header-pmnttrms = up_head-zterm. "付款條件
* Header texts
CLEAR: wa_text,lt_text[].
wa_text-itm_number = space.
wa_text-text_id = 'ZC01'.
wa_text-langu = sy-langu.
wa_text-format_col = '*'.
wa_text-text_line = up_head-tknum.
APPEND wa_text TO lt_text.
* Partners
CLEAR: wa_partner, lt_partner[].
wa_partner-partn_role = 'AG'. "售達方
wa_partner-partn_numb = up_head-kunnr_ag.
IF up_head-name1_ag IS NOT INITIAL. "一次性客戶
wa_partner-name = up_head-name1_ag.
wa_partner-country = 'CN'.
ENDIF.
APPEND wa_partner TO lt_partner.
CLEAR wa_partner.
wa_partner-partn_role = 'RE'. "收票方
wa_partner-partn_numb = up_head-kunnr_re.
IF up_head-name1_re IS NOT INITIAL. "一次性客戶
wa_partner-name = up_head-name1_re.
wa_partner-country = 'CN'.
ENDIF.
APPEND wa_partner TO lt_partner.
"RG 付款方
CLEAR wa_partner.
wa_partner-partn_role = 'RG'.
wa_partner-partn_numb = up_head-kunnr_rg.
IF up_head-name1_rg IS NOT INITIAL. "一次性客戶
wa_partner-name = up_head-name1_rg.
wa_partner-country = 'CN'.
ENDIF.
APPEND wa_partner TO lt_partner.
"WE 送達方
CLEAR wa_partner.
wa_partner-partn_role = 'WE'.
wa_partner-partn_numb = up_head-kunnr_we.
IF up_head-name1_we IS NOT INITIAL. "一次性客戶
wa_partner-name = up_head-name1_we.
wa_partner-country = 'CN'.
ENDIF.
APPEND wa_partner TO lt_partner.
*Items
REFRESH: lt_item,lt_cond,lt_schdl.
LOOP AT tp_item INTO ls_item.
CLEAR wa_item.
wa_item-itm_number = ls_item-posnr.
wa_item-material = ls_item-mabnr. "物料
wa_item-sales_unit = ls_item-vrkme. "計量單位
wa_item-plant = ls_item-werks. "工廠
wa_item-store_loc = ls_item-lgort. "庫存地
wa_item-val_type = ls_item-bwtar. "評估型別
wa_item-ship_type = 'Z1'. "裝運型別-汽車
APPEND wa_item TO lt_item.
CLEAR wa_schdl.
wa_schdl-itm_number = ls_item-posnr.
wa_schdl-req_qty = ls_item-kwmeng. "數量
APPEND wa_schdl TO lt_schdl.
CLEAR ls_sokey.
ls_sokey-vbeln = up_head-vbeln.
ls_sokey-posnr = ls_item-posnr.
APPEND ls_sokey TO lt_sokey.
ENDLOOP.
*Item Conditions
LOOP AT tp_cond INTO ls_cond.
CLEAR: wa_cond.
wa_cond-itm_number = ls_cond-posnr.
wa_cond-cond_type = ls_cond-kschl. "定價條件
wa_cond-cond_value = ls_cond-kbetr. "價格
wa_cond-currency = ls_cond-koein. "貨幣或%
wa_cond-cond_unit = ls_cond-kmein. "條件單位
wa_cond-cond_p_unt = ls_cond-kpein. "條件定價單位
APPEND wa_cond TO lt_cond.
ENDLOOP.
* Call BAPI
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
salesdocumentin = up_head-vbeln
order_header_in = wa_header
* ORDER_HEADER_INX =
* SENDER =
* BINARY_RELATIONSHIPTYPE =
* INT_NUMBER_ASSIGNMENT =
* BEHAVE_WHEN_ERROR =
* LOGIC_SWITCH =
* TESTRUN =
* CONVERT = ' '
* IMPORTING
* SALESDOCUMENT =
TABLES
return = lt_return
order_items_in = lt_item
* ORDER_ITEMS_INX =
order_partners = lt_partner
order_schedules_in = lt_schdl
* ORDER_SCHEDULES_INX =
order_conditions_in = lt_cond
* ORDER_CONDITIONS_INX =
* ORDER_CFGS_REF =
* ORDER_CFGS_INST =
* ORDER_CFGS_PART_OF =
* ORDER_CFGS_VALUE =
* ORDER_CFGS_BLOB =
* ORDER_CFGS_VK =
* ORDER_CFGS_REFINST =
* ORDER_CCARD =
order_text = lt_text
* ORDER_KEYS =
* EXTENSIONIN =
* PARTNERADDRESSES =
.
* 處理錯誤訊息:透過判斷訊息的型別,來判斷BAPI是否成功
LOOP AT lt_return INTO wa_return.
CLEAR ls_msg.
ls_msg-class = 'BUS'.
ls_msg-msgtyp = wa_return-type.
ls_msg-msgno = wa_return-number.
ls_msg-msgtxt = wa_return-message.
APPEND ls_msg TO tp_message.
IF wa_return-type EQ 'E' OR
wa_return-type = 'A' OR
wa_return = 'X'.
cp_eind = 'X'. "失敗
ENDIF.
ENDLOOP.
IF cp_eind NE 'X'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
COMMIT WORK AND WAIT.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
ENDIF.
EndFrom.
引自:http://www.cnblogs.com/zhumk/archive/2010/08/23/1806236.html
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/21882360/viewspace-1057762/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 精讀《Scheduling in React》React
- 7.2 FM Index MatchingIndex
- SAP Cloud for Customer裡Sales Order和Sales Quote的建模方式Cloud
- SCM605--Controlling Sales Documents with Sales Document Types
- 樹莓派上使用Pi-FM-RDS工具打造FM調頻電臺樹莓派
- 荔枝FM前端面試題前端面試題
- FM的正交解調法
- FM收聽新方式?多聽FM將釋出全新車載智慧硬體
- How to get propose products in Sales Order
- What is the difference between gross sales and revenue?ROS
- Additional Data Tab in Sales Order
- SAP CRM Fiori應用如何啟用Sales Office和Sales Group兩個欄位
- 荔枝FM的前端筆試題前端筆試
- 營銷屬性表和fm
- marketing和sales的區別
- FM演算法python實現演算法Python
- Swift仿寫喜馬拉雅FMSwift
- python實現FM演算法Python演算法
- Sora AI Video Generator by Sora.FMSoraAIIDE
- 淺談SAP Cloud for Sales 自動化Cloud
- 【Lintcode】1793. Balanced Sales Array
- Sales Order Form · Additional Line InformationORM
- SCM600--Master Data in Sales and DistributionAST
- Scheduling and Traffic Shaping 學習筆記(一)API筆記
- Create DatabaseDatabase
- SAP SD (Sales & Distribution) Training TutorialAI
- T-codes of sales report and information enquiryORMENQUI
- IT售前故事—Sales/AE一道去打獵
- [轉]Sales Order 中的User Exit開發
- create index/create index online區別Index
- create_singlethread_workqueue, create_workqueuethread
- 荔枝FM IPO招股書及簡要資料
- 【Leetcode】1029. Two City SchedulingLeetCode
- P2949 [USACO09OPEN] Work Scheduling G
- Order-level sales credit total () must equal 100%.
- SCM600---Enterprise Structures in Sales and DistributionStruct
- SCM605--Enterprise Structure in Sales and DistributionStruct
- SAP一句話入門:Sales and Distribution