Friday, 23 June 2017

How to read two sheets from excel.


step1:

create custom function module from standard FM.








Source Code:


FUNCTION zalsm_excel_to_internal_table .
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(FILENAME) LIKE  RLGRAP-FILENAME
*"     VALUE(I_BEGIN_COL) TYPE  I
*"     VALUE(I_BEGIN_ROW) TYPE  I
*"     VALUE(I_END_COL) TYPE  I
*"     VALUE(I_END_ROW) TYPE  I
*"     REFERENCE(SHEETS) TYPE  I
*"  TABLES
*"      IT_DATA STRUCTURE  ZALSMEX_TABLINE
*"  EXCEPTIONS
*"      INCONSISTENT_PARAMETERS
*"      UPLOAD_OLE
*"----------------------------------------------------------------------

  DATA: excel_tab     TYPE  ty_t_sender.
  DATA: ld_separator  TYPE  c.
  DATA: application TYPE  ole2_object,
        workbook    TYPE  ole2_object,
        range       TYPE  ole2_object,
        worksheet   TYPE  ole2_object.

  DATA: h_cell  TYPE  ole2_object,
        h_cell1 TYPE  ole2_object,
        intern  TYPE  ty_t_itab.
  TYPES: BEGIN OF st_sheets,
           sheets TYPE i,
         END OF st_sheets.
  DATA:
    ld_rc     TYPE i,
    it_sheets TYPE STANDARD TABLE OF st_sheets,
    wa_sheets TYPE st_sheets,
    sheetno   TYPE i.
*   Rückgabewert der Methode "clipboard_export     "

* Makro für Fehlerbehandlung der Methods
  DEFINE m_message.
    case sy-subrc.
      when 0.
      when 1.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      when others. raise upload_ole.
    endcase.
  END-OF-DEFINITION.


* check parameters
  IF i_begin_row > i_end_row. RAISE inconsistent_parameters. ENDIF.
  IF i_begin_col > i_end_col. RAISE inconsistent_parameters. ENDIF.

* Get TAB-sign for separation of fields
  CLASS cl_abap_char_utilities DEFINITION LOAD.
  ld_separator = cl_abap_char_utilities=>horizontal_tab.

* open file in Excel
  IF application-header = space OR application-handle = -1.
    CREATE OBJECT application 'Excel.Application'.
    m_message.
  ENDIF.
  CALL METHOD OF application 'Workbooks' = workbook.
  m_message.
  CALL METHOD OF workbook 'Open' EXPORTING #1 = filename.
  m_message.

  DO sheets TIMES.
    sheetno = sheetno + 1.
    GET PROPERTY OF  application 'ACTIVESHEET' = worksheet.
    m_message.
    CALL METHOD OF
        application
        'Worksheets' = worksheet
      EXPORTING
        #1           = sheetno.
    m_message.
    CALL METHOD OF
      worksheet
      'Activate'.

    m_message.

    GET PROPERTY OF application 'ACTIVESHEET' = worksheet.

    m_message.

* mark whole spread sheet
    CALL METHOD OF
        worksheet
        'Cells'   = h_cell
      EXPORTING
        #1        = i_begin_row
        #2        = i_begin_col.
    m_message.
    CALL METHOD OF
        worksheet
        'Cells'   = h_cell1
      EXPORTING
        #1        = i_end_row
        #2        = i_end_col.
    m_message.

    CALL METHOD OF
        worksheet
        'RANGE'   = range
      EXPORTING
        #1        = h_cell
        #2        = h_cell1.
    m_message.
    CALL METHOD OF
      range
      'SELECT'.
    m_message.

* copy marked area (whole spread sheet) into Clippboard
    CALL METHOD OF
      range
      'COPY'.
    m_message.

* read clipboard into ABAP
    CALL METHOD cl_gui_frontend_services=>clipboard_import
      IMPORTING
        data       = excel_tab
      EXCEPTIONS
        cntl_error = 1
*       ERROR_NO_GUI         = 2
*       NOT_SUPPORTED_BY_GUI = 3
        OTHERS     = 4.
    IF sy-subrc <> 0.
      MESSAGE a037(alsmex).
    ENDIF.

    PERFORM separated_to_intern_convert TABLES excel_tab intern
                                        USING  ld_separator
                                               sheetno.
    APPEND LINES OF intern TO it_data.

* clear clipboard
    REFRESH excel_tab.
    CALL METHOD cl_gui_frontend_services=>clipboard_export
      IMPORTING
        data       = excel_tab
      CHANGING
        rc         = ld_rc
      EXCEPTIONS
        cntl_error = 1
*       ERROR_NO_GUI         = 2
*       NOT_SUPPORTED_BY_GUI = 3
        OTHERS     = 4.

  ENDDO.
