网上找到的最简单说明建立IDoc的文章
2017-03-24 09:55
127 查看
This document illustrates how we can create our own Idoc from scratch, and an ABAP program is used to generate the Idoc and one Function module created for inbound process. The program adds the user name, the current date and time, and sends the information
to the receiving system. The receiving system processes the data and posts it to the database. It also sets the appropriate status of the IDoc, which then can be checked in the IDoc List (WE05).
In order to achieve our task, the following steps are necessary:
1. Create data container (Idoc)
2. Create database table
3. Create outbound program
4. Create inbound function
5. Set up ALE customizing
6. Send data
Create new segments
To create a new segment: Go to Transaction code WE30 and follow the steps shown in below screen shot.
Create the Segment with field ZIMATNR, ZMTART, SENDER, ZDATE, ZTIME.
After entering the segment fields, save and activate your segment.
Create new IDoc type
The IDoc type describes the technical structure of a message. It defines which segments will be used, and what is the hierarchical structure of the segments. For each segment, it also specifies whether it’s mandatory or optional, and how many times the segment
may appear in the IDoc.
To Create IDoc Type Use Transaction WE30.
Add Segment Type to IDoc Basic type.
Create new message type
The message type describes the contents of the message. It helps the system to decide how to process the message. To create a new message type use transaction code WE30.
Link message type with IDoc type:
Go to transaction Code WE82 and create new entry. And Link Message type with created IDoc type.
Step 2: Create a new database table
Go to the ABAP/4 Dictionary Initial screen (SE11), and create a new table. The table should mirror the structure of the segment created above.
Step 3: Create a program for outbound processing
Fill data into Idoc and pass IDoc to ALE layer. Close LUW (commit work). The IDoc consists of a control record and one or more data records (segments). The data segments contain the data of
the message. They are passed to ALE as an internal table (structure EDIDD). The control record contains general information about the IDoc (structure EDIDC). Function MASTER_IDOC_DISTRIBUTE is called to pass the IDoc to ALE. For further details, see the
code below.
*&———————————————————————*
*& Report ZALEIDOC
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT zaleidoc.
TABLES: z1segtyp. “IDoc segment
PARAMETERS: z1matnr LIKE z1segtyp-z1matnr OBLIGATORY,
zmtart LIKE z1segtyp-zmtart OBLIGATORY.
DATA: BEGIN OF f_idoc_header.
INCLUDE STRUCTURE edidc.
DATA: END OF f_idoc_header.
DATA: BEGIN OF t_idoc_data OCCURS 0.
INCLUDE STRUCTURE edidd.
DATA: END OF t_idoc_data.
DATA: BEGIN OF t_comm_idoc_control OCCURS 0.
INCLUDE STRUCTURE edidc.
DATA: END OF t_comm_idoc_control.
CLEAR t_idoc_data.
REFRESH t_idoc_data.
CLEAR f_idoc_header.
* move parameters into field string
z1segtyp-z1matnr = z1matnr.
z1segtyp-zmtart = zmtart.
* add data to field string
z1segtyp-sender = sy-uname.
z1segtyp-zdate = sy-datum.
z1segtyp-ztime = sy-uzeit.
* field string to IDoc-data
t_idoc_data-sdata = z1segtyp.
* segment name
t_idoc_data-segnam = ‘Z1SEGTYP’.
* append data
APPEND t_idoc_data.
* fill IDoc header
f_idoc_header-mestyp = ‘ZMESGTYP’.
f_idoc_header-idoctp = ‘ZALECON’.
* send IDoc
CALL FUNCTION ‘MASTER_IDOC_DISTRIBUTE’
EXPORTING
master_idoc_control = f_idoc_header
TABLES
communication_idoc_control = t_comm_idoc_control
master_idoc_data = t_idoc_data
EXCEPTIONS
error_in_idoc_control = 1
error_writing_idoc_status = 2
error_in_idoc_data = 3
sending_logical_system_unknown = 4
OTHERS = 5.
* check results
IF sy-subrc = 0.
WRITE:/ ‘IDoc created.’.
ELSE.
WRITE:/ ‘Error’,sy-subrc,‘in
MASTER_IDOC_DISTRIBUTE’.
ENDIF.
* close LUW
COMMIT WORK.
Step 4: Inbound processing
Create a function module for the inbound processing. Check that the IDoc contains the correct message type. Convert the character data to internal format, if necessary. If the data is OK, post it to the database table. Otherwise, return an error message
to ALE.
FUNCTION Z_IDOC_INPUT_ZALEIDOC.
*”———————————————————————-
*”*”Local Interface:
*” IMPORTING
*” REFERENCE(INPUT_METHOD) TYPE INPUTMETHD
*” REFERENCE(MASS_PROCESSING) TYPE MASS_PROC
*” EXPORTING
*” REFERENCE(WORKFLOW_RESULT) TYPE RESULT
*” REFERENCE(APPLICATION_VARIABLE) TYPE APPL_VAR
*” REFERENCE(IN_UPDATE_TASK) TYPE UPDATETASK
*” REFERENCE(CALL_TRANSACTION_DONE) TYPE CALLTRANS2
*” TABLES
*” IDOC_CONTRL STRUCTURE EDIDC
*” IDOC_DATA STRUCTURE EDIDD
*” IDOC_STATUS STRUCTURE BDIDOCSTAT
*” RETURN_VARIABLES STRUCTURE BDWFRETVAR
*” SERIALIZATION_INFO STRUCTURE BDI_SER
*” EXCEPTIONS
*” FAILED_FUNCTION_CALL
*”———————————————————————-
* IDoc inbound processing for ALE2
* database tables
TABLES: ZALETAB.
* field string for segment data
DATA: F_Z1SEGTYP LIKE Z1SEGTYP.
* read IDoc control record
LOOP AT IDOC_CONTRL.
* check correct IDoc type
IF IDOC_CONTRL-IDOCTP <> ‘ZALECON’.
RAISE WRONG_FUNCTION_CALLED.
ENDIF.
* clear segment field string
CLEAR F_Z1SEGTYP.
* read segments of the IDoc
LOOP AT IDOC_DATA WHERE DOCNUM
= IDOC_CONTRL-DOCNUM.
* move segment data into field string
F_Z1SEGTYP = IDOC_DATA-SDATA.
* common 3 statements for error or success
CLEAR IDOC_STATUS.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
* check error
IF F_Z1SEGTYP-zmtart IS INITIAL. “error
IDOC_STATUS-STATUS = ’51’.
IDOC_STATUS-MSGTY = ‘E’.
IDOC_STATUS-MSGID = ‘ZA’.
IDOC_STATUS-MSGNO = ‘001’.
IDOC_STATUS-UNAME = SY-UNAME.
IDOC_STATUS-REPID = SY-REPID.
WORKFLOW_RESULT = 99999.
RETURN_VARIABLES-WF_PARAM = ‘Error_IDOCs’.
ELSE. “no error
* post data
MOVE-CORRESPONDING F_Z1SEGTYP TO ZALETAB.
MODIFY ZALETAB.
* write IDoc status OK
IDOC_STATUS-STATUS = ’53’.
RETURN_VARIABLES-WF_PARAM = ‘Processed_IDOCs’.
WORKFLOW_RESULT = 0.
ENDIF.
* common 2 statements for error or success
APPEND IDOC_STATUS.
APPEND RETURN_VARIABLES.
ENDLOOP. “loop at idoc_data
ENDLOOP. “loop at idoc_contrl.
ENDFUNCTION.
a) Allocate API to Message Type WE57
Now go to transaction code WE57 to allocate API to Message Type.
Module name of your function
Type ‘F’ (function module)
Message type you created in step 1
Direction ‘2’ (inbound)
b) Declare API Attributes BD51
Go to Transaction Code BD51 to declare the API attributes.
And maintain Function module name, Input t. Dialog allowed as shown below:
c) Maintain Inbound Process Code: WE42
Go to Transaction Code WE42 to maintain the Inbound Process Code.
Then Click on the Logical message and maintain message type as shown in below screen.
Step 5: Set up ALE customizing BD64
In the distribution model, you have to define which messages are distributed from one system to another. The model directly controls the distribution. ALE IMG->Distribution customer model->Maintain customer distribution model directly; Maintain message flow.
We assume that the communication parameters, like partner profiles, ports, RFC destinations, have been set up by this time. You can run a consistency check for your set up.
Step 6 : Send data
On the sending system, run the program created in Step 3. The data will be put into an IDoc and sent to the receiving system. On the receiving system, use the IDoc overview (WE05) to check that your IDoc has arrived. If it has been processed successfully,
the database table created in Step 2 must contain the new record.
文章地址:
https://blogs.sap.com/2016/05/25/create-an-idoc-programatically/
to the receiving system. The receiving system processes the data and posts it to the database. It also sets the appropriate status of the IDoc, which then can be checked in the IDoc List (WE05).
In order to achieve our task, the following steps are necessary:
1. Create data container (Idoc)
2. Create database table
3. Create outbound program
4. Create inbound function
5. Set up ALE customizing
6. Send data
Step 1: Creating a new IDoc
Create new segmentsTo create a new segment: Go to Transaction code WE30 and follow the steps shown in below screen shot.
Create the Segment with field ZIMATNR, ZMTART, SENDER, ZDATE, ZTIME.
After entering the segment fields, save and activate your segment.
Create new IDoc type
The IDoc type describes the technical structure of a message. It defines which segments will be used, and what is the hierarchical structure of the segments. For each segment, it also specifies whether it’s mandatory or optional, and how many times the segment
may appear in the IDoc.
To Create IDoc Type Use Transaction WE30.
Add Segment Type to IDoc Basic type.
Create new message type
The message type describes the contents of the message. It helps the system to decide how to process the message. To create a new message type use transaction code WE30.
Link message type with IDoc type:
Go to transaction Code WE82 and create new entry. And Link Message type with created IDoc type.
Step 2: Create a new database table
Go to the ABAP/4 Dictionary Initial screen (SE11), and create a new table. The table should mirror the structure of the segment created above.
Step 3: Create a program for outbound processing
Fill data into Idoc and pass IDoc to ALE layer. Close LUW (commit work). The IDoc consists of a control record and one or more data records (segments). The data segments contain the data of
the message. They are passed to ALE as an internal table (structure EDIDD). The control record contains general information about the IDoc (structure EDIDC). Function MASTER_IDOC_DISTRIBUTE is called to pass the IDoc to ALE. For further details, see the
code below.
*&———————————————————————*
*& Report ZALEIDOC
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT zaleidoc.
TABLES: z1segtyp. “IDoc segment
PARAMETERS: z1matnr LIKE z1segtyp-z1matnr OBLIGATORY,
zmtart LIKE z1segtyp-zmtart OBLIGATORY.
DATA: BEGIN OF f_idoc_header.
INCLUDE STRUCTURE edidc.
DATA: END OF f_idoc_header.
DATA: BEGIN OF t_idoc_data OCCURS 0.
INCLUDE STRUCTURE edidd.
DATA: END OF t_idoc_data.
DATA: BEGIN OF t_comm_idoc_control OCCURS 0.
INCLUDE STRUCTURE edidc.
DATA: END OF t_comm_idoc_control.
CLEAR t_idoc_data.
REFRESH t_idoc_data.
CLEAR f_idoc_header.
* move parameters into field string
z1segtyp-z1matnr = z1matnr.
z1segtyp-zmtart = zmtart.
* add data to field string
z1segtyp-sender = sy-uname.
z1segtyp-zdate = sy-datum.
z1segtyp-ztime = sy-uzeit.
* field string to IDoc-data
t_idoc_data-sdata = z1segtyp.
* segment name
t_idoc_data-segnam = ‘Z1SEGTYP’.
* append data
APPEND t_idoc_data.
* fill IDoc header
f_idoc_header-mestyp = ‘ZMESGTYP’.
f_idoc_header-idoctp = ‘ZALECON’.
* send IDoc
CALL FUNCTION ‘MASTER_IDOC_DISTRIBUTE’
EXPORTING
master_idoc_control = f_idoc_header
TABLES
communication_idoc_control = t_comm_idoc_control
master_idoc_data = t_idoc_data
EXCEPTIONS
error_in_idoc_control = 1
error_writing_idoc_status = 2
error_in_idoc_data = 3
sending_logical_system_unknown = 4
OTHERS = 5.
* check results
IF sy-subrc = 0.
WRITE:/ ‘IDoc created.’.
ELSE.
WRITE:/ ‘Error’,sy-subrc,‘in
MASTER_IDOC_DISTRIBUTE’.
ENDIF.
* close LUW
COMMIT WORK.
Step 4: Inbound processing
Create a function module for the inbound processing. Check that the IDoc contains the correct message type. Convert the character data to internal format, if necessary. If the data is OK, post it to the database table. Otherwise, return an error message
to ALE.
FUNCTION Z_IDOC_INPUT_ZALEIDOC.
*”———————————————————————-
*”*”Local Interface:
*” IMPORTING
*” REFERENCE(INPUT_METHOD) TYPE INPUTMETHD
*” REFERENCE(MASS_PROCESSING) TYPE MASS_PROC
*” EXPORTING
*” REFERENCE(WORKFLOW_RESULT) TYPE RESULT
*” REFERENCE(APPLICATION_VARIABLE) TYPE APPL_VAR
*” REFERENCE(IN_UPDATE_TASK) TYPE UPDATETASK
*” REFERENCE(CALL_TRANSACTION_DONE) TYPE CALLTRANS2
*” TABLES
*” IDOC_CONTRL STRUCTURE EDIDC
*” IDOC_DATA STRUCTURE EDIDD
*” IDOC_STATUS STRUCTURE BDIDOCSTAT
*” RETURN_VARIABLES STRUCTURE BDWFRETVAR
*” SERIALIZATION_INFO STRUCTURE BDI_SER
*” EXCEPTIONS
*” FAILED_FUNCTION_CALL
*”———————————————————————-
* IDoc inbound processing for ALE2
* database tables
TABLES: ZALETAB.
* field string for segment data
DATA: F_Z1SEGTYP LIKE Z1SEGTYP.
* read IDoc control record
LOOP AT IDOC_CONTRL.
* check correct IDoc type
IF IDOC_CONTRL-IDOCTP <> ‘ZALECON’.
RAISE WRONG_FUNCTION_CALLED.
ENDIF.
* clear segment field string
CLEAR F_Z1SEGTYP.
* read segments of the IDoc
LOOP AT IDOC_DATA WHERE DOCNUM
= IDOC_CONTRL-DOCNUM.
* move segment data into field string
F_Z1SEGTYP = IDOC_DATA-SDATA.
* common 3 statements for error or success
CLEAR IDOC_STATUS.
IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
* check error
IF F_Z1SEGTYP-zmtart IS INITIAL. “error
IDOC_STATUS-STATUS = ’51’.
IDOC_STATUS-MSGTY = ‘E’.
IDOC_STATUS-MSGID = ‘ZA’.
IDOC_STATUS-MSGNO = ‘001’.
IDOC_STATUS-UNAME = SY-UNAME.
IDOC_STATUS-REPID = SY-REPID.
WORKFLOW_RESULT = 99999.
RETURN_VARIABLES-WF_PARAM = ‘Error_IDOCs’.
ELSE. “no error
* post data
MOVE-CORRESPONDING F_Z1SEGTYP TO ZALETAB.
MODIFY ZALETAB.
* write IDoc status OK
IDOC_STATUS-STATUS = ’53’.
RETURN_VARIABLES-WF_PARAM = ‘Processed_IDOCs’.
WORKFLOW_RESULT = 0.
ENDIF.
* common 2 statements for error or success
APPEND IDOC_STATUS.
APPEND RETURN_VARIABLES.
ENDLOOP. “loop at idoc_data
ENDLOOP. “loop at idoc_contrl.
ENDFUNCTION.
a) Allocate API to Message Type WE57
Now go to transaction code WE57 to allocate API to Message Type.
Module name of your function
Type ‘F’ (function module)
BasicIDoc type you created in step 1
Message type you created in step 1Direction ‘2’ (inbound)
b) Declare API Attributes BD51
Go to Transaction Code BD51 to declare the API attributes.
And maintain Function module name, Input t. Dialog allowed as shown below:
c) Maintain Inbound Process Code: WE42
Go to Transaction Code WE42 to maintain the Inbound Process Code.
Then Click on the Logical message and maintain message type as shown in below screen.
Step 5: Set up ALE customizing BD64
In the distribution model, you have to define which messages are distributed from one system to another. The model directly controls the distribution. ALE IMG->Distribution customer model->Maintain customer distribution model directly; Maintain message flow.
We assume that the communication parameters, like partner profiles, ports, RFC destinations, have been set up by this time. You can run a consistency check for your set up.
Step 6 : Send data
On the sending system, run the program created in Step 3. The data will be put into an IDoc and sent to the receiving system. On the receiving system, use the IDoc overview (WE05) to check that your IDoc has arrived. If it has been processed successfully,
the database table created in Step 2 must contain the new record.
文章地址:
https://blogs.sap.com/2016/05/25/create-an-idoc-programatically/
相关文章推荐
- 学习javascript时从网上看到的一篇比较简单和基础的文章,特转载!
- 我在网上看到的非常好的交叉环境建立文章
- jq 操作表单的常用代码(结合网上找到的简单记录一下)
- 网上找到的一篇java笔试文章
- 本程序说明了如何建立一个简单的可以接收UDP服务器数据的UDP客户端
- position属性absolute与relative 详解 最近一直在研究javascript脚本,熟悉DOM中CSS样式的各种定位属性,以前对这个属性不太了解,从网上找到两篇文章感觉讲得很透彻,
- 在进行嵌入式开发之前,首先要建立一个交叉编译环境,这是一套编译器、连接器和libc库等组成的开发环境。文章通过一个具体的例子说明了这些嵌入式交叉编译开发工具的制作过程。 随着消费类电子产品的大量开发和应用和Linux操作系统的不断健壮和强大,嵌入式系统越来
- rtf格式的一些说明,转载的,我找到的rtf资料中比较实用的一片文章了
- 英音学习的一些途径(在网上找到的一篇文章,对英音学习很有帮助)
- 想设置CListStrl的每一行的颜色,网上找到了如下文章,讲得不错
- php移位运算,移位操作应用口诀,网上找到的最强PHP位移操作的文章,收藏
- 用文件写入建立简单的网上调查
- 网上找到linux 简单模块编译脚本
- 网上找到的一篇讲解select机制非常详细透彻的文章,极力推荐
- 推荐系统 LFM 算法的简单理解,感觉比大部分网上抄来抄去的文章好理解
- 我写了一个简单的APP,用到了数据库,在程序中我自动建立了一个数据库,可以在File Explorer中找到,然后我把软件安装到虚拟机可以运行。
- 可能是最简单的讲解做一个IDoc的步骤说明
- python3.x的torndb使用记录(发现网上没有关于torndb的使用说明,可能太简单了吧:-P)
- 正当对棋盘覆盖和染色迷惑时,从网上找到一篇小学数学竞赛的文章,看了后明白了不少.