SAP Upload Excel document into internal table

ABAP code for uploading an Excel document into an internal table. See code below for structures. The code is based on uploading a simple Excel spreadsheet or for an actual Excel file click here.

There are also a couple of alternatives which use fucntion modules 'KCD_EXCEL_OLE_TO_INT_CONVERT' and 'ALSM_EXCEL_TO_INTERNAL_TABLE' but the method below is by far the simplest method to used. A big thanks to Jayanta for bringing this method to my attention.

Update: Just tried uploading a file which was in the new MS excel format (.xlsx) using the below method but unfortunately it did not work. Using 'ALSM_EXCEL_TO_INTERNAL_TABLE' or 'KCD_EXCEL_OLE_TO_INT_CONVERT' function modules still uploads .xlsx files though.

*..............................................................
*: Description                                                :
*: -----------                                                :
*: This is a simple example program to get data from an excel :
*: file and store it in an internal table.                    :
*:                                                            :
*: Author : www.SAP Development, based on code from Jayanta      :
*:                                                            :
*: SAP Version : 4.7                                          :
*:............................................................:
REPORT  zupload_excel_to_itab.
TYPE-POOLS: truxs.
PARAMETERS: p_file TYPE  rlgrap-filename.
TYPES: BEGIN OF t_datatab,
      col1(30)    TYPE c,
      col2(30)    TYPE c,
      col3(30)    TYPE c,
      END OF t_datatab.
DATA: it_datatab type standard table of t_datatab,
      wa_datatab type t_datatab.
DATA: it_raw TYPE truxs_t_text_data.
* At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      field_name = 'P_FILE'
    IMPORTING
      file_name  = p_file.
***********************************************************************
*START-OF-SELECTION.
START-OF-SELECTION.
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR        =
      i_line_header            =  'X'
      i_tab_raw_data           =  it_raw       " WORK TABLE
      i_filename               =  p_file
    TABLES
      i_tab_converted_data     = it_datatab[]    "ACTUAL DATA
   EXCEPTIONS
      conversion_failed        = 1
      OTHERS                   = 2.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
***********************************************************************
* END-OF-SELECTION.
END-OF-SELECTION.
  LOOP AT it_datatab INTO wa_datatab.
    WRITE:/ wa_datatab-col1,
            wa_datatab-col2,
            wa_datatab-col3.
  ENDLOOP.

Related Articles

SAP applications and ABAP reports that process data files stored on your PC or within SAP
HEX codes and there associated ABAP declaration within SAP
Display files on SAP Application Server(UNIX)
Browse files on SAP Application Server(UNIX)
Downloading files to PC(Presentation Server)
Downloading files to SAP Application Server
Popup window to select a File using function module WS_FILENAME_GET
Get list of files within specific directory or SAP Application server
Directory selection for ABAP report using SAP method DIRECTORY_BROWSE
File Selection for ABAP report using SAP object method FILE_OPEN_DIALOG
Save file location popup on ABAP report selection screen using FILE_SAVE_DIALOG
ABAP Upload and download Function Modules in SAP
SAP File Selection Window - various methods of adding a file selection popup to your ABAP report
Upload Tab delimited file from PC into ABAP internal table
Upload and download files into and out of SAP or your PC
ABAP to check if file exists before downloading from SAP
ABAP to Upload Excel document into internal table on SAP system including .xlsx
Upload Excel document into ABAP internal table
ABAP Uploading files from PC to SAP R/3 system
ABAP to Upload files from SAP Application Server
Upload Tab delimited file from PC into ABAP internal table
Upload Tab delimited file from application server into ABAP internal table
Example Excel Spreadsheet used to demo SAP upload and download using ABAP
Download file from SAP unix system to your desktop using transaction SXDA