SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Upload Excel document into internal table



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> OLE2, Excel, WinWord
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Mon Sep 03, 2007 10:58 pm    Post subject: Upload Excel document into internal table Reply with quote

ABAP code for uploading an Excel document into an internal table. See code below for structures. The code is based on uploading a simple Excel spreadsheet or for an actual Excel file click here.

There are also a couple of alternatives which use fucntion modules
'KCD_EXCEL_OLE_TO_INT_CONVERT'
and
'ALSM_EXCEL_TO_INTERNAL_TABLE'
but the method below is by far the simplest method to use.

Code:

*……………………………………………………..
*: Description :
*: ———– :
*: This is a simple example program to get data from an excel :
*: file and store it in an internal table. :
*: :
*: Author : www.sapdev.co.uk, based on code from Jayanta :
*: :
*: SAP Version : 4.7 :
*:……………………………………………………:
  REPORT zupload_excel_to_itab.

  TYPE-POOLS: truxs.

  PARAMETERS: p_file TYPE rlgrap-filename.

  TYPES: BEGIN OF t_datatab,
    col1(30) TYPE c,
    col2(30) TYPE c,
    col3(30) TYPE c,
  END OF t_datatab.
  DATA: it_datatab TYPE STANDARD TABLE OF t_datatab,
  wa_datatab TYPE t_datatab.

  DATA: it_raw TYPE truxs_t_text_data.

* At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION 'F4_FILENAME'
       EXPORTING
            field_name = 'P_FILE'
       IMPORTING
            file_name  = p_file.

***********************************************************************
START-OF-SELECTION.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
  EXPORTING
* I_FIELD_SEPERATOR =
  i_line_header = 'X'
  i_tab_raw_data = it_raw " WORK TABLE
  i_filename = p_file
  TABLES
  i_tab_converted_data = it_datatab[] "ACTUAL DATA
  EXCEPTIONS
  conversion_failed = 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.
  ENDIF.

***********************************************************************
END-OF-SELECTION.
  LOOP AT it_datatab INTO wa_datatab.
    WRITE:/ wa_datatab-col1,
    wa_datatab-col2,
    wa_datatab-col3.
  ENDLOOP.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> OLE2, Excel, WinWord All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.