You are on page 1of 3

How to upload Excel file into Internal Table with Required Format.

Link to this Page Link Tiny Link OK


Know n Location You must make a

Wiki Markup Cancel

Close Click to select the

Move Page How Search


Error reading the

Set Page Location Move


Recently View ed There w ere no re

The specified pag Brow se Failed to retrieve

You could try relo HTTP Status

There w ere no pa Show ing <b>{0}<

Move failed. Ther Code Gallery


Unknow n user or

You cannot move You cannot move


Page Restrictions

How to upload Ex Page Ordering


Editing restricted

Snippets Back
Cancel

Reorder
Close

Move
Save

Page restrictions apply Added by PremRaj kaushik, last edited by PremRaj kaushik on Jan 15, 2009 (view change)
view

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 */ The Function module 'ALSM_EXCEL_TO_INTERNAL_TABLE' returns us a Table having the format : Table 1.

Row 1

Column 0001

Value Prem(First Name )

0002

Raj(Middle name )

0003

Kaushik(Last name )

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 Prem Naresh Raj Kaushik 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 I_BEGIN_COL I_BEGIN_ROW I_END_COL I_END_ROW TABLES INTERN EXCEPTIONS INCONSISTENT_PARAMETERS = 1 UPLOAD_OLE OTHERS =2 = 3. = IT_FILE = FILE_PATH = '1' = '3' = '3' = '256' Last Name

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.

You might also like