IDOC练习实例.docx
《IDOC练习实例.docx》由会员分享,可在线阅读,更多相关《IDOC练习实例.docx(15页珍藏版)》请在冰豆网上搜索。
IDOC练习实例
1.自建IDOCTYPE的出站、进站处理
场景:
从集团800取得FI会计凭证号,利用自建的IDOC发送到集团810系统
1.1出站:
1)事物代码SALE定义逻辑数据库:
路径:
基本设置->逻辑系统->定义逻辑系统
T90CLNT090client800
T90CLNT810client810
2)事物代码SCC4分配逻辑系统到集团:
集团800逻辑系统:
T90CLNT090
集团810逻辑系统:
T90CLNT810
3)事物代码sm59定义2系统连接:
输入:
TargetHost:
SH03(可以用事物SM51来查看本机的信息)
SystemNumber:
00
登录信息,包括语言、集团、用户、密码
在集团800建立连接810的连接:
ZLINK810
在集团810建立连接800的连接:
ZLINK800
4)事物代码WE21创建IDOC处理端口:
集团800:
端口ZPORT_800,RFC目标选择ZLINK810
集团810:
端口ZPORT_810,RFC目标选择ZLINK800
5)事物代码WE31创建自定义IDOCTYPE
定义2个段,ZFIDOCH会计凭证抬头,ZFIDOCI会计凭证行项目
6)事物代码WE30创建IDOC类型:
关联2个段ZFIDOCH/ZFIDOCI
7)事物代码WE81创建一个IDOC消息
IDOC消息Z_FI_DOCU
8)事物代码WE82关联IDOC消息与IDOC类型
IDOC消息:
Z_FI_DOCU
IDOC类型:
ZFIDOCU
9)事物代码WE20定义合作伙伴
选择伙伴类型LS,创建伙伴T90CLNT810,
输入
消息类型:
Z_FI_DOCU
接收方端口:
ZPORT_800
基本类型:
ZFIDOCU
10)事物代码SE38创建IDOC出站程序Z_FI_IDOC
*&---------------------------------------------------------------------*
*& Report Z_FI_IDOC
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT z_fi_idoc.
TABLES:
bkpf.
DATA:
BEGIN OF it_bkpf OCCURS 0,
bukrs TYPE bkpf-bukrs,
belnr TYPE bkpf-belnr,
gjahr TYPE bkpf-gjahr,
blart TYPE bkpf-blart,
waers TYPE bkpf-waers,
END OF it_bkpf.
DATA:
wa_bkpf LIKE zfidoch.
DATA:
BEGIN OF it_bseg OCCURS 0,
bukrs LIKE bseg-bukrs,
belnr LIKE bseg-belnr,
gjahr LIKE bseg-gjahr,
buzei LIKE bseg-buzei,
shkzg LIKE bseg-shkzg,
dmbtr LIKE bseg-dmbtr,
hkont LIKE bseg-hkont,
END OF it_bseg.
DATA:
wa_bseg LIKE zfidoci.
DATA:
wa_edidc TYPE edidc,
it_edidc TYPE TABLE OF edidc WITH HEADER LINE,
it_edidd TYPE TABLE OF edidd WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK s1 WITH FRAME TITLE text-001.
PARAMETERS:
p_bukrs TYPE bkpf-bukrs OBLIGATORY DEFAULT '1000',
p_gjahr TYPE bkpf-gjahr OBLIGATORY DEFAULT '2011'.
SELECT-OPTIONS:
s_belnr FOR bkpf-belnr DEFAULT '1400000009'.
SELECTION-SCREEN END OF BLOCK s1.
START-OF-SELECTION.
PERFORM frm_select.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form FRM_SELECT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM frm_select.
SELECT bukrs belnr gjahr blart waers
INTO TABLE it_bkpf
FROM bkpf
WHERE bukrs = p_bukrs
AND belnr IN s_belnr
AND gjahr = p_gjahr.
IF it_bkpf[] IS INITIAL.
WRITE '没有数据'.
STOP.
ELSE.
SELECT bukrs belnr gjahr buzei
shkzg dmbtr hkont
INTO TABLE it_bseg
FROM bseg
WHERE bukrs = p_bukrs
AND belnr IN s_belnr
AND gjahr = p_gjahr.
ENDIF.
CLEAR wa_edidc.
*系统根据下面4行即可与WE20设置关联起来
wa_edidc-mestyp = 'Z_FI_DOCU'. "Message Type
* wa_edidc-mestyp = 'Z_FI_DOCU_DEMO'.
wa_edidc-idoctp = 'ZFIDOCU'. "IDOC Type
wa_edidc-rcvprn = 'T90CLNT810'. "Partner Number of Recipient
wa_edidc-rcvprt = 'LS'. "Partner Type of Receiver
SORT it_bkpf BY bukrs belnr gjahr.
SORT it_bseg BY bukrs belnr gjahr buzei.
LOOP AT it_bkpf.
*添加IDOC结点
it_edidd-segnam = 'ZFIDOCH'."结点名称
it_edidd-dtint2 = 0.
MOVE-CORRESPONDING it_bkpf TO wa_bkpf.
it_edidd-sdata = wa_bkpf.. "结点内容
APPEND it_edidd.
CLEAR:
wa_bkpf,it_edidd.
LOOP AT it_bseg WHERE bukrs = it_bkpf-bukrs
AND belnr = it_bkpf-belnr
AND gjahr = it_bkpf-gjahr..
it_edidd-segnam = 'ZFIDOCI'.
it_edidd-dtint2 = 0.
MOVE-CORRESPONDING it_bseg TO wa_bseg.
it_edidd-sdata = wa_bseg.
APPEND it_edidd.
CLEAR:
it_edidd, wa_bseg.
ENDLOOP.
ENDLOOP.
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
master_idoc_control = wa_edidc "Export
TABLES
communication_idoc_control = it_edidc "Import
master_idoc_data = it_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 AND WAIT.
WRITE:
'Idoc sent:
'.
LOOP AT it_edidc INTO wa_edidc.
NEW-LINE.
WRITE:
'Idoc number is',wa_edidc-docnum,
'; receiver partner is', wa_edidc-rcvprn,
'; sender partner',wa_edidc-sndprn.
ENDLOOP.
ENDIF.
ENDFORM. "FRM_SELECT
11)事物代码WE02查看生成的出站IDOC
1.2入站:
1)事物代码SE11创建2张表,用于存储IDOC传来数据
表:
ZFI_HEAD、ZFI_ITEM
2)事物代码SE37创建处理函数Z_IDOC_FI_DOCU_PROCESS;
FUNCTION z_idoc_fi_docu_process.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" REFERENCE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" EXPORTING
*" VALUE(WORKFLOW_RESULT) LIKE BDWF_PARAM-RESULT
*" VALUE(APPLICATION_VARIABL) LIKE BDWF_PARAM-APPL_VAR
*" VALUE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK
*" VALUE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS
*" TABLES
*" IDOC_CONTRL STRUCTURE EDIDC
*" IDOC_DATA STRUCTURE EDIDD
*" IDOC_STATUS STRUCTURE BDIDOCSTAT
*" RETURN_VARIABLES STRUCTURE BDWFRETVAR
*" SERIALIZATION_INFO STRUCTURE BDI_SER
*" EXCEPTIONS
*" WRONG_FUNCTION_CALLED
*" OTHERS
*"----------------------------------------------------------------------
DATA:
lv_subrc LIKE sy-subrc,
wa_bkpf TYPE zfidoch,
wa_bseg TYPE zfidoci,
it_head TYPE STANDARD TABLE OF zfi_head WITH HEADER LINE,
it_item TYPE STANDARD TABLE OF zfi_item WITH HEADER LINE.
CLEAR idoc_contrl.
READ TABLE idoc_contrl INDEX 1.
IF idoc_contrl-mestyp <> 'Z_FI_DOCU' AND idoc_contrl-mestyp <> 'Z_FI_DOCU_DEMO'.
RAISE wrong_function_called.
ENDIF.
LOOP AT idoc_contrl.
LOOP AT idoc_data WHERE docnum = idoc_contrl-docnum.
CASE idoc_data-segnam.
WHEN 'ZFIDOCH'.
wa_bkpf = idoc_data-sdata.
MOVE-CORRESPONDING wa_bkpf TO it_head.
it_head-datum = sy-datum.
it_head-uzeit = sy-uzeit.
APPEND it_head.
CLEAR:
it_head, wa_bkpf.
WHEN 'ZFIDOCI'.
wa_bseg = idoc_data-sdata.
MOVE-CORRESPONDING wa_bseg TO it_item.
it_item-datum = sy-datum.
it_item-uzeit = sy-uzeit.
APPEND it_item.
CLEAR:
it_item, wa_bseg.
WHEN OTHERS.
ENDCASE.
ENDLOOP.
ENDLOOP.
MODIFY zfi_head FROM TABLE it_head.
lv_subrc = sy-subrc.
MODIFY zfi_item FROM TABLE it_item.
lv_subrc = sy-subrc.
IF lv_subrc = 0.
COMMIT WORK AND WAIT.
idoc_status-docnum = idoc_contrl-docnum.
idoc_status-status = '53'. "IDOC处理成功
APPEND idoc_status.
ELSE.
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.
ENDFUNCTION.
3)事物代码BD51注册函数Z_IDOC_FI_DOCU_PROCESS
4)事物代码WE57关联函数、IDOC类型、消息类型
5)事物代码WE42创建处理码ZFIDOC
6)事物代码WE20创建合作伙伴
在集团810中创建合作伙伴T90CLNT090
7)在集团800利用程序Z_FI_IDOC发送IDOC
如果状态为30,则需要WE19立即执行
在集团810WE02查看IDOC
成功处理,表ZFI_HEAD/ZFI_ITEM存在数据
8)完成测试;
1.3设置筛选器
1)事物代码BD64创建分发模型
发送方:
T90CLNT090
接收方:
T90CLNT810
消息类型:
Z_FI_DOCU
创建好了以后,可以用菜单的环境->生成参数伙伴文件来生成合作伙伴
注意,需要在800、810都生成,如果已经存在则不用;
此步骤只是一个自动生成的过程,与手工建一样;
菜单:
编辑-》模型观察-》分配
2)事物代码BD95/BD59给消息类型Z_FI_DOCU设置过滤字段
标准的IDOCTYPE是有默认的过滤字段的,自定义的需要自己来设置
BD95
BD59设置字段BLART(凭证类型为筛选字段)
3)事物代码BD64创建过滤
设置筛选,只有类型为DZ的数据才可被出站
准备数据会计凭证1400000009类型为RV
1400000010类型为DZ
4)事物代码SE38执行程序
5)事物代码WE02查看IDOC
只有凭证1400000010被传出,正确;
1.4过滤字段过滤段
事物代码BD53
1.5创建替代规则
事物代码SALE
事物代码BD62创建规则
事物代码BD79替代规则
1.6ChangePoint
事物代码BD61激活changepointer
事物代码BD50Enablechangepointersforamessagetype;
事物代码BD52Specifythefiledsforwhichchangepointsaretobewritten;
程序:
RBDMIDOC来测试
表:
--使用T-code:
SCDO查看Changedocumentobject和它们相应的Table;
--Masterdata发生变化时,会生成changedocument存放在CDHDR和CDPOS表中;
--如果SharedMasterData设置恰当。
会在BDCP表中生成changepointer指向CDHDR表中changedocument;
--通过RBDMIDOC程序定期分析BDCP表中的changepointer,来生成IDOC消息。