在系统中,我们经常可以看到EDI方式的输出,与打印输出类似。下面我们基于文章"IDOC实例,Outbound IDOC"的基础上,简单讲解这种方式的IDOC输出。
1,创建一个function:Y_IDOC_PO_SEND.
这是我们的Outbound Funtion Module,用来创建IDOC的内容。同样的,该函数的接口都是标准的。
下面将要介绍的tcode WE41中可以查看系统已有的同类函数,可以参照设置我们的函数接口。然后写入如下代码:
DATA: ls_pohead TYPE ypohead,
ls_poitem TYPE ypoitem,
ls_ekko TYPE ekko,
lt_ekpo TYPE TABLE OF ekpo WITH HEADER LINE.
ls_poitem TYPE ypoitem,
ls_ekko TYPE ekko,
lt_ekpo TYPE TABLE OF ekpo WITH HEADER LINE.
* control_record_out
CLEAR control_record_out.
MOVE control_record_in TO control_record_out.
* control_record_out-mestyp = 'YPO'. "Message Type
* control_record_out-idoctp = 'YPOIDOC'. "IDOC Type
control_record_out-direct = '1'.
control_record_out-serial = sy-datum.
control_record_out-serial+8 = sy-uzeit.
CLEAR control_record_out.
MOVE control_record_in TO control_record_out.
* control_record_out-mestyp = 'YPO'. "Message Type
* control_record_out-idoctp = 'YPOIDOC'. "IDOC Type
control_record_out-direct = '1'.
control_record_out-serial = sy-datum.
control_record_out-serial+8 = sy-uzeit.
* Read from ekko/ekpo
CLEAR ls_ekko.
SELECT SINGLE *
INTO ls_ekko
FROM ekko
WHERE ebeln = object-objky(10) "采购单号
AND loekz = space.
IF sy-subrc <> 0.
RAISE error_message_received.
ENDIF.
CLEAR ls_ekko.
SELECT SINGLE *
INTO ls_ekko
FROM ekko
WHERE ebeln = object-objky(10) "采购单号
AND loekz = space.
IF sy-subrc <> 0.
RAISE error_message_received.
ENDIF.
REFRESH lt_ekpo.
SELECT *
INTO TABLE lt_ekpo
FROM ekpo
WHERE ebeln = ls_ekko-ebeln
AND loekz = space.
SELECT *
INTO TABLE lt_ekpo
FROM ekpo
WHERE ebeln = ls_ekko-ebeln
AND loekz = space.
* INT_EDIDD
CLEAR int_edidd.
int_edidd-docnum = control_record_out-docnum.
int_edidd-segnam = 'YPOHEAD'."结点名称
int_edidd-dtint2 = 0.
CLEAR ls_pohead.
ls_pohead-ebeln = ls_ekko-ebeln.
ls_pohead-bukrs = ls_ekko-bukrs.
ls_pohead-bedat = ls_ekko-bedat.
int_edidd-sdata = ls_pohead. "结点内容
APPEND int_edidd.
CLEAR int_edidd.
int_edidd-docnum = control_record_out-docnum.
int_edidd-segnam = 'YPOHEAD'."结点名称
int_edidd-dtint2 = 0.
CLEAR ls_pohead.
ls_pohead-ebeln = ls_ekko-ebeln.
ls_pohead-bukrs = ls_ekko-bukrs.
ls_pohead-bedat = ls_ekko-bedat.
int_edidd-sdata = ls_pohead. "结点内容
APPEND int_edidd.
LOOP AT lt_ekpo.
CLEAR int_edidd.
int_edidd-docnum = control_record_out-docnum.
int_edidd-segnam = 'YPOITEM'.
int_edidd-dtint2 = 0.
CLEAR ls_poitem.
ls_poitem-ebeln = lt_ekpo-ebeln.
ls_poitem-ebelp = lt_ekpo-ebelp.
ls_poitem-matnr = lt_ekpo-matnr.
ls_poitem-menge = lt_ekpo-menge.
ls_poitem-meins = lt_ekpo-meins.
int_edidd-sdata = ls_poitem.
APPEND int_edidd.
ENDLOOP.
CLEAR int_edidd.
int_edidd-docnum = control_record_out-docnum.
int_edidd-segnam = 'YPOITEM'.
int_edidd-dtint2 = 0.
CLEAR ls_poitem.
ls_poitem-ebeln = lt_ekpo-ebeln.
ls_poitem-ebelp = lt_ekpo-ebelp.
ls_poitem-matnr = lt_ekpo-matnr.
ls_poitem-menge = lt_ekpo-menge.
ls_poitem-meins = lt_ekpo-meins.
int_edidd-sdata = ls_poitem.
APPEND int_edidd.
ENDLOOP.
2,WE41, 创建Outbound Process Code
进入编辑状态后,选择“添加新条目”按钮,创建YPOSEND,对应于新建的Y_IDOC_PO_SEND。
选中下面的Process with ALE Service,代表创建Outbound IDOC后自动发送给接收方。
3,NACE/NACO,创建我们的输出类型
创建一个EDI类型的输出,Program填写RSNASTED,Form Routine填写EDI_PROCESSING。
当然我们也可以在这里找一个已有的EDI输出类型做测试,比如Application EF下的XX01。
4,WE20设置Partner Profile.
前两篇文章中,我们并没有要求填写Partner function,不过这次必须填写了。
Partner function是从属于partner type下面的,这个逻辑关系在表TPAR中体现。
假设我们选中partner type=LS,Partner function=LS。其维护与之前的类似,点击加号添加一个Outbound Parameter,步骤与之前类似,不过必须记得在Message Control中添加一行,Application=EF,Message Type=XX01,Process code为YPOSEND。这里EF和XX01与上面NACO中的定义对应。
5,发送IDOC
事实上,我们已经定义完毕了,可以维护某采购订单的输出类型来发送IDOC了。
为了大家能更好的理解,我们来模仿这个输出过程。创建新程序,写入:
TABLES: nast.
DATA: rcode TYPE i.
DATA: rcode TYPE i.
CLEAR nast.
nast-kappl = 'EF'.
nast-objky = '4014000182'. "采购单号
nast-kschl = 'XX01'.
nast-parnr = 'I02LS'. "Partner number
nast-parvw = 'LS'. "Partner function
PERFORM edi_processing(rsnasted) USING rcode 'X'.
IF rcode IS INITIAL.
COMMIT WORK. "发送IDOC到接收方
COMMIT WORK. "发送IDOC到接收方
ENDIF.
上面的方法并不会在NAST留下输出记录。如果您希望能在NAST中留下一条记录,则应该这样:
TABLES: nast.
DATA: rcode TYPE i.
DATA: rcode TYPE i.
CLEAR nast.
nast-kappl = 'EF'.
nast-objky = '4014000182'.
nast-kschl = 'XX01'.
nast-parnr = 'I02LS'.
nast-parvw = 'LS'.
nast-spras = sy-langu.
nast-erdat = sy-datum.
nast-eruhr = sy-uzeit.
nast-nacha = '6'. "EDI
nast-anzal = 0.
nast-usnam = sy-uname.
PERFORM einzelnachricht(rsnast00) USING rcode.
IF rcode IS INITIAL.
COMMIT WORK. "发送IDOC到接收方
COMMIT WORK. "发送IDOC到接收方
ENDIF.
下面这种方式同样可用于触发其他方式的输出类型,比如打印输出。