码迷,mamicode.com
首页 > 其他好文 > 详细

ZTEST003

时间:2018-05-09 01:19:15      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:lan   class   ola   iter   tran   char   out   mod   other   

REPORT  ZTEST003.

DATA: BEGIN OF GS_DATA ,
    COLA TYPE STRING,
    COLB TYPE STRING,
  END OF GS_DATA,
  GT_DATA LIKE TABLE OF GS_DATA.




DATA LV_FILE LIKE RLGRAP-FILENAME VALUE /usr/sap/D01/DVEBMGS00/data/CSV_TEST.csv.


DATA: LO_CSV TYPE REF TO CL_RSDA_CSV_CONVERTER,
      LV_CPCODEPAGE TYPE CPCODEPAGE,
      LV_CSV(1024).


CALL METHOD CL_RSDA_CSV_CONVERTER=>CREATE
*  EXPORTING
*    i_delimiter = C_DEFAULT_DELIMITER
*    i_separator = C_DEFAULT_SEPARATOR
      RECEIVING
        R_R_CONV    = LO_CSV.

OPEN DATASET LV_FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC = 0.
  DO.
    READ DATASET LV_FILE INTO LV_CSV.
    IF SY-SUBRC = 0.
      CLEAR GS_DATA.
      "去除CSV每一行结尾的换行符#
      CALL FUNCTION NLS_GET_FRONTEND_CP
        EXPORTING
          LANGU                 = SY-LANGU
          FETYPE                = MS
        IMPORTING
          FRONTEND_CODEPAGE     = LV_CPCODEPAGE
        EXCEPTIONS
          ILLEGAL_SYST_CODEPAGE = 1
          NO_FRONTEND_CP_FOUND  = 2
          INTERNAL_OR_DB_ERROR  = 3
          OTHERS                = 4.
      CALL FUNCTION SCP_REPLACE_STRANGE_CHARS
        EXPORTING
          INTEXT            = LV_CSV
          INTER_CP          = LV_CPCODEPAGE
          REPLACEMENT       = 32
        IMPORTING
          OUTTEXT           = LV_CSV
        EXCEPTIONS
          INVALID_CODEPAGE  = 1
          CODEPAGE_MISMATCH = 2
          INTERNAL_ERROR    = 3
          CANNOT_CONVERT    = 4
          FIELDS_NOT_TYPE_C = 5
          OTHERS            = 6.
      CALL METHOD LO_CSV->CSV_TO_STRUCTURE
        EXPORTING
          I_DATA   = LV_CSV
        IMPORTING
          E_S_DATA = GS_DATA.
      APPEND GS_DATA TO GT_DATA.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.
  CLOSE DATASET LV_FILE.
ELSE.
  MESSAGE Cannot open file! TYPE E .

ENDIF.

 

ZTEST003

标签:lan   class   ola   iter   tran   char   out   mod   other   

原文地址:https://www.cnblogs.com/wangxiaowen/p/9011701.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!