0% found this document useful (0 votes)
246 views

How To Upload Excel File Into Internal Table With Required Format

This document describes how to upload an Excel file into an internal ABAP table with a specific required format using the ALSM_EXCEL_TO_INTERNAL_TABLE function module. It first loads the Excel file into a table with one row per cell, then loops through this table to reformat the data into the internal table's structure with columns for first name, middle name, and last name.

Uploaded by

Erick Vite
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
246 views

How To Upload Excel File Into Internal Table With Required Format

This document describes how to upload an Excel file into an internal ABAP table with a specific required format using the ALSM_EXCEL_TO_INTERNAL_TABLE function module. It first loads the Excel file into a table with one row per cell, then loops through this table to reformat the data into the internal table's structure with columns for first name, middle name, and last name.

Uploaded by

Erick Vite
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

SAP Community Network Wiki - Code Gallery - How to upload Excel file into Internal T...

Page 1 of 2

Log In Register About Us How to Contribute


Welcome Guest

SDN Community BPX Community BusinessObjects University Alliances SAP EcoHub


Home Forums Wiki Blogs Articles eLearning Downloads Code Exchange Career Center Events InnoCentive Idea Place

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 */

The Function module 'ALSM_EXCEL_TO_INTERNAL_TABLE' returns us a Table having the format :

 Table 1.
 

Row Column Value

1 0001 Prem(First Name )

1 0002 Raj(Middle name )

1 0003 Kaushik(Last name )

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

Prem Raj Kaushik

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)   

Contact Us Site Index Marketing Opportunities Legal Terms Privacy Impressum


Powered by SAP NetWeaver

http://wiki.sdn.sap.com/wiki/display/Snippets/How+to+upload+Excel+file+into+Internal... 19/01/2011

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy