Excel in interne Tabelle einlesen

ABAP Snippet um ein Excel in eine interne Tabelle einzulesen.

Like it? Share it!
REPORT zexcel_einlesen. CONSTANTS: co_max_col TYPE i VALUE 20. PARAMETERS: pa_file TYPE localfile OBLIGATORY. TYPE-POOLS: kcde. TYPES: tt_excel TYPE kcde_intern, ts_excel TYPE kcde_intern_struc, tv_data TYPE kcd_text32. TYPES: BEGIN OF ts_data, value_0001 TYPE tv_data, value_0002 TYPE tv_data, value_0003 TYPE tv_data, value_0004 TYPE tv_data, value_0005 TYPE tv_data, value_0006 TYPE tv_data, value_0007 TYPE tv_data, value_0008 TYPE tv_data, value_0009 TYPE tv_data, value_0010 TYPE tv_data, value_0011 TYPE tv_data, value_0012 TYPE tv_data, value_0013 TYPE tv_data, value_0014 TYPE tv_data, value_0015 TYPE tv_data, value_0016 TYPE tv_data, value_0017 TYPE tv_data, value_0018 TYPE tv_data, value_0019 TYPE tv_data, value_0020 TYPE tv_data, END OF ts_data, tt_data TYPE TABLE OF ts_data, tv_value TYPE tv_data, tv_index(4) TYPE n. *&---------------------------------------------------------------------* *& START-OF-SELECTION *&---------------------------------------------------------------------* START-OF-SELECTION. DATA: lt_excel TYPE tt_excel, ls_excel TYPE ts_excel, lt_data TYPE tt_data. * Funktionsbaustein konvertiert Excel in Interne tabelle. * Parameter geben an, ab welcher Zeile bzw. welcher Spalte CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT' EXPORTING filename = pa_file i_begin_col = 1 i_begin_row = 1 i_end_col = 20 i_end_row = 10000 TABLES intern = lt_excel EXCEPTIONS inconsistent_parameters = 1 upload_ole = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. STOP. ENDIF. LOOP AT lt_excel INTO ls_excel. PERFORM itab_befuellen USING ls_excel-col ls_excel-row ls_excel-value CHANGING lt_data. ENDLOOP. PERFORM itab_ausgabe USING lt_data. *&---------------------------------------------------------------------* *& Form excel_prasen *&---------------------------------------------------------------------* FORM excel_prasen CHANGING pt_excel TYPE tt_excel. ENDFORM. "excel_prasen *&---------------------------------------------------------------------* *& Form itab_befuellen *&---------------------------------------------------------------------* FORM itab_befuellen USING pi_col TYPE tv_index pi_row TYPE tv_index pi_value TYPE tv_data CHANGING pt_data TYPE tt_data. DATA: lv_fieldname TYPE string. FIELD-SYMBOLS: <fs_data> TYPE ts_data, <fs_value> TYPE tv_data. CHECK pi_value <> ''. WHILE pi_row > LINES( pt_data ). INSERT INITIAL LINE INTO TABLE pt_data. ENDWHILE. READ TABLE pt_data ASSIGNING <fs_data> INDEX pi_row. ASSERT sy-subrc = 0. CONCATENATE 'VALUE_' pi_col INTO lv_fieldname. ASSIGN COMPONENT lv_fieldname OF STRUCTURE <fs_data> TO <fs_value>. ASSERT sy-subrc = 0. <fs_value> = pi_value. ENDFORM. "itab_befuellen *&---------------------------------------------------------------------* *& Form itab_ausgabe *&---------------------------------------------------------------------* FORM itab_ausgabe USING pt_data TYPE tt_data. DATA: ls_data TYPE ts_data, lv_value TYPE tv_data. LOOP AT pt_data INTO ls_data. WRITE: / sy-tabix. DO co_max_col TIMES VARYING lv_value FROM ls_data-value_0001 NEXT ls_data-value_0002. WRITE: lv_value(10). ENDDO. ENDLOOP. ENDFORM. "itab_ausgabe

>_ Author

>_ last updated 5 yearss ago

>_ Language: ABAP