![Sap Upload Excel File Sap Upload Excel File](/uploads/1/2/5/3/125355186/109452491.jpg)
Utility class to Upload Excel file. CLASS lclexceluploader DEFINITION. PUBLIC SECTION. DATA: headerrowscount TYPE i. DATA: maxrows TYPE i. DATA: filename TYPE localfile.
Scenario: To upload an excel file using WebDynpro Application. Procedure: 1. Go to transaction SE80. Select “WebDynpro Comp./Intf” from the list. Create a new WebDynpro component by the name ZEXCEL_UPLOAD. Double-click on the View. Select Context Tab.
METHODS: constructor. METHODS: upload CHANGING ctdata TYPE ANY TABLE.
PRIVATE SECTION. DATA: lvtotcomponents TYPE i. METHODS: doupload IMPORTING ivbegin TYPE i ivend TYPE i EXPORTING rvempty TYPE flag CHANGING ctdata TYPE STANDARD TABLE. 'lclexceluploader DEFINITION. CLASS lclexceluploader IMPLEMENTATION. METHOD constructor.
Maxrows = 9999. 'constructor METHOD upload. DATA: lostruct TYPE REF TO clabapstructdescr, lotable TYPE REF TO clabaptabledescr, ltcomp TYPE clabapstructdescr= componenttable. Lotable?= clabapstructdescr= describebydata ( ctdata ).
Lostruct?= lotable- gettablelinetype ( ). Ltcomp = lostruct- getcomponents ( ). lvtotcomponents = LINES ( ltcomp ). DATA: lvempty TYPE flag, lvbegin TYPE i, lvend TYPE i. lvbegin = headerrowscount + 1. Lvend = maxrows.
![What is excel file What is excel file](https://blogs.sap.com/wp-content/uploads/2012/09/3_167466.jpg)
WHILE lvempty IS INITIAL. Doupload ( EXPORTING ivbegin = lvbegin ivend = lvend IMPORTING rvempty = lvempty CHANGING ctdata = ctdata ). Lvbegin = lvend + 1.
Lvend = lvbegin + maxrows. 'upload. METHOD doupload.
DATA: liexceldata TYPE STANDARD TABLE OF alsmextabline. DATA: lsexceldata LIKE LINE OF liexceldata. DATA: lvtotrows TYPE i. DATA: lvpacket TYPE i. FIELD-SYMBOLS: TYPE ANY, TYPE ANY. Upload this packet CALL FUNCTION 'ALSMEXCELTOINTERNALTABLE' EXPORTING filename = filename ibegincol = 1 ibeginrow = ivbegin iendcol = lvtotcomponents iendrow = ivend TABLES intern = liexceldata EXCEPTIONS inconsistentparameters = 1 uploadole = 2 OTHERS = 3. something wrong, exit IF sy-subrc 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. Rvempty = 'X'. No rows uploaded, exit IF liexceldata IS INITIAL. Rvempty = 'X'.
Move from Row, Col to Flat Structure LOOP AT liexceldata INTO lsexceldata. ' Append new row AT NEW row. APPEND INITIAL LINE TO ctdata ASSIGNING. ' component and its value ASSIGN COMPONENT lsexceldata-col OF STRUCTURE TO. IF sy-subrc EQ 0. = lsexceldata- value. ' add the row count AT END OF row.
IF IS NOT INITIAL. Lvtotrows = lvtotrows + 1. packet has more rows than uploaded rows,. no more packet left. Thus exit lvpacket = ivend - ivbegin. IF lvtotrows LT lvpacket. Rvempty = 'X'.
'doupload ENDCLASS. 'lclexceluploader IMPLEMENTATION. To use this utility class.
ABAP code for uploading an Excel document into an internal table. See code below for structures. The code is based on uploading a or for an actual Excel file There are also a couple of alternatives which use fucntion modules and but the method below is by far the simplest method to used.
A big thanks to for bringing this method to my attention. Update: Just tried uploading a file which was in the new MS excel format (.xlsx) using the below method but unfortunately it did not work. Using or function modules still uploads.xlsx files though.: Description:.: -:.: This is a simple example program to get data from an excel:.: file and store it in an internal table.:.::.: Author: www.erpworkbench.com, based on code from:.::.: SAP Version: 4.7:.: REPORT zuploadexceltoitab. TYPE-POOLS: truxs. PARAMETERS: pfile TYPE rlgrap-filename.
TYPES: BEGIN OF tdatatab, col1(30) TYPE c, col2(30) TYPE c, col3(30) TYPE c, END OF tdatatab. DATA: itdatatab type standard table of tdatatab, wadatatab type tdatatab. DATA: itraw TYPE truxsttextdata. At selection screen AT SELECTION-SCREEN ON VALUE-REQUEST FOR pfile. CALL FUNCTION 'F4FILENAME' EXPORTING fieldname = 'PFILE' IMPORTING filename = pfile.START-OF-SELECTION. CALL FUNCTION 'TEXTCONVERTXLSTOSAP' EXPORTING. IFIELDSEPERATOR = ilineheader = 'X' itabrawdata = itraw ' WORK TABLE ifilename = pfile TABLES itabconverteddata = itdatatab 'ACTUAL DATA EXCEPTIONS conversionfailed = 1 OTHERS = 2.
IF sy-subrc 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. END-OF-SELECTION. LOOP AT itdatatab INTO wadatatab. WRITE:/ wadatatab-col1, wadatatab-col2, wadatatab-col3.