*&---------------------------------------------------------------------* *& Report Z018 *& *&---------------------------------------------------------------------* *& *& 上传Excel文件 *&---------------------------------------------------------------------* REPORT Z018 MESSAGE-ID ZHQ NO STANDARD PAGE HEADING. PARAMETERS P_FILE TYPE CHAR128 OBLIGATORY. TYPES:BEGIN OF MATERIAL, ID TYPE CHAR10, NAME TYPE CHAR50, END OF MATERIAL. DATA GT_MATERIAL TYPE TABLE OF MATERIAL. DATA GS_MATERIAL TYPE MATERIAL. INITIALIZATION. P_FILE = 'C:\Users\Administrator\Desktop\ABCD.xlsx'. AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE. CALL FUNCTION 'WS_FILENAME_GET' EXPORTING MASK = ',excel,*.xlsx,' MODE = 'O' TITLE = '上传EXCEL表格文件' IMPORTING FILENAME = P_FILE EXCEPTIONS INV_WINSYS = 1 NO_BATCH = 2 SELECTION_CANCEL = 3 SELECTION_ERROR = 4 OTHERS = 5. START-OF-SELECTION. DATA RAW TYPE TRUXS_T_TEXT_DATA. CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP' EXPORTING I_FIELD_SEPERATOR = 'X' I_LINE_HEADER = 'X' I_TAB_RAW_DATA = RAW I_FILENAME = P_FILE TABLES I_TAB_CONVERTED_DATA = GT_MATERIAL EXCEPTIONS CONVERSION_FAILED = 1 OTHERS = 2. END-OF-SELECTION. DATA LEN TYPE I VALUE 0. DESCRIBE TABLE GT_MATERIAL LINES LEN. IF LEN > 0. LOOP AT GT_MATERIAL INTO GS_MATERIAL. WRITE: / GS_MATERIAL-ID,GS_MATERIAL-NAME. ENDLOOP. ELSE. MESSAGE S000 WITH '没有数据' DISPLAY LIKE 'e'. ENDIF.
标签:CONVERT,SELECTION,TEXT,MATERIAL,EXCEL,FILE,TYPE,DATA From: https://www.cnblogs.com/hua900822/p/17381933.html