SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software Kodyaz SAP and ABAP Programming Tutorials
Development resources, articles, tutorials, samples, codes and tools for .Net, SQL Server, Vista, etc.




Win FREE BOOK
from Kodyaz



CRM Companies List
Web Based CRM Software

How to Upload Data to SAP from Excel File using alsm_excel_to_internal_table Function Module


Frequently, ABAP developers and SAP users require data upload from Excel to SAP.
Data upload to SAP systems can be managed using third-party SAP tools or using built-in ABAP function modules like alsm_excel_to_internal_table.
alsm_excel_to_internal_table function module help ABAP developers to upload Excel to SAP internal tables in their ABAP codes.

In this ABAP tutorial, I'll try to show how data from Excel files can be upload to SAP internal tables with a sample ABAP report.
Here is a sample Excel data file which contains currency codes and currency names in two columns in an Excel spreadsheet as shown in the below screenhot.

excel

Using ABAP function module alsm_excel_to_internal_table, we will upload Excel to SAP internal table and then list the contents of the ABAP internal table as an ABAP list.
Below ABAP programmers will see the output of the sample ABAP report.

currency





Here is the ABAP source codes of the sample program ZUploadExcelData which reads an Excel file from a given path "C:\currency.xls"
ABAP ALSM_EXCEL_TO_INTERNAL_TABLE function module upload Excel to SAP internal table gt_exceldata.
Please note that gt_exceldata is a type table of alsmex_tabline.
After Excel data is uploaded from Excel to ABAP internal table of type alsmex_tabline, by using ABAP Loop command each column value is assigned to the desired work-area structure.
And after data assignment to work area structures are completed each structure or workarea is added to the desired ABAP internal table using APPEND command.

REPORT ZUploadExcelData .

TYPES :
 BEGIN OF gty_currency,
  currencycode(5) TYPE c,
  currencyname(50) TYPE c,
 END OF gty_currency.

DATA :
  currline TYPE i,
  gs_exceldata TYPE alsmex_tabline,
  gt_exceldata TYPE TABLE OF alsmex_tabline,
  gs_currency TYPE gty_currency,
  gt_currency TYPE TABLE OF gty_currency.


* Import data from Excel
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
 EXPORTING
  filename = 'C:\currency.xls'
  i_begin_col = 1
  i_begin_row = 1
  i_end_col = 2
  i_end_row = 1000
 TABLES
  intern = gt_exceldata
* 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.


* Load data into internal table
currline = 0.
SORT gt_exceldata BY row value.
LOOP AT gt_exceldata INTO gs_exceldata.

  IF currline = 0.
    currline = gs_exceldata-row.
  ENDIF.

  IF currline <> gs_exceldata-row.
    currline = gs_exceldata-row.
    APPEND gs_currency TO gt_currency.
  ENDIF.

 CASE gs_exceldata-col.
  WHEN 1.
   gs_currency-currencycode = gs_exceldata-value.
  WHEN 2.
   gs_currency-currencyname = gs_exceldata-value.
  WHEN OTHERS.
 ENDCASE.

ENDLOOP.


* Display data
 WRITE : /
  'Code',
  10 'Currency'.

LOOP AT gt_currency INTO gs_currency.

 WRITE : /
  gs_currency-currencycode UNDER 'Code',
  gs_currency-currencyname UNDER 'Currency'.

ENDLOOP.

For ABAP developers who want to execute the given sample ABAP report for data upload from Excel to SAP, sample Excel source file currency.xls can be download from Download currency.xls







SAP Resources

SAP Tutorial

SAP Forums

SAP Tools

SAP Transaction Codes Table






SAP Tutorial and ABAP Tutorials (including Web Dynpro and Smartforms)

