公众号:SAP Technical
本文作者:matinal
 

前言部分

大家可以关注我的公众号,公众号里的排版更好,阅读更舒适。

正文部分


*&---------------------------------------------------------------------*
*& Report Z_IDOC_EDI_CONVERT *
*& *
*&---------------------------------------------------------------------*
REPORT Z_IDOC_EDI_CONVERT .
TABLES:ZEDITAB,EDISDEF,EDSAPPL.
*&---------------------------------------------------------------------*
*& Author: ZHT.
*& paramenters region.(parameters)
*&---------------------------------------------------------------------*
PARAMETERS:
P_FILE LIKE FILEPATH-PATHINTERN OBLIGATORY , "read file path.
W_FILE LIKE FILEPATH-PATHINTERN OBLIGATORY , "write file path
CRITERIA TYPE C LENGTH DEFAULT '*' OBLIGATORY,
IDOC_EDI RADIOBUTTON GROUP RDO, "radio button. idoc convert edi.
EDI_IDOC RADIOBUTTON GROUP RDO. "radio button edi convert idoc. IF IDOC_EDI = 'X'.
" Choose idoc convert to edi.
CALL FUNCTION 'ZIDOC_CONVERT_EDI'
EXPORTING
P_FILE = P_FILE
W_FILE = W_FILE
CRITERIA = CRITERIA.
ELSEIF EDI_IDOC = 'X'.
" Choose edi convert to idoc..
CALL FUNCTION 'ZEDI_CONVERT_IDOC'
EXPORTING
P_FILE = P_FILE
W_FILE = W_FILE
CRITERIA = CRITERIA.
ENDIF. ​

idoc convert edi的代码如下:


