资源描述
1.创建记录发送时间的表:
2.定义自定义段:WE31
3.定义基本类型WE30
将段挂在基本类型下:
4.定义消息类型we81
5.基本类型分配给消息类型:
6. 定义自定义结构zmkpf_line.(即数据库表mkpf的前五个字段)
7. 表结构,ZMKpf_TYP,对应行类型结构为ZMKpf_LINE
8.创建发送idoc的函数:
FUNCTION ZMKPF_IDOC_SEND .
*"----------------------------------------------------------------------
*"*"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 edidc,
*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,
*help 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-mestyp 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_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_system_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.
* 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 application 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_status = 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.
raise no_idoc.
* no IDoc was created, you can react here, if neccessary
ENDIF.
ENDFUNCTION.
函数截图:
11.定义逻辑系统:
分配到集团:
12.定义目标系统:
13连接与权限测试:
14配置分布模型:
生成伙伴参数文件:
更改伙伴参数文件:
新建端口we21
新建出站参数:
执行函数ZMKPF_IDOC_SEND:
发送数据:
查看结果we02
消息的状态监视:bd87
点击处理按钮:
端口xml文件: (发送了三次,xml文件有点大)
<?xml version="1.0" encoding="UTF-8"?>
<ZMKPF_IDOC><IDOCBEGIN="1"><EDI_DC40SEGMENT="1"><TABNAM>EDI_DC40</TABNAM><MANDT>114</MANDT><DOCNUM>0000000000002001</DOCNUM><DOCREL>702</DOCREL><STATUS>30</STATUS><DIRECT>1</DIRECT><OUTMOD>4</OUTMOD><IDOCTYP>ZMKPF_IDOC</IDOCTYP><MESTYP>ZMKPF_IDOC</MESTYP><SNDPOR>SAPBP1</SNDPOR><SNDPRT>LS</SNDPRT><SNDPRN>ZSYS4674</SNDPRN><RCVPOR>ZXML</RCVPOR><RCVPRT>LS</RCVPRT><RCVPRN>BP5CLNT300</RCVPRN><CREDAT>20120821</CREDAT><CRETIM>050516</CRETIM><SERIAL>20120821050515</SERIAL></EDI_DC40>
<ZMKPF SEGMENT="1"><MJAHR>0000</MJAHR></ZMKPF></IDOC>
<IDOC BEGIN="1"><EDI_DC40 SEGMENT="1"><TABNAM>EDI_DC40</TABNAM><MANDT>114</MANDT><DOCNUM>0000000000002002</DOCNUM><DOCREL>702</DOCREL><STATUS>30</STATUS><DIRECT>1</DIRECT><OUTMOD>4</OUTMOD><IDOCTYP>ZMKPF_IDOC</IDOCTYP><MESTYP>ZMKPF_IDOC</MESTYP><SNDPOR>SAPBP1</SNDPOR><SNDPRT>LS</SNDPRT><SNDPRN>ZSYS4674</SNDPRN><RCVPOR>ZXML</RCVPOR><RCVPRT>LS</RCVPRT><RCVPRN>BP5CLNT300</RCVPRN><CREDAT>20120821</CREDAT><CRETIM>050718</CRETIM><SERIAL>20120821050717</SERIAL></EDI_DC40><ZMKPF SEGMENT="1"><MANDT>114</MANDT><MBLNR>4900000000</MBLNR><MJAHR>2011</MJAHR><VGART>WA</VGART><BLART>PR</BLART></ZMKPF></IDOC><IDOC BEGIN="1">
<EDI_DC40 SEGMENT="1"><TABNAM>EDI_DC40</TABNAM><MANDT>114</MANDT><DOCNUM>0000000000003001</DOCNUM><DOCREL>702</DOCREL><STATUS>30</STATUS><DIRECT>1</DIRECT><OUTMOD>4</OUTMOD><IDOCTYP>ZMKPF_IDOC</IDOCTYP><MESTYP>ZMKPF_IDOC</MESTYP><SNDPOR>SAPBP1</SNDPOR><SNDPRT>LS</SNDPRT><SNDPRN>ZSYS4674</SNDPRN><RCVPOR>ZXML</RCVPOR><RCVPRT>LS</RCVPRT><RCVPRN>BP5CLNT300</RCVPRN><CREDAT>20120821</CREDAT><CRETIM>190105</CRETIM><SERIAL>20120821190104</SERIAL></EDI_DC40><ZMKPF SEGMENT="1"><MANDT>114</MANDT><MBLNR>4900000000</MBLNR><MJAHR>2011</MJAHR><VGART>WA</VGART><BLART>PR</BLART></ZMKPF></IDOC></ZMKPF_IDOC>
展开阅读全文