1、 1.创建记录发送时间的表: 2.定义自定义段:WE31 3.定义基本类型WE30 将段挂在基本类型下: 4.定义消息类型we81 5.基本类型分配给消息类型: 6. 定义自定义结构zmkpf_line.(即数据库表mkpf的前五个字段) 7. 表结构,ZMKpf_TYP,对应行类型结构为ZMKpf_LINE 8.创建发送idoc的函数: FUNCTION ZMKPF_IDOC_SEND . *"-----------------------------------------------------------------
2、 *"*"Local interface: *" TABLES *" ZMKPF TYPE ZMKPF_TYP *" EXCEPTIONS *" NO_IDOC *" NO_MODEL *"---------------------------------------------------------------------- *variables of general interest DATA: *control record for the IDoc idoc_control LIKE edid
3、c, *data records for the IDoc t_idoc_data LIKE edidd OCCURS 0 WITH HEADER LINE, *table for the IDocs created by MASTER_IDOC_CONTROL t_comm_control LIKE edidc OCCURS 0 WITH HEADER LINE, *partner type for logical system c_partner_type_logical_system LIKE edidc-rcvprt, *h
4、elp variable for the check if an IDoc has to be created h_create_idoc. * variables specific for this example DATA: * field strings with IDoc segment structure e1xmkal TYPE ZMKPF_line, * data to be put to the control record c_message_type LIKE edidc-mest
5、yp VALUE 'ZMKPF_IDOC', c_base_idoc_type LIKE edidc-idoctp VALUE 'ZMKPF_IDOC', * segment types to be put to the data record table c_header_segtyp LIKE edidd-segnam VALUE 'ZMKPF'. * check if an IDoc has to be created, read the distribution model CALL FUNCTION 'ALE_MODEL_
6、DETERMINE_IF_TO_SEND' EXPORTING message_type = c_message_type * SENDING_SYSTEM = ' ' * RECEIVING_SYSTEM = ' ' * VALIDDATE = SY-DATUM IMPORTING idoc_must_be_sent = h_create_idoc. * exceptions * own_syste
7、m_not_defined = 1 * others = 2. IF h_create_idoc IS INITIAL. raise no_model. * no message flow maintained in the model, nothing to do EXIT. ENDIF. * put the application header record to the IDoc LOOP AT zmkpf. MOVE-CORRESPONDING zmkpf TO e1xmkal.
8、 * append record to IDoc data table t_idoc_data-segnam = c_header_segtyp. t_idoc_data-sdata = e1xmkal. APPEND t_idoc_data. ENDLOOP. idoc_control-mestyp = c_message_type. idoc_control-idoctp = c_base_idoc_type. CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE' * in update task "if ap
9、plication document is posted in update task EXPORTING master_idoc_control = idoc_control TABLES communication_idoc_control = t_comm_control master_idoc_data = t_idoc_data EXCEPTIONS error_in_idoc_control = 1 error_writing_idoc_s
10、tatus = 2 error_in_idoc_data = 3 sending_logical_system_unknown = 4 OTHERS = 5. * A commit work has to be done. It could also be done in the calling * application. COMMIT WORK. READ TABLE t_comm_control INDEX 1. IF sy-subrc <> 0.
11、 raise no_idoc. * no IDoc was created, you can react here, if neccessary ENDIF. ENDFUNCTION. 函数截图: 11.定义逻辑系统: 分配到集团: 12.定义目标系统: 13连接与权限测试: 14配置分布模型: 生成伙伴参数文件: 更改伙伴参数文件: 新建端口we21 新建出站参数: 执行函数ZMKPF_IDOC_SEND: 发送数据: 查看结果we02 消息的状态
12、监视:bd87
点击处理按钮:
端口xml文件: (发送了三次,xml文件有点大)
13、MKPF_IDOC
14、00
15、RT>LS 16、>PR 17、PRT>LS






