메뉴 건너뛰기

SAP 한국 커뮤니티




REPORT zr_dynamic_table_update_excel NO STANDARD PAGE HEADING.
*** --- Data Declarations
DATA:lt_excel       TYPE TABLE OF alsmex_tabline,
     lt_dref        TYPE REF TO data,
     ls_dref        TYPE REF TO data,
     lv_col         TYPE i,
     lo_alv         TYPE REF TO cl_salv_table,
     lt_table_filds TYPE TABLE OF dfies.
*** --- Field Symbols
FIELD-SYMBOLS : <fs_table> TYPE any .
FIELD-SYMBOLS : <ft_table> TYPE STANDARD TABLE.
FIELD-SYMBOLS : <dyn_field> .

*** --- Selection screen designing
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS:p_file  TYPE rlgrap-filename OBLIGATORY,
           p_table TYPE dd02l-tabname OBLIGATORY,
           p_test  AS CHECKBOX DEFAULT abap_true.
SELECTION-SCREEN END OF BLOCK b1.

*** --- value request for p_file
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    IMPORTING
      file_name = p_file.
*** --- START-OF-SELECTION
START-OF-SELECTION.
*create OBJECT lr_descr.
*** --- Assigning fields symbols for Tables
  CREATE DATA lt_dref TYPE TABLE OF (p_table).
  CREATE DATA ls_dref TYPE (p_table).
*** --- Assign field symbol with table type of DDIC
  ASSIGN lt_dref->* TO <ft_table>.
*** --- Assign field symbol with Structure type of DDIC
  ASSIGN ls_dref->* TO <fs_table>.
*** --- Call the Function module ALSM_EXCEL_TO_INTERNAL_TABLE
  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = p_file
      i_begin_col             = 1
      i_begin_row             = 1
      i_end_col               = 99
      i_end_row               = 999999
    TABLES
      intern                  = lt_excel
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      OTHERS                  = 3.
  IF sy-subrc EQ 0.
*** --- Sort
    SORT lt_excel BY row.

    LOOP AT lt_excel INTO DATA(ls_excel).

*** --- Adding count to skip the mapping for MANDT field
      lv_col = ls_excel-col + 1.
      ASSIGN COMPONENT lv_col OF STRUCTURE <fs_table> TO <dyn_field>.
      IF sy-subrc = 0.
***-- Compare Excel sheet column data and Dynamic table fields
            IF ls_excel-row = 1.
              CALL FUNCTION 'DDIF_FIELDINFO_GET'
                EXPORTING
                  tabname        = p_table
                TABLES
                  dfies_tab      = lt_table_filds
                EXCEPTIONS
                  not_found      = 1
                  internal_error = 2
                  OTHERS         = 3.
              READ TABLE lt_table_filds INTO DATA(ls_table_fields) INDEX lv_col.
              IF sy-subrc = 0.
                IF ls_table_fields-fieldname NE ls_excel-value.
                  WRITE: 'Excel sheet data and Dynamic table fields are not matching'.
                  EXIT.
                ENDIF.
              ENDIF.
            ELSE.
              <dyn_field> = ls_excel-value.
            ENDIF.
      ENDIF.
      IF ls_excel-row GT 1.
        AT END OF row.
          APPEND <fs_table> TO <ft_table>.
          CLEAR <fs_table>.
        ENDAT.
      ENDIF.
    ENDLOOP.

    IF <ft_table> IS NOT INITIAL.
      IF p_test IS INITIAL.
*** --- Modify
        MODIFY (p_table) FROM TABLE <ft_table>.
        IF sy-subrc EQ 0.
          COMMIT WORK.
          DATA(lv_lines) = lines( <ft_table> ).
          WRITE: TEXT-002,lv_lines.
        ELSE.
          ROLLBACK WORK.
          MESSAGE TEXT-003 TYPE 'E' DISPLAY LIKE 'I'.
        ENDIF.
      ELSE.
*** --- Factory Method
        cl_salv_table=>factory(
          IMPORTING
            r_salv_table   =  lo_alv   " Basis Class Simple ALV Tables
          CHANGING
            t_table        = <ft_table>
        ).
*** --- Display
        lo_alv->display( ).
      ENDIF.
    ENDIF.
  ENDIF.

image.png

 

 

출처 : https://blogs.sap.com/2019/09/20/dynamically-update-data-from-excel-to-database-table/

 

번호 제목 글쓴이 날짜 조회 수
공지 자료실 업로드에 관련하여... [183] 보나 2009.11.05 340175
» 엑셀 파일을 동적으로 테이블에 업데이트 하는 프로그램 file sapabap 2019.10.22 119
1360 S/4 HANA 소개자료 Simplication [2] file sapjoy 2019.02.27 2406
1359 S/4 HANA 1809 소개자료(주요변화사항) [5] file sapjoy 2019.02.25 1062
1358 NEPTUNE 솔루션 SAP 데이터를 FIORI로 보여주는 솔루션입니다. easy abap(김성준) 2018.09.07 942
1357 개발자 가이드 for SAP HANA STUDIO [4] file 얀웬리 2018.08.10 1751
1356 S4 HANA IDES 설치 따라하기 [2] easy abap(김성준) 2018.07.14 1528
1355 Transaction code naming [2] easy abap(김성준) 2018.02.12 1958
1354 User Exit 질문 [3] 푸딩딩 2017.04.17 4677
1353 GRID 밤의화신 2017.04.04 3659
1352 Next Generation ABAP Development (2007 영문 PDF) file 대략나 2016.12.20 3902
1351 Graphical Form Painter could not be called (FORMPAINTER_CREATE_WINDOW, ) [1] easy abap(김성준) 2016.11.22 3788
1350 PI/XI 7.0 Alert Config 영문 file cry6 2016.09.01 3575
1349 PI/XI 7.1 Troubleshooting Guide - 영문 file cry6 2016.09.01 3235
1348 Excel Macro 이용한 Table Layout file 아네사 2016.08.19 3871
1347 모든 CBO 테이블 엑셀 업로드 프로그램 [1] easy abap(김성준) 2016.08.17 5185
1346 LSMW example (FK01 - vendor master create ) [2] file cupycopy2000 2016.04.30 3784
1345 ABAP Debugging Tips and Tricks [4] file 아밥뽀 2016.03.31 4516
1344 ALV with IDA(Integrated Data Access ) 설명 및 한글 자료 있으신 분 있으신가요 ? [1] miss841 2016.01.19 4452
1343 ABAP 7.40 Quick Reference [5] easy abap(김성준) 2015.11.19 6669
1342 SAP NetWeaver Application Server ABAP 7.4 Overview and Product Highlight file easy abap(김성준) 2015.11.12 3824