SAP IDOC开发
生活随笔
收集整理的這篇文章主要介紹了
SAP IDOC开发
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
創(chuàng)建IDOC:
?? 第一步:WE31 創(chuàng)建IDOC所包含的字段.
?? 第二步:WE30 創(chuàng)建IDOC 把Segment分配給IDOC
第三步:WE81?創(chuàng)建信息類型
第四步:WE82?把IDOC類型與信息類型對應(yīng). 第五步:WE57 Assign Message & Idoc Type to a Function Module for Data Process 第六步:SM59 Define a RFC connection for Idoc transfer 第七步:WE21 Define a Port ( Assign a RFC destination which created in SM59 ) 第八步:WE41/42 Creat Process Code 第九步:WE20 Define a Partner Profiles( Also creat a Outbound parameters with Port, or Inbound parameters with Process code ) 管理IDOC:
?? WE02?顯示IDOC,可以根據(jù)時間,IDOC類型查找IDOC,查看成功,出錯信息。 WE46?IDOC管理(出\入) WE60?IDOC類型文檔(可以查看IDOC結(jié)構(gòu),和每個字段的描述.? WE19?根據(jù)IDOC號進行IDOC處理,可以修改IDOC值進行補發(fā)動作,處理分為內(nèi)向和外向。
消息配置: WE20 配置伙伴消息進和出IDOC類型 WE21 配置伙伴。 官方介紹: What is a IDOC?
An IDoc is simply a data container that is used to exchange information between any two processes that can understand the syntax and semantics of the data. IDoc is not a process.
??IDocs are stored in the database. In the SAP system, IDocs are stored in database tables.
??IDocs are independent of the sending and receiving systems.
??IDocs are independent of the direction of data exchange. An IDoc Type is SAP's format for data being moved between applications. Essentially, SAP has defined what a sales order, financial statement, invoice, etc will look like electronically. This includes how fields are grouped together (segments), the order and hierarchy of these groupings, and the format of each individual field.
If you're familiar with EDI at all, then an IDoc will look very familiar to you. Nearly everything you're used to is there: from segment name to allowable codes to min/max occurs. It is important to note that an IDoc Type is really just a structure defined on the system and given a name (i.e., ORDERS04). An actual IDoc, however, consists of data, which fits within the defined structure of the IDoc Type. This IDoc is identified by a number rather than by a type. Creation of IDOCs Transaction code: WE30 Steps of Defining Segment
Creating Segment : Tcode - WE31 Creating Message Type : Tcode - we81 Assigning Message type to Idoc type: Tcode - we82 Process The two processes for IDoc are Outbound Process and Inbound Process.
Outbound Process
When the data is sent out from the system, the process is called Outbound Process and the IDoc is known as Outbound IDoc.
Inbound Process
When the data is coming in, the process is called Inbound Process and the IDoc is known as Inbound IDoc. Outbound Process (Sending System) Steps :?? 1) Goto Tcode SALE:
Creating the logical system Click on Sending & Receiving Systems à Select Logical Systems--Here Define the Logical Systems?a Click on Execute Button
Go for New Entries 1)??System Name : LOG1 prescription: Sending System
??System Name : LOG2 prescription: Receiving System
?Press Enter & Save it will ask for Request if you want new request create new request or press continue for transferring the objects.
Assigning Client to the Logical System: Select Assign Client to Logical Systems Client?????????: Sending System
Logical System?: LOG1
and also Client? ?????? : Receiving System
System? ?????? : LOG2 Save this Data.
Step 2) For RFC Creation:
Goto Tcode SM59 and??Select R/3 Connects
Click on create Button
RFC Destination Name should be same as partner's logical system name and case sensitive to create the ports automatically while generating the partner profiles
Give the information for required fields:
RFC Destination? ? : LOG2
Connection type? ? : 3
Target Host????????: sappdc.wipro.com System No??????????: 00 Client?????????????: 210
User???????????????: Login user name5 s6 q6 o; y- O: [??g+ }- Z
Password???????????:
Save this & Test it and Remote Login
Step 3) Goto Tcode BD64:
Click on the change button>Click on the create model view Short Text: model view Technical Name: LMOD
Save this & press ok
Select just created model view Name: "LMOD"
Goto add message type Model Name??: LMOD Sender? ?? ?? ???: LOG1
Receiver? ?? ?? ?: LOG2
Message type: ZAZHARMESS Save and press Enter 4) Goto Tcode BD82:
Give Model View? ?: LMOD
Partner system? ???: LOG2
Execute this by pressing F8
It will gives you sending system port No:??A00000000089 (Like)
5) Goto Tcode BD64:
Select the model view
Goto >Edit >model view > Distribute
Press ok & Press Enter.
Run your Zprogram REPORT??ZIDOC1?. SPAN {font-family: "新宋體";font-size: 10pt;color: #000000;background: #CCE8CF;}.L0S31 {font-style. italic;color: #808080;}.L0S32 {color: #3399FF;}.L0S33 {color: #4DA619;}.L0S52 {color: #0000FF;}DATA:?BEGIN?OF?imara?OCCURS?0,
???????matnr?LIKE?mara-matnr,
???????mtart?LIKE?mara-mtart,
??????END?OF?imara.
DATA:?wamas_con?LIKE?edidc,
imas_data?LIKE?edidd?OCCURS?0?WITH?HEADER?LINE,
icom_con?LIKE?edidc?OCCURS?0?WITH?HEADER?LINE.
PARAMETERS:?e_matnr?LIKE?mara-matnr,
??????e_msgtyp?LIKE?edidc-mestyp,
??????e_rcvprn?LIKE?edidc-rcvprn.
*?retrive?app.?data?from?DB
SELECT?matnr?mtart?FROM?mara?INTO?TABLE?imara
???WHERE?matnr?=?e_matnr.
*Master?idoc?control?record
wamas_con-rcvprt?=?'LS'.
wamas_con-rcvprn?=?e_rcvprn.
wamas_con-idoctp?=?'ZAZHARIDOC'.
wamas_con-mestyp?=?e_msgtyp.
*?master?idoc?data?records
LOOP?AT?imara.
??imas_data-segnam?=?'ZAZHARSEG'.
??MOVE?imara?TO?imas_data-sdata?.
??APPEND?imas_data.
ENDLOOP.
CALL?FUNCTION?'MASTER_IDOC_DISTRIBUTE'
??EXPORTING
????master_idoc_control????????=?wamas_con
??TABLES
????communication_idoc_control?=?icom_con
????master_idoc_data???????????=?imas_data.
COMMIT?WORK. 6) Verifying Transfer of IDOCs Tcode - we05
ALE/IDOC Status Codes (outbound): 01> IDoc Added
30 > IDoc ready for dispatch
29 >Error in ALE service Layer
12 >Dispatch ok
03 > Data passed to port ok. Inbound Process (Receiving System) Steps:
Do the same step as you did in sending system
9 |9 S! c+ a??{
>??Creating IDoc >? Defining the Segment
>? Creating Message Type >? Assigning the Message Type
>? Defining the Logical System >? Assigning the Logical System >? Creating the Distribution Model
1) Goto Tcode - we57 Assign function module to IDoc type
Module: Function module
Basic type:??
Message type:
Direction: 2 (inbound)
2) Creating Inbound process code - we42
3) Verifying Idoc List Tcode - we05 4) ALE/IDOC Status Codes (Inbound): 50 >IDoc Added 51 >Application Document not posted 64 >IDoc ready to be transferred to application
62 >IDoc passed to application
53?>Application Document posted
----------------------實例------------------------------------------------
簡而言之,IDOC是類似XML的一種SAP系統(tǒng)與其他系統(tǒng)的一種集成工具。
假設(shè)I04和I02是同一個集團下兩個不同子公司的SAP系統(tǒng),I04需要將其采購訂單信息及時發(fā)送給I02。下面簡單介紹IDOC的設(shè)置步驟,為了避免混淆,我的命名都比較特別。
1,設(shè)置IDOC Type.
?(1) WE31,創(chuàng)建segment,類似于創(chuàng)建XML的結(jié)點及結(jié)點屬性。 這里先輸入YPOHEAD,點擊創(chuàng)建,在接下來的屏幕中,錄入EBELN, BUKRS, BEDAT等字段及他們對應(yīng)的data element;接著創(chuàng)建YPOITEM,輸入EBELN, EBELP, MATNR, MENGE, MEINS等字段及他們對應(yīng)的data element。 保存后用SE12查看你將發(fā)現(xiàn),系統(tǒng)自動添加了YPOHEAD和YPOITEM兩個結(jié)構(gòu),每個字段都成了CHAR類型,長度就是WE31中的EXPORT LENG。
?(2) WE30, 創(chuàng)建IDOC Type,定義結(jié)點間的相互邏輯關(guān)系. 先輸入YPOIDOC,然后點擊創(chuàng)建,緊跟著點擊create new進入。在主界面中,先點擊創(chuàng)建按鈕,將YPOHEAD添加,設(shè)置Mandatory seg打勾,min = 1, max = 1,代表我們每個IDOC僅包含一張采購訂單。然后在YPOHEAD下添加YPOITEM,同樣的Mandatory seg打勾,min = 1, max = 99999. 2,創(chuàng)建Message Type. (1) WE81,創(chuàng)建Message Type.
??? 先切換到編輯狀態(tài),然后點擊New Entries,輸入YPO即可。
?(2) WE82,,關(guān)聯(lián)Message Type和IDOC Type. 3,創(chuàng)建到I02的端口. 首先確保系統(tǒng)內(nèi)已經(jīng)有到I02的R/3 Connection(SM59),如果沒有則先創(chuàng)建一個名為I02001 接著WE21創(chuàng)建Port,類型TRANSACTIONAL RFC,名為I02PORT,RFC destination則填寫I02001。
?4,SALE,創(chuàng)建Logical System.? SALE, Sending and Receiving Systems,Logical Systems, define logical systems(T-code:BD54),新增一個logical system,名為I02LS,這將作為下一步的Partner。 Define logical systems下方,有Assign Client to logical system,這里可針對本系統(tǒng)(I04)定義logical system,作為發(fā)送IDOC時的發(fā)送方標(biāo)識,我對Client 001的定義是I04LS.
?5,WE20,定義我們的Partner profile. 在PARTNER TYPE為logical system下,創(chuàng)建一個patner no為I02LS的partner,type填寫LS。 下面的Permitted agent,填寫US(User),Agent為你自己的用戶名或某basis人員用戶名。 然后,點擊outbound下方的加號,創(chuàng)建一個outbound parameter。Message Type為YPO,receiver port為I02PORT,output mode選擇transfer idoc immed.,Basic Type填寫YPOIDOC,保存即可。
?6,編程發(fā)送IDOC
?? 設(shè)置了這么多,真累啊,總算可以寫程序了,是不是很開心呢?
程序的思路就是,把每個IDOC結(jié)點按字符串形式逐個添加,而字符串的添加次序自然也體現(xiàn)了IDOC結(jié)點間的邏輯關(guān)系。代碼如下, DATA: ls_pohead TYPE ypohead,? ls_poitem TYPE ypoitem,? ls_edidc TYPE edidc, lt_edidc TYPE TABLE OF edidc, lt_edidd TYPE TABLE OF edidd WITH HEADER LINE. CLEAR ls_edidc.
*系統(tǒng)根據(jù)下面4行即可與WE20設(shè)置關(guān)聯(lián)起來
ls_edidc-mestyp = 'YPO'.???? "Message Type ls_edidc-idoctp = 'YPOIDOC'. "IDOC Type ls_edidc-rcvprn = 'I02LS'.?? "partner Number of Recipient6 ls_edidc-rcvprt = 'LS'.????? "partner Type of Receiver
*添加IDOC結(jié)點 CLEAR lt_edidd.
lt_edidd-segnam = 'YPOHEAD'."結(jié)點名稱 lt_edidd-dtint2 = 0.
CLEAR ls_pohead. ls_pohead-ebeln = '4001122334'.
ls_pohead-bukrs = '0400'. ls_pohead-bedat = '20090630'.
lt_edidd-sdata = ls_pohead. "結(jié)點內(nèi)容
APPEND lt_edidd. CLEAR lt_edidd.
lt_edidd-segnam = 'YPOITEM'. lt_edidd-dtint2 = 0.
CLEAR ls_poitem.
ls_poitem-ebeln = '4001122334'.
ls_poitem-ebelp = '0001'. ls_poitem-matnr = '000000000000004527'.
ls_poitem-menge = '3'.
ls_poitem-meins = 'ST'. lt_edidd-sdata = ls_poitem. APPEND lt_edidd.
CLEAR lt_edidd.
lt_edidd-segnam = 'YPOITEM'. lt_edidd-dtint2 = 0. CLEAR ls_poitem. ls_poitem-ebeln = '4001122334'. ls_poitem-ebelp = '0002'.
ls_poitem-matnr = '000000000000009289'.
ls_poitem-menge = '5'.8 P( Y; S' _9 |
ls_poitem-meins = 'M'.
lt_edidd-sdata = ls_poitem.
APPEND lt_edidd.
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' EXPORTING
??? master_idoc_control? ?? ?? ?? ?= ls_edidc "Export
? TABLES
??? communication_idoc_control? ???= lt_edidc "Import
??? master_idoc_data? ?? ?? ?? ?? ?= lt_edidd "Export
??EXCEPTIONS"? error_in_idoc_control? ?? ?? ? = 1 error_writing_idoc_status? ?? ?= 2 error_in_idoc_data? ?? ?? ?? ? = 3 sending_logical_system_unknown = 4,? OTHERS? ?? ?? ?? ?? ?? ?? ?? ? = 5.
IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. COMMIT WORK. WRITE: 'Idoc sent:'. LOOP AT lt_edidc INTO ls_edidc. NEW-LINE. WRITE: 'Idoc number is', ls_edidc-docnum, '; receiver partner is', ls_edidc-rcvprn,
'; sender partner',ls_edidc-sndprn. ENDLOOP. ENDIF. 7,查看IDOC. WE05可以查看我們剛剛發(fā)送的IDOC, BD87還可對IDOC進行一些處理。
---------------------------------------實例----------------------------------Inbound Idoc 這里將繼續(xù)沿用上篇文章的例子,講述I02對接收到的采購訂單信息進行的相關(guān)處理。
1,創(chuàng)建IDOC Type和Message Type.
與上篇Outbound Idoc中的前兩個步驟完全一樣。
2,創(chuàng)建一個function:Y_IDOC_PO_PROCESS. 當(dāng)IDOC設(shè)置完畢之后,SAP可以自動調(diào)用該Funtion Module處理IDOC。所以這個函數(shù)的接口都是規(guī)范的。 下面步驟中將介紹的tcode:BD51中可以查詢到很多Inbound Function,比如IDOC_INPUT_BBP_IV,可參照創(chuàng)建我們的接口。
接下來就可以寫入我們的代碼,根據(jù)IDOC內(nèi)容,創(chuàng)建相應(yīng)的銷售訂單。為了簡化,這里我們僅僅將其存到數(shù)據(jù)庫表里面,請先創(chuàng)建兩個表Y02_POHEAD和Y02_POITEM,字段參考WE31中的YPOHEAD和YPOITEM。然后寫入下面代碼: DATA: lv_subrc LIKE sy-subrc,?? ls_chead TYPE ypohead, ls_citem TYPE ypoitem,
ls_pohead TYPE y02_pohead, lt_poitem TYPE TABLE OF y02_poitem WITH HEADER LINE.
CLEAR idoc_contrl. READ TABLE idoc_contrl INDEX 1. IF idoc_contrl-mestyp <> 'YPO'.
??? RAISE wrong_function_called.
ENDIF.
LOOP AT idoc_contrl.
CLEAR: ls_pohead, lt_poitem[].
LOOP AT idoc_data WHERE docnum = idoc_contrl-docnum.
CASE idoc_data-segnam. WHEN 'YPOHEAD'.
????????? CLEAR: ls_chead, ls_pohead.
????????? ls_chead = idoc_data-sdata. MOVE-CORRESPONDING ls_chead TO ls_pohead.
????????WHEN 'YPOITEM'. CLEAR: ls_citem, lt_poitem.
????????? ls_citem = idoc_data-sdata. MOVE-CORRESPONDING ls_citem TO lt_poitem. APPEND lt_poitem. WHEN OTHERS. ENDCASE. ENDLOOP.
??? lv_subrc = 0.
??? INSERT y02_pohead FROM ls_pohead. IF sy-subrc = 0.
??????INSERT y02_poitem FROM TABLE lt_poitem.
??????lv_subrc = sy-subrc.
??? ELSE. "訂單號已經(jīng)存在
??????lv_subrc = sy-subrc. ENDIF.
??? IF lv_subrc = 0.?? COMMIT WORK.
??????CLEAR idoc_status.
??????idoc_status-docnum = idoc_contrl-docnum.
??????idoc_status-status = '53'. "IDOC處理成功 APPEND idoc_status.
??? ELSE. ROLLBACK WORK. CLEAR idoc_status.
??????idoc_status-docnum = idoc_contrl-docnum.
??????idoc_status-status = '51'. "IDOC不成功 idoc_status-msgty = 'E'. "錯誤信息
??????idoc_status-msgid = 'YMSG'. idoc_status-msgno = '001'. APPEND idoc_status. ENDIF.
??ENDLOOP. 3,在BD51中注冊我們的Function Module.
在編輯狀態(tài)下,點擊New Entries,填入函數(shù)名Y_IDOC_PO_PROCESS,Input Type=1即可。 4,在WE57中將Function Module與IDOC Type/Message Type關(guān)聯(lián)
點擊New Entries,Function Module輸入Y_IDOC_PO_PROCESS,其下的Type填寫F;IDOC Type下的Basic Type填寫YPOIDOC;Message Type填寫YPO;Direction填寫2(Inbound)。
5,WE42,創(chuàng)建Inbound Process Code. 注意該步驟必須在BD51和WE57之后,否則將出現(xiàn)錯誤提示。 創(chuàng)建新條目,Process Code輸入YPC_PO,在Option ALE下選擇Processing with ALE service,在Processing Type下選擇function module。保存后,在隨后的窗口中,輸入Inbound Module為Y_IDOC_PO_PROCESS。
6,WE20,維護Partner Profiles. 首先確保SALE中已經(jīng)維護好了對應(yīng)于接收方的Logical System,假設(shè)名稱為I04LS。(WE05查看您的Inbound IDOC, 均可看到其Partner名稱,這就是我們所需要的。本步驟與上篇的WE20類似,不同的是,這里是維護從I04LS過來的Inbound Parameters。Message Type輸入YPO,Process Type輸入YPC_PO,然后選中"Trigger immediately"即可。
7,至此,我們的設(shè)置已經(jīng)完畢。系統(tǒng)接收到從I04傳來的IDOC后即會立刻處理。 同時,各位針對上篇做過練習(xí)的朋友,系統(tǒng)中應(yīng)該會遺留幾個處于出錯狀態(tài)的IDOC吧?可以用BD87,在主界面上選中結(jié)點YPO后,點擊Process按鈕,一次性處理。處理前,順便在SE37中打開Y_IDOC_PO_PROCESS并設(shè)置幾個斷點即可調(diào)試。
補充: (1)如果狀態(tài)碼為56,則應(yīng)該是您的WE20沒設(shè)置好;
(2)由于上面代碼中控制了不能插入同樣的采購單號,所以只有一個Inbound IDOC將處理成功(狀態(tài)碼53),其余將失敗(狀態(tài)碼51)。只要新發(fā)送的IDOC賦于不同的采購單號即可避免。 (3)Outbound的狀態(tài)碼是0-50,03代表OK;Inbound的狀態(tài)碼則是50-99,53代表OK。
?? 第一步:WE31 創(chuàng)建IDOC所包含的字段.
?? 第二步:WE30 創(chuàng)建IDOC 把Segment分配給IDOC
第三步:WE81?創(chuàng)建信息類型
第四步:WE82?把IDOC類型與信息類型對應(yīng). 第五步:WE57 Assign Message & Idoc Type to a Function Module for Data Process 第六步:SM59 Define a RFC connection for Idoc transfer 第七步:WE21 Define a Port ( Assign a RFC destination which created in SM59 ) 第八步:WE41/42 Creat Process Code 第九步:WE20 Define a Partner Profiles( Also creat a Outbound parameters with Port, or Inbound parameters with Process code ) 管理IDOC:
?? WE02?顯示IDOC,可以根據(jù)時間,IDOC類型查找IDOC,查看成功,出錯信息。 WE46?IDOC管理(出\入) WE60?IDOC類型文檔(可以查看IDOC結(jié)構(gòu),和每個字段的描述.? WE19?根據(jù)IDOC號進行IDOC處理,可以修改IDOC值進行補發(fā)動作,處理分為內(nèi)向和外向。
消息配置: WE20 配置伙伴消息進和出IDOC類型 WE21 配置伙伴。 官方介紹: What is a IDOC?
An IDoc is simply a data container that is used to exchange information between any two processes that can understand the syntax and semantics of the data. IDoc is not a process.
??IDocs are stored in the database. In the SAP system, IDocs are stored in database tables.
??IDocs are independent of the sending and receiving systems.
??IDocs are independent of the direction of data exchange. An IDoc Type is SAP's format for data being moved between applications. Essentially, SAP has defined what a sales order, financial statement, invoice, etc will look like electronically. This includes how fields are grouped together (segments), the order and hierarchy of these groupings, and the format of each individual field.
If you're familiar with EDI at all, then an IDoc will look very familiar to you. Nearly everything you're used to is there: from segment name to allowable codes to min/max occurs. It is important to note that an IDoc Type is really just a structure defined on the system and given a name (i.e., ORDERS04). An actual IDoc, however, consists of data, which fits within the defined structure of the IDoc Type. This IDoc is identified by a number rather than by a type. Creation of IDOCs Transaction code: WE30 Steps of Defining Segment
Creating Segment : Tcode - WE31 Creating Message Type : Tcode - we81 Assigning Message type to Idoc type: Tcode - we82 Process The two processes for IDoc are Outbound Process and Inbound Process.
Outbound Process
When the data is sent out from the system, the process is called Outbound Process and the IDoc is known as Outbound IDoc.
Inbound Process
When the data is coming in, the process is called Inbound Process and the IDoc is known as Inbound IDoc. Outbound Process (Sending System) Steps :?? 1) Goto Tcode SALE:
Creating the logical system Click on Sending & Receiving Systems à Select Logical Systems--Here Define the Logical Systems?a Click on Execute Button
Go for New Entries 1)??System Name : LOG1 prescription: Sending System
??System Name : LOG2 prescription: Receiving System
?Press Enter & Save it will ask for Request if you want new request create new request or press continue for transferring the objects.
Assigning Client to the Logical System: Select Assign Client to Logical Systems Client?????????: Sending System
Logical System?: LOG1
and also Client? ?????? : Receiving System
System? ?????? : LOG2 Save this Data.
Step 2) For RFC Creation:
Goto Tcode SM59 and??Select R/3 Connects
Click on create Button
RFC Destination Name should be same as partner's logical system name and case sensitive to create the ports automatically while generating the partner profiles
Give the information for required fields:
RFC Destination? ? : LOG2
Connection type? ? : 3
Target Host????????: sappdc.wipro.com System No??????????: 00 Client?????????????: 210
User???????????????: Login user name5 s6 q6 o; y- O: [??g+ }- Z
Password???????????:
Save this & Test it and Remote Login
Step 3) Goto Tcode BD64:
Click on the change button>Click on the create model view Short Text: model view Technical Name: LMOD
Save this & press ok
Select just created model view Name: "LMOD"
Goto add message type Model Name??: LMOD Sender? ?? ?? ???: LOG1
Receiver? ?? ?? ?: LOG2
Message type: ZAZHARMESS Save and press Enter 4) Goto Tcode BD82:
Give Model View? ?: LMOD
Partner system? ???: LOG2
Execute this by pressing F8
It will gives you sending system port No:??A00000000089 (Like)
5) Goto Tcode BD64:
Select the model view
Goto >Edit >model view > Distribute
Press ok & Press Enter.
Run your Zprogram REPORT??ZIDOC1?. SPAN {font-family: "新宋體";font-size: 10pt;color: #000000;background: #CCE8CF;}.L0S31 {font-style. italic;color: #808080;}.L0S32 {color: #3399FF;}.L0S33 {color: #4DA619;}.L0S52 {color: #0000FF;}DATA:?BEGIN?OF?imara?OCCURS?0,
???????matnr?LIKE?mara-matnr,
???????mtart?LIKE?mara-mtart,
??????END?OF?imara.
DATA:?wamas_con?LIKE?edidc,
imas_data?LIKE?edidd?OCCURS?0?WITH?HEADER?LINE,
icom_con?LIKE?edidc?OCCURS?0?WITH?HEADER?LINE.
PARAMETERS:?e_matnr?LIKE?mara-matnr,
??????e_msgtyp?LIKE?edidc-mestyp,
??????e_rcvprn?LIKE?edidc-rcvprn.
*?retrive?app.?data?from?DB
SELECT?matnr?mtart?FROM?mara?INTO?TABLE?imara
???WHERE?matnr?=?e_matnr.
*Master?idoc?control?record
wamas_con-rcvprt?=?'LS'.
wamas_con-rcvprn?=?e_rcvprn.
wamas_con-idoctp?=?'ZAZHARIDOC'.
wamas_con-mestyp?=?e_msgtyp.
*?master?idoc?data?records
LOOP?AT?imara.
??imas_data-segnam?=?'ZAZHARSEG'.
??MOVE?imara?TO?imas_data-sdata?.
??APPEND?imas_data.
ENDLOOP.
CALL?FUNCTION?'MASTER_IDOC_DISTRIBUTE'
??EXPORTING
????master_idoc_control????????=?wamas_con
??TABLES
????communication_idoc_control?=?icom_con
????master_idoc_data???????????=?imas_data.
COMMIT?WORK. 6) Verifying Transfer of IDOCs Tcode - we05
ALE/IDOC Status Codes (outbound): 01> IDoc Added
30 > IDoc ready for dispatch
29 >Error in ALE service Layer
12 >Dispatch ok
03 > Data passed to port ok. Inbound Process (Receiving System) Steps:
Do the same step as you did in sending system
9 |9 S! c+ a??{
>??Creating IDoc >? Defining the Segment
>? Creating Message Type >? Assigning the Message Type
>? Defining the Logical System >? Assigning the Logical System >? Creating the Distribution Model
1) Goto Tcode - we57 Assign function module to IDoc type
Module: Function module
Basic type:??
Message type:
Direction: 2 (inbound)
2) Creating Inbound process code - we42
3) Verifying Idoc List Tcode - we05 4) ALE/IDOC Status Codes (Inbound): 50 >IDoc Added 51 >Application Document not posted 64 >IDoc ready to be transferred to application
62 >IDoc passed to application
53?>Application Document posted
----------------------實例------------------------------------------------
簡而言之,IDOC是類似XML的一種SAP系統(tǒng)與其他系統(tǒng)的一種集成工具。
假設(shè)I04和I02是同一個集團下兩個不同子公司的SAP系統(tǒng),I04需要將其采購訂單信息及時發(fā)送給I02。下面簡單介紹IDOC的設(shè)置步驟,為了避免混淆,我的命名都比較特別。
1,設(shè)置IDOC Type.
?(1) WE31,創(chuàng)建segment,類似于創(chuàng)建XML的結(jié)點及結(jié)點屬性。 這里先輸入YPOHEAD,點擊創(chuàng)建,在接下來的屏幕中,錄入EBELN, BUKRS, BEDAT等字段及他們對應(yīng)的data element;接著創(chuàng)建YPOITEM,輸入EBELN, EBELP, MATNR, MENGE, MEINS等字段及他們對應(yīng)的data element。 保存后用SE12查看你將發(fā)現(xiàn),系統(tǒng)自動添加了YPOHEAD和YPOITEM兩個結(jié)構(gòu),每個字段都成了CHAR類型,長度就是WE31中的EXPORT LENG。
?(2) WE30, 創(chuàng)建IDOC Type,定義結(jié)點間的相互邏輯關(guān)系. 先輸入YPOIDOC,然后點擊創(chuàng)建,緊跟著點擊create new進入。在主界面中,先點擊創(chuàng)建按鈕,將YPOHEAD添加,設(shè)置Mandatory seg打勾,min = 1, max = 1,代表我們每個IDOC僅包含一張采購訂單。然后在YPOHEAD下添加YPOITEM,同樣的Mandatory seg打勾,min = 1, max = 99999. 2,創(chuàng)建Message Type. (1) WE81,創(chuàng)建Message Type.
??? 先切換到編輯狀態(tài),然后點擊New Entries,輸入YPO即可。
?(2) WE82,,關(guān)聯(lián)Message Type和IDOC Type. 3,創(chuàng)建到I02的端口. 首先確保系統(tǒng)內(nèi)已經(jīng)有到I02的R/3 Connection(SM59),如果沒有則先創(chuàng)建一個名為I02001 接著WE21創(chuàng)建Port,類型TRANSACTIONAL RFC,名為I02PORT,RFC destination則填寫I02001。
?4,SALE,創(chuàng)建Logical System.? SALE, Sending and Receiving Systems,Logical Systems, define logical systems(T-code:BD54),新增一個logical system,名為I02LS,這將作為下一步的Partner。 Define logical systems下方,有Assign Client to logical system,這里可針對本系統(tǒng)(I04)定義logical system,作為發(fā)送IDOC時的發(fā)送方標(biāo)識,我對Client 001的定義是I04LS.
?5,WE20,定義我們的Partner profile. 在PARTNER TYPE為logical system下,創(chuàng)建一個patner no為I02LS的partner,type填寫LS。 下面的Permitted agent,填寫US(User),Agent為你自己的用戶名或某basis人員用戶名。 然后,點擊outbound下方的加號,創(chuàng)建一個outbound parameter。Message Type為YPO,receiver port為I02PORT,output mode選擇transfer idoc immed.,Basic Type填寫YPOIDOC,保存即可。
?6,編程發(fā)送IDOC
?? 設(shè)置了這么多,真累啊,總算可以寫程序了,是不是很開心呢?
程序的思路就是,把每個IDOC結(jié)點按字符串形式逐個添加,而字符串的添加次序自然也體現(xiàn)了IDOC結(jié)點間的邏輯關(guān)系。代碼如下, DATA: ls_pohead TYPE ypohead,? ls_poitem TYPE ypoitem,? ls_edidc TYPE edidc, lt_edidc TYPE TABLE OF edidc, lt_edidd TYPE TABLE OF edidd WITH HEADER LINE. CLEAR ls_edidc.
*系統(tǒng)根據(jù)下面4行即可與WE20設(shè)置關(guān)聯(lián)起來
ls_edidc-mestyp = 'YPO'.???? "Message Type ls_edidc-idoctp = 'YPOIDOC'. "IDOC Type ls_edidc-rcvprn = 'I02LS'.?? "partner Number of Recipient6 ls_edidc-rcvprt = 'LS'.????? "partner Type of Receiver
*添加IDOC結(jié)點 CLEAR lt_edidd.
lt_edidd-segnam = 'YPOHEAD'."結(jié)點名稱 lt_edidd-dtint2 = 0.
CLEAR ls_pohead. ls_pohead-ebeln = '4001122334'.
ls_pohead-bukrs = '0400'. ls_pohead-bedat = '20090630'.
lt_edidd-sdata = ls_pohead. "結(jié)點內(nèi)容
APPEND lt_edidd. CLEAR lt_edidd.
lt_edidd-segnam = 'YPOITEM'. lt_edidd-dtint2 = 0.
CLEAR ls_poitem.
ls_poitem-ebeln = '4001122334'.
ls_poitem-ebelp = '0001'. ls_poitem-matnr = '000000000000004527'.
ls_poitem-menge = '3'.
ls_poitem-meins = 'ST'. lt_edidd-sdata = ls_poitem. APPEND lt_edidd.
CLEAR lt_edidd.
lt_edidd-segnam = 'YPOITEM'. lt_edidd-dtint2 = 0. CLEAR ls_poitem. ls_poitem-ebeln = '4001122334'. ls_poitem-ebelp = '0002'.
ls_poitem-matnr = '000000000000009289'.
ls_poitem-menge = '5'.8 P( Y; S' _9 |
ls_poitem-meins = 'M'.
lt_edidd-sdata = ls_poitem.
APPEND lt_edidd.
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' EXPORTING
??? master_idoc_control? ?? ?? ?? ?= ls_edidc "Export
? TABLES
??? communication_idoc_control? ???= lt_edidc "Import
??? master_idoc_data? ?? ?? ?? ?? ?= lt_edidd "Export
??EXCEPTIONS"? error_in_idoc_control? ?? ?? ? = 1 error_writing_idoc_status? ?? ?= 2 error_in_idoc_data? ?? ?? ?? ? = 3 sending_logical_system_unknown = 4,? OTHERS? ?? ?? ?? ?? ?? ?? ?? ? = 5.
IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. COMMIT WORK. WRITE: 'Idoc sent:'. LOOP AT lt_edidc INTO ls_edidc. NEW-LINE. WRITE: 'Idoc number is', ls_edidc-docnum, '; receiver partner is', ls_edidc-rcvprn,
'; sender partner',ls_edidc-sndprn. ENDLOOP. ENDIF. 7,查看IDOC. WE05可以查看我們剛剛發(fā)送的IDOC, BD87還可對IDOC進行一些處理。
---------------------------------------實例----------------------------------Inbound Idoc 這里將繼續(xù)沿用上篇文章的例子,講述I02對接收到的采購訂單信息進行的相關(guān)處理。
1,創(chuàng)建IDOC Type和Message Type.
與上篇Outbound Idoc中的前兩個步驟完全一樣。
2,創(chuàng)建一個function:Y_IDOC_PO_PROCESS. 當(dāng)IDOC設(shè)置完畢之后,SAP可以自動調(diào)用該Funtion Module處理IDOC。所以這個函數(shù)的接口都是規(guī)范的。 下面步驟中將介紹的tcode:BD51中可以查詢到很多Inbound Function,比如IDOC_INPUT_BBP_IV,可參照創(chuàng)建我們的接口。
接下來就可以寫入我們的代碼,根據(jù)IDOC內(nèi)容,創(chuàng)建相應(yīng)的銷售訂單。為了簡化,這里我們僅僅將其存到數(shù)據(jù)庫表里面,請先創(chuàng)建兩個表Y02_POHEAD和Y02_POITEM,字段參考WE31中的YPOHEAD和YPOITEM。然后寫入下面代碼: DATA: lv_subrc LIKE sy-subrc,?? ls_chead TYPE ypohead, ls_citem TYPE ypoitem,
ls_pohead TYPE y02_pohead, lt_poitem TYPE TABLE OF y02_poitem WITH HEADER LINE.
CLEAR idoc_contrl. READ TABLE idoc_contrl INDEX 1. IF idoc_contrl-mestyp <> 'YPO'.
??? RAISE wrong_function_called.
ENDIF.
LOOP AT idoc_contrl.
CLEAR: ls_pohead, lt_poitem[].
LOOP AT idoc_data WHERE docnum = idoc_contrl-docnum.
CASE idoc_data-segnam. WHEN 'YPOHEAD'.
????????? CLEAR: ls_chead, ls_pohead.
????????? ls_chead = idoc_data-sdata. MOVE-CORRESPONDING ls_chead TO ls_pohead.
????????WHEN 'YPOITEM'. CLEAR: ls_citem, lt_poitem.
????????? ls_citem = idoc_data-sdata. MOVE-CORRESPONDING ls_citem TO lt_poitem. APPEND lt_poitem. WHEN OTHERS. ENDCASE. ENDLOOP.
??? lv_subrc = 0.
??? INSERT y02_pohead FROM ls_pohead. IF sy-subrc = 0.
??????INSERT y02_poitem FROM TABLE lt_poitem.
??????lv_subrc = sy-subrc.
??? ELSE. "訂單號已經(jīng)存在
??????lv_subrc = sy-subrc. ENDIF.
??? IF lv_subrc = 0.?? COMMIT WORK.
??????CLEAR idoc_status.
??????idoc_status-docnum = idoc_contrl-docnum.
??????idoc_status-status = '53'. "IDOC處理成功 APPEND idoc_status.
??? ELSE. ROLLBACK WORK. CLEAR idoc_status.
??????idoc_status-docnum = idoc_contrl-docnum.
??????idoc_status-status = '51'. "IDOC不成功 idoc_status-msgty = 'E'. "錯誤信息
??????idoc_status-msgid = 'YMSG'. idoc_status-msgno = '001'. APPEND idoc_status. ENDIF.
??ENDLOOP. 3,在BD51中注冊我們的Function Module.
在編輯狀態(tài)下,點擊New Entries,填入函數(shù)名Y_IDOC_PO_PROCESS,Input Type=1即可。 4,在WE57中將Function Module與IDOC Type/Message Type關(guān)聯(lián)
點擊New Entries,Function Module輸入Y_IDOC_PO_PROCESS,其下的Type填寫F;IDOC Type下的Basic Type填寫YPOIDOC;Message Type填寫YPO;Direction填寫2(Inbound)。
5,WE42,創(chuàng)建Inbound Process Code. 注意該步驟必須在BD51和WE57之后,否則將出現(xiàn)錯誤提示。 創(chuàng)建新條目,Process Code輸入YPC_PO,在Option ALE下選擇Processing with ALE service,在Processing Type下選擇function module。保存后,在隨后的窗口中,輸入Inbound Module為Y_IDOC_PO_PROCESS。
6,WE20,維護Partner Profiles. 首先確保SALE中已經(jīng)維護好了對應(yīng)于接收方的Logical System,假設(shè)名稱為I04LS。(WE05查看您的Inbound IDOC, 均可看到其Partner名稱,這就是我們所需要的。本步驟與上篇的WE20類似,不同的是,這里是維護從I04LS過來的Inbound Parameters。Message Type輸入YPO,Process Type輸入YPC_PO,然后選中"Trigger immediately"即可。
7,至此,我們的設(shè)置已經(jīng)完畢。系統(tǒng)接收到從I04傳來的IDOC后即會立刻處理。 同時,各位針對上篇做過練習(xí)的朋友,系統(tǒng)中應(yīng)該會遺留幾個處于出錯狀態(tài)的IDOC吧?可以用BD87,在主界面上選中結(jié)點YPO后,點擊Process按鈕,一次性處理。處理前,順便在SE37中打開Y_IDOC_PO_PROCESS并設(shè)置幾個斷點即可調(diào)試。
補充: (1)如果狀態(tài)碼為56,則應(yīng)該是您的WE20沒設(shè)置好;
(2)由于上面代碼中控制了不能插入同樣的采購單號,所以只有一個Inbound IDOC將處理成功(狀態(tài)碼53),其余將失敗(狀態(tài)碼51)。只要新發(fā)送的IDOC賦于不同的采購單號即可避免。 (3)Outbound的狀態(tài)碼是0-50,03代表OK;Inbound的狀態(tài)碼則是50-99,53代表OK。
總結(jié)
以上是生活随笔為你收集整理的SAP IDOC开发的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 集团公司有什么性质
- 下一篇: 小企业“银行存款”科目的核算内容包括哪些