FUNCTION ZIDOC_CONVERT_EDI.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(P_FILE) TYPE FILENAME-FILEINTERN
*" REFERENCE(W_FILE) TYPE FILENAME-FILEINTERN
*" REFERENCE(CRITERIA) TYPE ZCRITERIA
*"----------------------------------------------------------------------
DATA:
readfielname LIKE filepath-pathintern ,writefielname LIKE filepath-pathintern ,
mess TYPE string,segtype LIKE edsappl-segtyp,str_format TYPE c LENGTH ,
str_filedvalue TYPE c LENGTH ,readresult TYPE c LENGTH ,
curr_field_length TYPE i,_index TYPE i VALUE ,INX TYPE i VALUE ,
len TYPE i,
substring_result TYPE c LENGTH ,
count TYPE i,
str TYPE c LENGTH VALUE '&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&',
read_line_index TYPE i VALUE ,write_str TYPE c LENGTH ,strlenth TYPE i ,
write_result TYPE c LENGTH ,itab_lines TYPE i,
gen_filename TYPE STRING , " generate fileName.
read_filename TYPE STRING, " read file name.
ms_type TYPE c LENGTH ,
prefix_path TYPE c LENGTH , "prefix path,
max_length TYPE i, "last a record .
sigent_filename TYPE Z_FILE_NAME,
document_number TYPE EDI4DOCNUC,
idoc_number TYPE EDI4DOCNUC, wname TYPE string, "temp write file name.
fname_write TYPE String,
fname_read(),
many_record TYPE i,
mess_type TYPE zmestype. "message type.
readfielname = p_file. "logical path.
writefielname = w_file. "physical file.
*&Structure region:(work area)Author: ZHT.
DATA:BEGIN OF idoc_doment_wa,
format_str TYPE c LENGTH ,
read_result TYPE c LENGTH ,
fieldvalue TYPE c LENGTH ,
END OF idoc_doment_wa.
DATA:BEGIN OF writestr, "declare a structure ,
str TYPE string,
strlength TYPE i,
END OF writestr.
DATA:str_itab LIKE TABLE OF writestr.
*&Internal Tables Region.*& Author: ZHT.
DATA:zeditab_itab LIKE STANDARD TABLE OF zeditab WITH HEADER LINE,
zeditab_itab_two LIKE STANDARD TABLE OF zeditab WITH HEADER LINE,
itab_edsappl LIKE STANDARD TABLE OF edsappl WITH HEADER LINE ,
idoc_doment_itab LIKE idoc_doment_wa OCCURS WITH HEADER LINE,
tb_list_of_file LIKE TABLE OF rsfillst,
wa_list_of_file LIKE LINE OF tb_list_of_file.
*&file process .parameters: readfielname and writefielname return a writefielname internal table.
CALL FUNCTION 'ZIDOC_EDI_FILEPROCESS_PATH_FUN'
EXPORTING
CRITERIA = CRITERIA
READFIELNAME = readfielname
READ_FILENAME = read_filename
WRITEFIELNAME = writefielname
GEN_FILENAME = gen_filename
IMPORTING
FNAME_WRITE = fname_write
TABLES
TB_LIST_OF_FILE = tb_list_of_file.
prefix_path = fname_write.
"&loop all files.
LOOP AT tb_list_of_file INTO wa_list_of_file.
CONCATENATE wa_list_of_file-dirname wa_list_of_file-name INTO fname_read .
IF wa_list_of_file-name <> '.' AND wa_list_of_file-name <> '..'.
*&open dataset.(read file).
OPEN DATASET fname_read FOR INPUT IN TEXT MODE ENCODING DEFAULT MESSAGE mess.
DO.
READ DATASET fname_read INTO readresult.
IF sy-subrc <> .
EXIT. "if sy-subrc <> 0.
ENDIF.
IF sy-index = .
mess_type = readresult+(). "get Message type.
idoc_number = readresult+(). "get idoc number.
CLEAR: zeditab_itab,idoc_doment_itab.
SELECT * INTO CORRESPONDING FIELDS OF TABLE zeditab_itab FROM zeditab WHERE messagetype = mess_type AND zidefaultidoc = ''. "search data,. return zditab internal table.
itab_lines = LINES( zeditab_itab ).
wname = wa_list_of_file-name.
CALL FUNCTION 'ZGENERATE_FILENAME_FUNCTION'
EXPORTING
MESS_TYPE = MESS_TYPE
READ_FILE_NAME = WNAME
ZTYPE = 'IDOC_EDI'
IMPORTING
WRITE_FINENAME = gen_filename.
sigent_filename = gen_filename.
fname_write = gen_filename.
CLEAR gen_filename.
ENDIF.
"&if is first line.
IF sy-index <> .
idoc_doment_itab-read_result = readresult.
str_format = idoc_doment_itab-read_result+(). "Reading the document. Get top 7 as a format.
IF str_format = 'E2EDL24'.
many_record = many_record + .
ENDIF.
CALL FUNCTION 'ZHT_SEARCH_EDISDEF' "Call function,import format. return a SEGTYPE.
EXPORTING
strformat = str_format
IMPORTING
segtype = segtype.
idoc_doment_itab-format_str = segtype.
idoc_doment_itab-fieldvalue = readresult+().
APPEND idoc_doment_itab.
CLEAR str_format.
ENDIF.
ENDDO.
CLOSE DATASET fname_read. "Close DataSet
"&Automatic single data processing
CALL FUNCTION 'ZSINGLE_RECORD_FUNCTION'
TABLES
ZEDITAB_ITAB_TWO = ZEDITAB_ITAB_TWO
ZEDITAB_ITAB = ZEDITAB_ITAB
IDOC_DOMENT_ITAB = IDOC_DOMENT_ITAB.
"&Automatic many data processing
CALL FUNCTION 'ZMANY_RECORD_FUNCTION'
EXPORTING
many_record = many_record
TABLES
ZEDITAB_ITAB_TWO = ZEDITAB_ITAB_TWO
ZEDITAB_ITAB = ZEDITAB_ITAB
IDOC_DOMENT_ITAB = IDOC_DOMENT_ITAB.
CLEAR: many_record.
DATA:read_index TYPE i VALUE .
DATA:sum_num TYPE i.
LOOP AT zeditab_itab_two.
sum_num = zeditab_itab_two-edi_index.
ENDLOOP.
REFRESH: zeditab_itab,IDOC_DOMENT_ITAB,str_itab.
"&loop all line.
DO sum_num TIMES.
IF sy-subrc <> .
EXIT.
ENDIF.
LOOP AT zeditab_itab_two WHERE edi_index = _index.
"Append space.
IF read_index = .
write_str = zeditab_itab_two-eancomsegment.
IF STRLEN( write_str ) < .
len = - STRLEN( write_str ).
strlenth = STRLEN( str ) - len.
CONCATENATE write_str str+strlenth(len) INTO write_str.
ENDIF.
ENDIF.
IF zeditab_itab_two-qualifiervalue = space.
strlenth = STRLEN( str ) - zeditab_itab_two-length.
CONCATENATE write_str str+strlenth(zeditab_itab_two-length) INTO write_str.
ELSE.
CALL FUNCTION 'ZIDOC_EDI_REPLACE_FUNCTION' "CALL FUNCTION . replace str. return a resullt.
EXPORTING
qualifiervalue = zeditab_itab_two-qualifiervalue
format = zeditab_itab_two-z_format
param_num =
IMPORTING
reploace_result = zeditab_itab_two-qualifiervalue.
CONCATENATE write_str zeditab_itab_two-qualifiervalue INTO write_str.
ENDIF.
read_index = read_index + .
writestr-str = write_str.
ENDLOOP.
APPEND writestr TO str_itab.
read_index = .
_index = _index + .
ENDDO.
_index = . IF itab_lines <> .
"OPEN DATASET .
CONCATENATE prefix_path fname_write INTO fname_write.
OPEN DATASET fname_write FOR OUTPUT IN TEXT MODE ENCODING DEFAULT MESSAGE mess.
LOOP AT str_itab INTO writestr.
count = STRLEN( writestr-str ).
DO count TIMES.
REPLACE '&' WITH ' ' INTO writestr-str LENGTH . "replace #&# with ' '.
ENDDO.
SELECT COUNT(*) INTO document_number FROM ZEDITAB WHERE EDI_INDEX = INX AND MESSAGETYPE = MESS_TYPE.
INX = INX + .
CALL FUNCTION 'IDOC_EDI_LOGDATA_FUN'
EXPORTING
DOCUMENT_NUMBER = idoc_number "idoc number.
IDOC_MESSAGETYPE = MESS_TYPE
IDOC_NUMBER = document_number "document number.
FILE_NAME = sigent_filename.
WRITE: / writestr-str.
TRANSFER writestr-str TO fname_write.
ENDLOOP.
INX = .
CLOSE DATASET fname_write. "close dataset.
IF itab_lines = .
MESSAGE e000(ZIDOC_EDI_MSG).
ELSE.
MESSAGE s001(ZIDOC_EDI_MSG) WITH fname_write.
ENDIF.
WRITE: / sy-uline.
ENDIF.
CLEAR fname_write.
REFRESH: zeditab_itab,str_itab,zeditab_itab_two.
* DATA:filename TYPE filepath-pathintern.
* filename = wa_list_of_file-name.
* IF MESS_TYPE <> 'ORDRSP'.
* CALL FUNCTION 'ZMOVEOUTEDI_IDOCFILEFUNCITON'
* EXPORTING
* resourefilepath = fname_read
* messagetype = mess_type
* filename = filename.
* ENDIF.
ENDIF.
ENDLOOP.
ENDFUNCTION. ​