* quit Excel and free ABAP Object - unfortunately, this does not kill
* the Excel process
  CALL METHOD OF
    application
    'QUIT'.
  m_message.

* >>>>> Begin of change note 575877
* to kill the Excel process it's necessary to free all used objects
  FREE OBJECT h_cell.       m_message.
  FREE OBJECT h_cell1.      m_message.
  FREE OBJECT range.        m_message.
  FREE OBJECT worksheet.    m_message.
  FREE OBJECT workbook.     m_message.
  FREE OBJECT application.  m_message.
* <<<<< End of change note 575877

ENDFUNCTION.






1.Include LZALSMEXTOP


FUNCTION-POOL ZALSMEX.                  "MESSAGE-ID ..

TYPE-POOLS: ole2.
*      value of excel-cell
TYPES: ty_d_itabvalue             TYPE zalsmex_tabline-value,
*      internal table containing the excel data
       ty_t_itab                  TYPE zalsmex_tabline   OCCURS 0,
*      line type of sender table
       BEGIN OF ty_s_senderline,
         line(4096)               TYPE c,
       END OF ty_s_senderline,
*      sender table
       ty_t_sender                TYPE ty_s_senderline  OCCURS 0.

CONSTANTS:  gc_esc              VALUE '"'.



2. INCLUDE LZALSMEXUXX.

if you double click above the below include will come

*****************************************************************
*   THIS FILE IS GENERATED BY THE FUNCTION LIBRARY.             *
*   NEVER CHANGE IT MANUALLY, PLEASE!                           *
*****************************************************************
INCLUDE LZALSMEXU01.
                    "ZALSM_EXCEL_TO_INTERNAL_TABLE



The above include is source code of FM.

3. LZALSMEXF01


*----------------------------------------------------------------------*
***INCLUDE LAALSMEXF01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  SEPARATED_TO_INTERN_CONVERT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM SEPARATED_TO_INTERN_CONVERT TABLES I_TAB       TYPE TY_T_SENDER
                                        I_INTERN    TYPE TY_T_ITAB
                                 USING  I_SEPARATOR TYPE C
                                        P_SHEETNO.
  DATA: L_SIC_TABIX LIKE SY-TABIX,
        L_SIC_COL   TYPE KCD_EX_COL.
  DATA: L_FDPOS     LIKE SY-FDPOS.

  REFRESH I_INTERN.

  LOOP AT I_TAB.
    L_SIC_TABIX = SY-TABIX.
    L_SIC_COL = 0.
    WHILE I_TAB CA I_SEPARATOR.
      L_FDPOS = SY-FDPOS.
      L_SIC_COL = L_SIC_COL + 1.
      PERFORM LINE_TO_CELL_SEPARAT TABLES I_INTERN
                                   USING  I_TAB L_SIC_TABIX L_SIC_COL
                                          I_SEPARATOR L_FDPOS
                                          P_SHEETNO. " added by  06.10.2014
    ENDWHILE.
    IF I_TAB <> SPACE.
      CLEAR I_INTERN.
      I_INTERN-ROW = L_SIC_TABIX.
      I_INTERN-COL = L_SIC_COL + 1.
      I_INTERN-VALUE = I_TAB.
      I_INTERN-SHEETNO = P_SHEETNO. " added  - 06.10.2014
      APPEND I_INTERN.
     ENDIF.
  ENDLOOP.
ENDFORM.                    " SEPARATED_TO_INTERN_CONVERT
*---------------------------------------------------------------------*
FORM LINE_TO_CELL_SEPARAT TABLES I_INTERN    TYPE TY_T_ITAB
                          USING  I_LINE
                                 I_ROW       LIKE SY-TABIX
                                 CH_CELL_COL TYPE KCD_EX_COL
                                 I_SEPARATOR TYPE C
                                 I_FDPOS     LIKE SY-FDPOS
                                 P_SHEETNO." added by  06.10.2014
  DATA: L_STRING   TYPE TY_S_SENDERLINE.
  DATA  L_SIC_INT  TYPE I.

  CLEAR I_INTERN.
  L_SIC_INT = I_FDPOS.
  I_INTERN-ROW = I_ROW.
  L_STRING = I_LINE.
  I_INTERN-COL = CH_CELL_COL.
