1、选择excel文件:

PARAMETERS: P_FILE  LIKE RLGRAP-FILENAME OBLIGATORY.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
   EXPORTING
     PROGRAM_NAME        = SYST-REPID
     DYNPRO_NUMBER       = SYST-DYNNR
*     FIELD_NAME          = ' '
     STATIC              = 'X'
     MASK                = ',*.XLS,*.XLS'
    CHANGING
      FILE_NAME           = P_FILE
   EXCEPTIONS
     MASK_TOO_LONG       = 1
     OTHERS              = 2
            .
  DATA: lt_file_table TYPE filetable.
  DATA: lv_fn TYPE LINE OF filetable.
  DATA: lv_rc TYPE i.
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
*     WINDOW_TITLE            =
*     DEFAULT_EXTENSION       =
*     DEFAULT_FILENAME        =
      file_filter             = cl_gui_frontend_services=>filetype_excel
    CHANGING
      file_table              = lt_file_table
      rc                      = lv_rc
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.

 

2、导入到与excel文件字段一致的内表:

TYPE-POOLS TRUXS.
DATA  GT_RAW TYPE TRUXS_T_TEXT_DATA.
TYPES: BEGIN OF GTY_EXCEL,
    COL1    TYPE  STRING,
    COL2    TYPE  STRING,
END OF GTY_EXCEL.
DATA: GT_EXCEL TYPE TABLE OF GTY_EXCEL,
      GS_EXCEL TYPE GTY_EXCEL.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*   I_FIELD_SEPERATOR          =
     I_LINE_HEADER              = 'X'
     I_TAB_RAW_DATA             = GT_RAW
     I_FILENAME                 = P_FILE
    TABLES
     I_TAB_CONVERTED_DATA       = GT_EXCEL
   EXCEPTIONS
     CONVERSION_FAILED          = 1
     OTHERS                     = 2
            .

 3、类似函数

TEXT_CONVERT_CSV_TO_SAP
TEXT_CONVERT_TEX_TO_SAP
TEXT_CONVERT_TXT_TO_SAP
TEXT_CONVERT_XLS_TO_SAP
TEXT_CONVERT_XML_TO_SAP

 

SAP_CONVERT_TO_CSV_FORMAT
SAP_CONVERT_TO_TEX_FORMAT
SAP_CONVERT_TO_TXT_FORMAT
SAP_CONVERT_TO_XLS_FORMAT
SAP_CONVERT_TO_XML_FORMAT

posted on 2016-07-28 17:29  小伙儿  阅读(5380)  评论(0编辑  收藏  举报