[转]SAP IDOC简介

创建IDOC:

第一步:WE31 创建IDOC所包含的字段.
第二步:WE30 创建IDOC 把Segment分配给IDOC
第三步:WE81 创建信息类型
第四步:WE82 把IDOC类型与信息类型对应.
第五步: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,可以根据时间,IDOC类型查找IDOC,查看成功,出错信息。
WE46 IDOC管理(出\入)
WE60 IDOC类型文档(可以查看IDOC结构,和每个字段的描述.
WE19 根据IDOC号进行IDOC处理,可以修改IDOC值进行补发动作,处理分为内向和外向。

消息配置:

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: WE 30
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 à Click on Execute Button
Go for New Entries
1) System Name : LOG1:Description: Sending System
2) System Name : LOG2:Description: 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
Logical 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 name
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 .
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
> 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例子(Outbound Idoc)

简而言之,IDOC是类似XML的一种SAP系统与其他系统的一种集成工具。
假设I04和I02是同一个集团下两个不同子公司的SAP系统,I04需要将其采购订单信息及时发送给I02。下面简单介绍IDOC的设置步骤,为了避免混淆,我的命名都比较特别。

1,设置IDOC Type.
(1) WE31,创建segment,类似于创建XML的结点及结点属性。
这里先输入YPOHEAD,点击创建,在接下来的屏幕中,录入EBELN, BUKRS, BEDAT等字段及他们对应的data element;接着创建YPOITEM,输入EBELN, EBELP, MATNR, MENGE, MEINS等字段及他们对应的data element。
保存后用SE12查看你将发现,系统自动添加了YPOHEAD和YPOITEM两个结构,每个字段都成了CHAR类型,长度就是WE31中的EXPORT LENG。
(2) WE30, 创建IDOC Type,定义结点间的相互逻辑关系.
先输入YPOIDOC,然后点击创建,紧跟着点击create new进入。在主界面中,先点击创建按钮,将YPOHEAD添加,设置Mandatory seg打勾,min = 1, max = 1,代表我们每个IDOC仅包含一张采购订单。然后在YPOHEAD下添加YPOITEM,同样的Mandatory seg打勾,min = 1, max = 99999.

2,创建Message Type.
(1) WE81,创建Message Type.
先切换到编辑状态,然后点击New Entries,输入YPO即可。
(2) WE82,,关联Message Type和IDOC Type.

3,创建到I02的端口.
首先确保系统内已经有到I02的R/3 Connection(SM59),如果没有则先创建一个名为I02001。
接着WE21创建Port,类型TRANSACTIONAL RFC,名为I02PORT,RFC destination则填写I02001。

4,SALE,创建Logical System.
SALE, Sending and Receiving Systems,Logical Systems, define logical systems,新增一个logical system,名为I02LS,这将作为下一步的Partner。
Define logical systems下方,有Assign Client to logical system,这里可针对本系统(I04)定义logical system,作为发送IDOC时的发送方标识,我对Client 001的定义是I04LS.

5,WE20,定义我们的Partner profile.
在PARTNER TYPE为logical system下,创建一个patner no为I02LS的partner,type填写LS。
下面的Permitted agent,填写US(User),Agent为你自己的用户名或某basis人员用户名。
然后,点击outbound下方的加号,创建一个outbound parameter。Message Type为YPO,receiver port为I02PORT,output mode选择transfer idoc immed.,Basic Type填写YPOIDOC,保存即可。

6,编程发送IDOC
设置了这么多,真累啊,总算可以写程序了,是不是很开心呢?
程序的思路就是,把每个IDOC结点按字符串形式逐个添加,而字符串的添加次序自然也体现了IDOC结点间的逻辑关系。代码如下,

7,查看IDOC.
WE05可以查看我们刚刚发送的IDOC, BD87还可对IDOC进行一些处理。
Idoc例子(Inbound Idoc)
这里将继续沿用上篇文章的例子,讲述I02对接收到的采购订单信息进行的相关处理。

1,创建IDOC Type和Message Type.
与上篇Outbound Idoc中的前两个步骤完全一样。

2,创建一个function:Y_IDOC_PO_PROCESS.
当IDOC设置完毕之后,SAP可以自动调用该Funtion Module处理IDOC。所以这个函数的接口都是规范的。
下面步骤中将介绍的tcode:BD51中可以查询到很多Inbound Function,比如IDOC_INPUT_BBP_IV,可参照创建我们的接口。
接下来就可以写入我们的代码,根据IDOC内容,创建相应的销售订单。为了简化,这里我们仅仅将其存到数据库表里面,请先创建两个表Y02_POHEAD和Y02_POITEM,字段参考WE31中的YPOHEAD和YPOITEM。然后写入下面代码:

3,在BD51中注册我们的Function Module.
在编辑状态下,点击New Entries,填入函数名Y_IDOC_PO_PROCESS,Input Type=1即可。

4,在WE57中将Function Module与IDOC Type/Message Type关联
点击New Entries,Function Module输入Y_IDOC_PO_PROCESS,其下的Type填写F;IDOC Type下的Basic Type填写YPOIDOC;Message Type填写YPO;Direction填写2(Inbound)。

5,WE42,创建Inbound Process Code.
注意该步骤必须在BD51和WE57之后,否则将出现错误提示。
创建新条目,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中已经维护好了对应于接收方的Logical System,假设名称为I04LS。
(WE05查看您的Inbound IDOC, 均可看到其Partner名称,这就是我们所需要的。)
本步骤与上篇的WE20类似,不同的是,这里是维护从I04LS过来的Inbound Parameters。
Message Type输入YPO,Process Type输入YPC_PO,然后选中”Trigger immediately”即可。

7,至此,我们的设置已经完毕。系统接收到从I04传来的IDOC后即会立刻处理。
同时,各位针对上篇做过练习的朋友,系统中应该会遗留几个处于出错状态的IDOC吧?可以用BD87,在主界面上选中结点YPO后,点击Process按钮,一次性处理。处理前,顺便在SE37中打开Y_IDOC_PO_PROCESS并设置几个断点即可调试。

补充:
(1)如果状态码为56,则应该是您的WE20没设置好;
(2)由于上面代码中控制了不能插入同样的采购单号,所以只有一个Inbound IDOC将处理成功(状态码53),其余将失败(状态码51)。只要新发送的IDOC赋于不同的采购单号即可避免。
(3)Outbound的状态码是0-50,03代表OK;Inbound的状态码则是50-99,53代表OK。

本文作者: GavinDong

版权属于: GavinDong博客

文章链接: https://gavindong.com/200.html

如果使用过程中遇到问题,可 **点击此处** 交流沟通。

版权所有,转载时必须以链接形式注明作者和原始出处及本声明。

(0)

相关文章

发表回复

登录后才能评论