* csv Dateien mit separator in Zelle: --> ;"abc;cd";
  IF ( I_SEPARATOR = ';' OR  I_SEPARATOR = ',' ) AND
       L_STRING(1) = GC_ESC.
      PERFORM LINE_TO_CELL_ESC_SEP USING L_STRING
                                         L_SIC_INT
                                         I_SEPARATOR
                                         I_INTERN-VALUE.
  ELSE.
    IF L_SIC_INT > 0.
      I_INTERN-VALUE = I_LINE(L_SIC_INT).
    ENDIF.
  ENDIF.
  IF L_SIC_INT > 0.
    I_INTERN-SHEETNO = P_SHEETNO. " added  - 06.10.2014
    APPEND I_INTERN.
  ENDIF.
  L_SIC_INT = L_SIC_INT + 1.
  I_LINE = I_LINE+L_SIC_INT.
ENDFORM.

*---------------------------------------------------------------------*
FORM LINE_TO_CELL_ESC_SEP USING I_STRING
                                I_SIC_INT      TYPE I
                                I_SEPARATOR    TYPE C
                                I_INTERN_VALUE TYPE TY_D_ITABVALUE.
  DATA: L_INT TYPE I,
        L_CELL_END(2).
  FIELD-SYMBOLS: <L_CELL>.
  L_CELL_END = GC_ESC.
  L_CELL_END+1 = I_SEPARATOR .

  IF I_STRING CS GC_ESC.
    I_STRING = I_STRING+1.
    IF I_STRING CS L_CELL_END.
      L_INT = SY-FDPOS.
      ASSIGN I_STRING(L_INT) TO <L_CELL>.
      I_INTERN_VALUE = <L_CELL>.
      L_INT = L_INT + 2.
      I_SIC_INT = L_INT.
      I_STRING = I_STRING+L_INT.
    ELSEIF I_STRING CS GC_ESC.
*     letzte Celle
      L_INT = SY-FDPOS.
      ASSIGN I_STRING(L_INT) TO <L_CELL>.
      I_INTERN_VALUE = <L_CELL>.
      L_INT = L_INT + 1.
      I_SIC_INT = L_INT.
      I_STRING = I_STRING+L_INT.
      L_INT = STRLEN( I_STRING ).
      IF L_INT > 0 . MESSAGE X001(KX) . ENDIF.
    ELSE.
      MESSAGE X001(KX) . "was ist mit csv-Format
    ENDIF.
  ENDIF.
ENDFORM.

**********************************************************************************
Program to Read Mulitiple Sheets:


report zsalary_posting_us30.

types: begin of ty_sheet1,
         h1  type string,
         h2  type string,
         h3  type string,
         h4  type string,
         h5  type string,
         h6  type string,
         h7  type string,
         h8  type string,
         h9  type string,
         h10 type string,
         h11 type string,
         h12 type string,
         h13 type string,
       end of ty_sheet1.

data: it_sheet1 type table of ty_sheet1,
      wa_sheet1 type ty_sheet1.
data: it_sheet3 type table of ty_sheet1,
      wa_sheet3 type ty_sheet1.

types: begin of ty_sheet2,
         h1    type string,
         h2    type string,
         h3    type string,
         h4    type string,
         h5    type string,
         h6    type string,
         h7    type string,
         h8    type string,
         h9    type string,
         gl_1  type string,
         gl_2  type string,
         gl_3  type string,
         gl_4  type string,
         gl_5  type string,
         gl_6  type string,
         gl_7  type string,
         gl_8  type string,
         gl_9  type string,
         gl_10 type string,
         gl_11 type string,
         gl_12 type string,
         gl_13 type string,
         gl_14 type string,
         gl_15 type string,
         gl_16 type string,
         gl_17 type string,
         gl_18 type string,
         gl_19 type string,
         gl_20 type string,
         gl_21 type string,
         gl_22 type string,
         gl_23 type string,
         gl_24 type string,
         gl_25 type string,
         gl_26 type string,
       end of ty_sheet2.

data: it_sheet2 type table of ty_sheet2,
      wa_sheet2 type ty_sheet2.

data: lv_sheets      type i,
      v_document_url type c length 128,
      p_rows         type i value 1,
      p_cols         type i value 1,
      i_intern       type table of zalsmex_tabline,
      w_intern       type zalsmex_tabline.



parameters: p_file type rlgrap-filename.

at selection-screen on value-request for p_file.
*  call function 'F4_FILENAME'
*    exporting
*      program_name  = syst-cprog
*      dynpro_number = syst-dynnr
**     FIELD_NAME    = ' '
*    importing
*      file_name     = p_file.

  perform sub_file_f4.


start-of-selection.

  concatenate 'FILE://' p_file into v_document_url.
  clear : i_intern[].
  lv_sheets = '2'. " Sheet Number in Excel File

  call function 'ZALSM_EXCEL_TO_INTERNAL_TABLE'
    exporting
      filename                = v_document_url
      i_begin_col             = p_rows
      i_begin_row             = p_cols
      i_end_col               = 35
      i_end_row               = 65535
      sheets                  = lv_sheets
    tables
      it_data                 = i_intern
    exceptions
      inconsistent_parameters = 1
      upload_ole              = 2
      others                  = 3.
  if sy-subrc <> 0.
