How To Upload Excel File Into Internal Table With Required Format
How To Upload Excel File Into Internal Table With Required Format
Page 1 of 2
How to upload Excel file into Internal Table with Required Format.
Added by PremRaj kaushik, last edited by PremRaj kaushik on Jan 15, 2009
Author: PremRaj kaushik
Submitted: <15-01-2009>
Related Links:
Description:
This code gives the brief idea of how to use Function module 'ALSM_EXCEL_TO_INTERNAL_TABLE' for uploading the Excel file into your Internal table with the required Format .Hope this will help
you .
/* your snippet */
Table 1.
2 0001 Naresh But we can't insert that data directly into our internal table . so we have to convert that data into the following format :
Table 2 ..
First Name
Middle Name Last Name
Naresh The following Code sample returns the Table IT_FILE which is in format of Table 1 above.
Now we have to convert it into the format of same as our Internal Table Like Table 2.
Code Sample :
DATA : IT_FILE LIKE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
DATA FILE_PATH LIKE RLGRAP-FILENAME.
TYPES : BEGIN OF SBU_UPLOAD ,
BU TYPE c,
BU_DESC TYPE c,
DELETE TYPE C,
END OF SBU_UPLOAD .
DATA TBU_UPLOAD TYPE STANDARD TABLE OF SBU_UPLOAD WITH HEADER LINE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'FILE_LOC' "Here file_LOC is the text Element name on Screen.
IMPORTING
file_name = FILE_PATH.
"In FILE_PATH you get the excel file path , ehich you want to upload in Internal table ex: E:\Prem\Premral_details.xls' and we pass this file name to the following function Module which Return back
the Internal table of its own Format ."
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = FILE_PATH
I_BEGIN_COL = '1'
I_BEGIN_ROW = '3'
I_END_COL = '3'
I_END_ROW = '256'
TABLES
INTERN = IT_FILE
EXCEPTIONS
http://wiki.sdn.sap.com/wiki/display/Snippets/How+to+upload+Excel+file+into+Internal... 19/01/2011
SAP Community Network Wiki - Code Gallery - How to upload Excel file into Internal T... Page 2 of 2
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
IF SY-SUBRC NE SPACE.
*leave PROGRAM.
ENDIF.
" Now I use the following Logic to convert that IT_FILE table into our own table format."
LOOP AT IT_FILE.
CASE IT_FILE-COL.
WHEN '0001'.
MOVE IT_FILE-VALUE TO TBU_UPLOAD-BU.
WHEN '0002'.
MOVE IT_FILE-VALUE TO TBU_UPLOAD-BU_DESC.
WHEN '0003'.
MOVE IT_FILE-VALUE TO TBU_UPLOAD-DELETE.
ENDCASE.
AT END OF ROW.
"At end of row TBU_UPLOAD is updated with the desired value i.e
When Row Column in table one converted from 1 to 2 , the first column in Table 2 is inserted. Which is the required format of us . "
APPEND TBU_UPLOAD.
CLEAR TBU_UPLOAD.
ENDAT.
* APPEND TBU_UPLOAD.
ENDLOOP.
Labels
alsm_excel_to_internal_table abap
Comments (1)
http://wiki.sdn.sap.com/wiki/display/Snippets/How+to+upload+Excel+file+into+Internal... 19/01/2011