ПАРС TXT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
REPORT ztest_files. PARAMETER p_file TYPE string LOWER CASE OBLIGATORY DEFAULT 'C:test.txt'. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. cl_salv_test_data=>select_file( IMPORTING filename = p_file ). START-OF-SELECTION. TYPES:BEGIN OF tab, col1 TYPE char1, col2 TYPE d, END OF tab. DATA: itab TYPE TABLE OF tab, length TYPE I, header TYPE XSTRING. FIELD-SYMBOLS: <fs> TYPE tab. cl_gui_frontend_services=>gui_upload( EXPORTING filename = p_file filetype = 'ASC' codepage = '4110' dat_mode = 'X' IMPORTING filelength = length header = header CHANGING data_tab = itab EXCEPTIONS OTHERS = 99 ). IF sy-subrc <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. WRITE : / 'Размер файла', length, ' Содержимое файла:'. LOOP AT itab ASSIGNING <fs>. WRITE: / sy-tabix,':', 'col1:', <fs>-col1, ' col2',<fs>-col2 MM/DD/YYYY. ENDLOOP. |
Парсим xls
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
REPORT ztest_files. TYPES: BEGIN OF tab, col1 TYPE char1, col2 TYPE char1, col3 TYPE char1, END OF tab. DATA: itab TYPE TABLE OF tab. FIELD-SYMBOLS: <fs> TYPE tab. CALL METHOD cl_gui_frontend_services=>gui_upload EXPORTING filename = 'C:eetext.xls' filetype = 'ASC' has_field_separator = 'X' CHANGING data_tab = itab. IF sy-subrc = 0. WRITE:/ 'success'. ENDIF. LOOP AT itab ASSIGNING <fs>. WRITE: / sy-tabix, ':', 'col1', <fs>-col1, ' col2', <fs>-col2, ' col3', <fs>-col3. ENDLOOP. |
Сохранение Загрузка документов
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
REPORT ztest_files. TABLES: zavto. TYPES: BEGIN OF par_data, col1 TYPE char300, col2 TYPE char300, col3 TYPE char300, END OF par_data. DATA: itab TYPE STANDARD TABLE OF par_data WITH HEADER LINE. DATA: exp_tab TYPE STANDARD TABLE OF par_data. FIELD-SYMBOLS: <fs1> TYPE any, <fs2> TYPE any, <fs3> TYPE any. CALL METHOD cl_gui_frontend_services=>gui_upload EXPORTING filename = 'C:ee1.csv' filetype = 'ASC' * has_field_separator = cl_abap_char_utilities=>horizontal_tab dat_mode = 'X' codepage = '4110' CHANGING data_tab = itab[]. SKIP. LOOP AT itab. APPEND itab TO exp_tab. ENDLOOP. CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING * bin_filesize = filename = 'C:ee2.csv' filetype = 'ASC' * WRITE_field_separator = cl_abap_char_utilities=>horizontal_tab changing data_tab = exp_tab. "--- DATA: col1 TYPE STRING, col2 TYPE STRING, col3 TYPE STRING. LOOP AT itab. col1 = itab-col1. col2 = itab-col2. col3 = itab-col3. WRITE: / col1, col2, col3. APPEND itab TO exp_tab. ENDLOOP. . |
Парс CSV
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
TYPES: BEGIN OF tab, col TYPE char300, END OF tab. TYPES: BEGIN OF par_data, col1 TYPE char300, col2 TYPE char300, col3 TYPE char300, END OF par_data. DATA: itab TYPE TABLE OF tab WITH HEADER LINE, pars TYPE TABLE OF par_data WITH HEADER LINE, tmp_par TYPE TABLE OF par_data WITH HEADER LINE, tmp TYPE TABLE OF char300 WITH HEADER LINE. FIELD-SYMBOLS: <fs1> TYPE any. CALL METHOD cl_gui_frontend_services=>gui_upload EXPORTING filename = 'C:ee1.csv' filetype = 'ASC' * has_field_separator = 'X' dat_mode = 'X' codepage = '4110' CHANGING data_tab = itab[]. SKIP. LOOP AT itab. SPLIT itab-col AT cl_abap_char_utilities=>horizontal_tab INTO TABLE tmp. LOOP AT tmp. ASSIGN COMPONENT sy-tabix OF STRUCTURE tmp_par TO <fs1>. CHECK sy-subrc = 0. <fs1> = tmp. ENDLOOP. APPEND tmp_par TO pars. ENDLOOP. |