* Implement suitable error handling here
  endif.

  if i_intern[] is not initial.
    delete i_intern where row = 1. " Delete Header Text in Excel File
  endif.

  perform split_multiple_tab.

form split_multiple_tab.

  data: lv_tabix     type i value '1',
        lv_col(4)    type n,
        lv_row_count type i.
  clear:lv_row_count.
  describe table i_intern lines lv_row_count.
  data: lv_sheetno type i.
  clear: it_sheet1[],it_sheet2[].


  loop at i_intern into w_intern.

    sy-tabix = lv_tabix.

    if lv_row_count < lv_tabix .
      exit.
    endif.

    read table i_intern into w_intern index  lv_tabix.
    if sy-subrc = 0.
      clear : lv_sheetno.
      lv_sheetno = w_intern-sheetno.
    endif.

*  Move Excel values to internal Table.

    if lv_sheetno = '1'. " Header

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet1-h1 = w_intern-value.
        lv_tabix = lv_tabix + 1.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet1-h2 = w_intern-value.
        lv_tabix = lv_tabix + 1.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet1-h3 = w_intern-value.
        lv_tabix = lv_tabix + 1.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet1-h4 = w_intern-value.
        lv_tabix = lv_tabix + 1.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet1-h5 = w_intern-value.
        lv_tabix = lv_tabix + 1.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet1-h6 = w_intern-value.
        lv_tabix = lv_tabix + 1.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet1-h7 = w_intern-value.
        lv_tabix = lv_tabix + 1.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet1-h8 = w_intern-value.
        lv_tabix = lv_tabix + 1.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet1-h9 = w_intern-value.
        lv_tabix = lv_tabix + 1.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet1-h10 = w_intern-value.
        lv_tabix = lv_tabix + 1.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet1-h11 = w_intern-value.
        lv_tabix = lv_tabix + 1.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet1-h12 = w_intern-value.
        lv_tabix = lv_tabix + 1.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet1-h13 = w_intern-value.
        lv_tabix = lv_tabix + 1.
      endif.
      append wa_sheet1 to it_sheet1.

    elseif lv_sheetno = '2'.
      lv_tabix = lv_tabix - 1.
      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
*        IF w_intern-value = '#'.
*          w_intern-value = ''.
*        ENDIF.
        condense w_intern-value.
        wa_sheet2-h1 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-h2 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-h3 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-h4 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-h5 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-h6 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-h7 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-h8 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-h9 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_1 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_2 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

 read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_3 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

 read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_4 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_5 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_6 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_7 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_8 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_9 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_10 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_11 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

      read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_12 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.


 read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_13 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

  read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_14 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_15 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_16 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_17 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_18 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_19 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_20 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_21 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_22 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_23 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_24 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

  read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_25 = w_intern-value.
        lv_tabix = lv_tabix + 1.
        clear : w_intern.
      endif.

read table i_intern into w_intern index lv_tabix.
      if sy-subrc eq 0.
        condense w_intern-value.
        wa_sheet2-gl_26 = w_intern-value.
       lv_tabix = lv_tabix + 1.
        clear : w_intern.
         lv_tabix = lv_tabix + 1.
      endif.

      append wa_sheet2 to it_sheet2.

    endif.

  endloop.

  move: it_sheet1 to it_sheet3.

endform.


form sub_file_f4 .
  data:
    l_desktop  type string,
    l_i_files  type filetable,
    l_wa_files type file_table,
    l_rcode    type int4.

* Finding desktop
  call method cl_gui_frontend_services=>get_desktop_directory
    changing
      desktop_directory    = l_desktop
    exceptions
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      others               = 4.
  if sy-subrc <> 0.
    message e001(00) with
    'Desktop not found'.
  endif.

* Update View
  call method cl_gui_cfw=>update_view
    exceptions
      cntl_system_error = 1
      cntl_error        = 2
      others            = 3.

  call method cl_gui_frontend_services=>file_open_dialog
    exporting
      window_title            = 'Select Excel file'
*     default_extension       = '.xls'
*     file_filter             = '.xls'
      initial_directory       = l_desktop
    changing
      file_table              = l_i_files
      rc                      = l_rcode
    exceptions
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      others                  = 5.
  if sy-subrc <> 0.
    message e001(00) with 'Error while opening file'.
  endif.

  read table l_i_files index 1 into l_wa_files.
  if sy-subrc = 0.
    p_file = l_wa_files-filename.
  else.
    message e001(00) with 'Error while opening file'.
  endif.

endform.



No comments:

Post a Comment