zoukankan      html  css  js  c++  java
  • 读取EXCEL到内表


    report ztest2.


    DATA: filetab TYPE filetable WITH HEADER LINE .
    DATA: rc TYPE i.
    DATA: outtab TYPE TABLE OF mara WITH HEADER LINE  .
    DATA: itab TYPE TABLE OF alsmex_tabline WITH HEADER LINE.
    DATA:g_file TYPE rlgrap-filename.

    FIELD-SYMBOLS: <fs>.

    PARAMETERS: p_file TYPE string.


    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

      CALL METHOD cl_gui_frontend_services=>file_open_dialog
        EXPORTING
          default_filename = p_file
        CHANGING
          rc               = rc
          file_table       = filetab[].


      READ TABLE  filetab INDEX  1.

      IF sy-subrc EQ 0.
        p_file = filetab-filename.
      ENDIF.


    START-OF-SELECTION.

      g_file = p_file.  "注意两个文件用于不同的函数,所以类型不同

      CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
        EXPORTING
          filename    = g_file
          i_begin_col = 1
          i_begin_row = 1
          i_end_col   = 255
          i_end_row   = 65536
        TABLES
          intern      = itab[].

      DELETE itab WHERE row = 1.  "删除字段名行

      LOOP AT itab.
        ON CHANGE OF itab-row.
          IF sy-tabix NE 1.
            APPEND outtab.
            CLEAR outtab.
          ENDIF.
        ENDON.

        ASSIGN COMPONENT itab-col OF STRUCTURE outtab TO <fs>.         "动态方法将值传到相应的内表
        <fs> = itab-value.
      ENDLOOP.


      APPEND outtab.   "这句不要忘记,要把最后一条APPEND到内表中

  • 相关阅读:
    POJ 1981 Circle and Points (扫描线)
    UVA 1514 Piece it together (二分图匹配)
    CodeForces 140D New Year Contest
    HDU 4863 Centroid of a Tree
    HDU 4865 Peter's Hobby
    HDU 4870 Rating
    HDU 4864 Task
    CodeForces 766E Mahmoud and a xor trip
    CodeForces 766D Mahmoud and a Dictionary
    CodeForces 767D Cartons of milk
  • 原文地址:https://www.cnblogs.com/eric0701/p/3772346.html
Copyright © 2011-2022 走看看