Unicode Character Problem in IFS File Interface
Read Pricing Condition Text using ABAP in SAP Sales Document Output
Export SAP Data to Fixed Length Text File
Export Table Contents into Text File and Download File
Business Document Service Error: Error when accessing graphic (BDS), RC = 5
Get Proforma Invoice from Commercial Invoice in ABAP
Convert Sales Unit into Text using Function Module in Target Language
Get Fullname of SAP user using Function Module in ABAP Program
ABAP Submit Report to Run Another ABAP Program within Code
Message no XS826: Cannot process message; no node determined for 76550052
SE63 Smartform Translation and Export using SLXT Program
VF31 SAP Transaction to Reprocess Billing Output Messages
Import and Export SO10 Standard Text using RSTXSCRP ABAP Program
CALL_FUNCTION_NOT_FOUND ABAP Run Time Error
SAP Output Management - Create New SAP Output Type
SAP Purchase Order Tables, Transaction Codes and Output
Assign SAP Item Category to Sales Document Type using SPRO
Window MAIN does not fit onto page PAGE (height)
SAP Invoice Output ZZZZ is not Defined
Invoice Output fail because of missing Billing Type text in TVFKT table
Read Integer and Decimals of a Numeric Value in ABAP Programming
SAP Smartforms Table Parameter in Form Routine
Complex Conditions in SAP Smartform with AND/OR
Free Adobe LiveCycle Designer Download
Create SAP Dynamic Variant using Date Calculation
Translate Web Dynpro Header Title displayed on Web Browser
ABAP RegEx for ABAP Regular Expression to fetch Date from String
Change Output Condition Records
Web Dynpro Text Translation using Assistance Class
Move Minus Sign from Right to Left of Negative Number in SAP Smartform
Read Address Data using FM ADDR_GET instead of Querying ADRC Table
Add Value Help to Web Dynpro Select Options
Add Web Dynpro Applications to SAP Favorites Menu
Component Usage ALV Does Not Have an Active Component
Web Dynpro Component Service Syntax Error in Program /1BCWDY/O3EC1AX6A3OVKK9L5FXO==CP
Web DynPro Tutorial - Display Spool Requests using Web DynPro Table
Web DynPro Tutorial - How to create Web Dynpro Application (Web Dynpro Component)
Display Data on Web DynPro Table Element
Test Web Dynpro ABAP Component by Creating Web Dynpro Application
Graphics White Background Displayed Grey on SAP Smartform Output
Get SAP Document Flow using SD_DOCUMENT_FLOW_GET ABAP Function Module
How to Spell Numbers using ABAP Spell_Amount Function Module
How to Transport SAP Graphics using SE78 Transaction
How to Delete Standard Text using SO10 SAP Transaction
Dynamic Programming using Field Symbols in ABAP Reports
How to Disable Word Editor in SAP Smartform Text
How to Debug Popup Screen in ABAP
TVAP Item Category and SAP Table TVAPT for Text Translations
ABAP Runtime Error ST22 Transaction using Short Dump Analysis
Create Transport Request for Text Translations using RS_LXE_RECORD_TORDER
SAP Invoice Output Determination Analysis for Not Created Output Message
Set Default Single Values List for SAP Selection Screen Parameter
SAP Payment Terms Table and ZTERM Texts Table for ABAP Developers
How to Create SAPScript Text using SO10 Transaction Code
SAP Smartforms Tutorial - Table Calculations using Sum Total
SAP Smartforms Tutorial - Table Calculations using Count
SAP Smartforms Tutorial - How to Create Smartform
SAP NetWeaver Installation Guide using installshield wizard
SAP Smartforms Table for Sales Order and Invoice Outputs
Email Spool Request using SAPOffice - Spool to PDF
How to Display SAP Graphics using SE78 Transaction Code
SAPScript Transaction Codes
ABAP Tutorial - ABAP String Split Example Code
Sales Tables among ABAP Tables (SAP Sales and Distribution SD Tables)
How to Upload Data to SAP from Excel File using alsm_excel_to_internal_table Function Module
ALV Grid Color - Table Row Background Color in ALV List
Multi Color ALV Grid Color Alternate using ALV Layout info_fname Property
How to Debug SmartForms - Debugging SAP SmartForm in ABAP ?
ABAP - Create Hierarchy Tree List using rs_tree_construct, rs_tree_list_display and snodetext
Create CL_GUI_ALV_GRID ALV Grid Column Header using ABAP Data Element
ABAP Tutorial - SAP Split and ABAP Split String Function
Upload Data from Excel File in ABAP using TEXT_CONVERT_XLS_TO_SAP
SAP Tutorial - Convert Spool Request to PDF File using RSTXPDFT4 ABAP Report
SAP ABAP Tutorial - ALV Grid Example with cl_gui_alv_grid and Screen Painter
Convert Smartform to PDF in Print Preview Mode
SAP Smartforms Tutorial - Create Smartforms Example
SAP Smartforms - How to Call Smartform within ABAP Program
Complete List of SAP Modules






Copyright © 2004 - 2013 Eralper Yilmaz. All rights reserved.
Community Server by Telligent Systems