【ABAP系列】SAP 一个完整的SAP的Abap例子(idoc,edi文件的相互转换)的更多相关文章

  1. 一个完整的JENKINS下的ANT BUILD.XML文件(Jenkins可以参考)

    一个完整的JENKINS下的ANT BUILD.XML文件 <?xml version="1.0" encoding="UTF-8"?> <p ...

  2. 一个完整的SAP RFC调用接口封装

    因为经常需要访问sap操作数据,就封装了一个类方便调用,运行条件需要安装sap客户端,在sap客户端安装之后会带有一个com接口,本接口就通过这个com访问sap,因为com的后期绑定问题故使用了vb ...

  3. Jenkins进阶系列之——16一个完整的JENKINS下的ANT BUILD.XML文件

    网上看见的,确实很全,该有的基本都覆盖到了.自己拿来稍微改改就可以用了. 注:property中的value是你自己的一些本地变量.需要改成自己的 <?xml version="1.0 ...

  4. 一个完整的JENKINS下的ANT BUILD.XML文件

    网上看见的,确实很全,该有的基本都覆盖到了.自己拿来稍微改改就可以用了. 注:property中的value是你自己的一些本地变量.需要改成自己的 <?xml version="1.0 ...

  5. 【ABAP系列】SAP ABAP BAPI_REQUISITION_CREATE创建采购申请

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP BAPI_RE ...

  6. 【ABAP系列】SAP ABAP 字符编码与解码、Unicode

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP 字符编码与解码 ...

  7. 【ABAP系列】SAP ABAP Break Point

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP Break P ...

  8. 【ABAP系列】SAP ABAP替代校验全解析

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP替代校验全解析 ...

  9. 【ABAP系列】SAP ABAP DATA - COMMON PART

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP DATA - ...

