By using the standard function ALSM_EXCEL_TO_INTERNAL_TABLE, you can import most Excel documents into an SAP internal table. Please note that this code is set up for spreadsheets up to 9999 rows. If you need more, use a 'DO' statement to loop through the Excel file in 9999 row segments until all is retreived
The code runs on 4.6B.
DATA: DATA LIKE ALSMEX_TABLINE OCCURS 100, "ALSM_EXCEL_TO_INTERNAL_TABLE structure BCOL TYPE I VALUE 1, "This can be any Column in your " spreadsheet where you want to start " importing data BROW TYPE I VALUE 1, "This can be any Row in your " spreadsheet where you want to start " importing data ECOL TYPE I VALUE 9, "This can be any Column in your " spreadsheet where you want to stop " importing data EROW TYPE I VALUE 9999. "This can be any Row in your " spreadsheet where you want to stop " importing data "There is little hurt to enter a larger "number for the upper limit of the rows "or columns. It may take a few extra "seconds to import, but only those "fields who's values are not equal "to ' ', space, will be imported. DATA: UPFILE(128) VALUE 'C:/'. "You should provide the user a popup " window to allow them the option to " select a file from their PC or network "Call to import Excel document CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' EXPORTING FILENAME = UPFILE I_BEGIN_COL = BCOL I_BEGIN_ROW = BROW I_END_COL = ECOL I_END_ROW
= EROW TABLES INTERN = DATA 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. ENDIF. "Sample contents of internal table, " 'DATA', when populated succefully "Row '0001' contains the column titles " created when the user exported my " ALV to a SpreadSheet "Col represents the Excel columns after " exported and/or user manipulated " within the defined Columns declared " above "Value represents the column contents Table 'DATA' contents: ROW COL Value ---------------------- 0001|0001|Begin Time 0001|0002|End Time 0001|0003|Seat 0001|0004|Pers. No. 0001|0005|Pers. Name 0001|0006|Org. Unit 0001|0007|Org. Text 0001|0008|Begin Date 0001|0009|End Date 0002|0001|08:00:00 0002|0002|09:00:00 0002|0003|0001 0002|0004|99999999 0002|0005|Smith, John 0002|0006|00000001 0002|0007|Shipping Clerk 0002|0008|01/01/2001 0002|0009|01/01/2001 ....
This was first published in March 2003