随机推荐

  1. C++使用socket传输图片

    Client: #include <WinSock2.h> #include <Windows.h> #include <stdio.h> #pragma comm ...

  2. Luogu P4171 [JSOI2010]满汉全席 2-sat

    终于搞懂了\(2-sat\).实际上是个挺简单的东西,像网络流一样关键在于建模. 问题:\(n\)个数\(A\),可以选择\(0\)和\(1\),现在给你\(m\)组条件\(A\),\(B\),对每个 ...

  3. JAVA笔记12-接口interface

    1.概念:接口是抽象方法和常量值得定义的集合.本质上,接口是一种特殊的抽象类,这种抽象类只包含常量和方法的定义,而没有变量和方法的实现. 接口定义举例: 2.接口特性: (1)接口可以多重实现:(接口 ...

  4. 【转】深入理解Java多态性

    http://developer.51cto.com/art/200906/130414.htm http://blog.csdn.net/cyzero/article/details/7266831 ...

  5. C# 数据测试

    查询 100w条数据   39列 把100w条数据转换为匿名对象 加入到集合  所用的时间是 32 s 39列 600万条数据

  6. Nowcoder Playing Games ( FWT 优化 DP && 博弈论 && 线性基)

    题目链接 题意 : 给出 N 个数.然后问你最多取出多少石子使得在 NIM 博弈中.后手必胜 分析 :  Nim 博弈模型,后手必胜当且仅当各个堆的石子的数目的异或和为 0 转化一下.变成最少取多少石 ...

  7. Angular 文档中的修改链接是从哪里改的

    如何修改修改的文本的链接. 如下图表示的,如何修改这个地方的链接到自己的 SCM 中. 你需要修改的文件为: aio\tools\transforms\templates\lib\githubLink ...

  8. 3105: [cqoi2013]新Nim游戏

    貌似一道经典题 在第一个回合中,第一个游戏者可以直接拿走若干个整堆的火柴.可以一堆都不拿,但不可以全部拿走.第二回合也一样,第二个游戏者也有这样一次机会.从第三个回合(又轮到第一个游戏者)开始,规则和 ...

  9. 使用word2vec对中文维基百科数据进行处理

    一.下载中文维基百科数据https://dumps.wikimedia.org/zhwiki/并使用gensim中的wikicorpus解析提取xml中的内容 二.利用opencc繁体转简体 三.利用 ...

  10. Super Mario(主席树)

    Super Mario  Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded ...