Tip

Move Excel data into an SAP internal table

By using the standard function ALSM_EXCEL_TO_INTERNAL_TABLE, you can import most Excel documents into an SAP internal table. Please note that this code is set up for spreadsheets

    Requires Free Membership to View

up to 9999 rows. If you need more, use a 'DO' statement to loop through the Excel file in 9999 row segments until all is retreived
The code runs on 4.6B.


 

 

DATA: 
  DATA LIKE ALSMEX_TABLINE OCCURS 100,
"ALSM_EXCEL_TO_INTERNAL_TABLE structure
  BCOL TYPE I VALUE 1, 
"This can be any Column in your 
"   spreadsheet where you want to start 
"   importing data
  BROW TYPE I VALUE 1, 
"This can be any Row in your 
"   spreadsheet where you want to start
"   importing data
  ECOL TYPE I VALUE 9, 
"This can be any Column in your 
"    spreadsheet where you want to stop 
"    importing data
  EROW TYPE I VALUE 9999. 
"This can be any Row in your 
"    spreadsheet where you want to stop 
"    importing data

"There is little hurt to enter a larger 
"number for the upper limit of the rows 
"or columns. It may take a few extra 
"seconds to import, but only those 
"fields who's values are not equal 
"to ' ', space, will be imported.

DATA: UPFILE(128) VALUE 'C:/'.
"You should provide the user a popup 
" window to allow them the option to
" select a file from their PC or network

"Call to import Excel document
  CALL FUNCTION 
      'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
     FILENAME     = UPFILE
     I_BEGIN_COL  = BCOL
     I_BEGIN_ROW  = BROW
     I_END_COL    = ECOL
     I_END_ROW    = EROW
    TABLES 
     INTERN       = DATA
    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.

"Sample contents of internal table, 
"  'DATA', when populated succefully
"Row '0001' contains the column titles
"  created when the user exported my 
"  ALV to a SpreadSheet
"Col represents the Excel columns after
"  exported and/or user manipulated 
"  within the defined Columns declared 
"  above
"Value represents the column contents

Table 'DATA' contents:
ROW  COL  Value
----------------------
0001|0001|Begin Time
0001|0002|End Time
0001|0003|Seat
0001|0004|Pers. No.
0001|0005|Pers. Name
0001|0006|Org. Unit
0001|0007|Org. Text
0001|0008|Begin Date
0001|0009|End Date
0002|0001|08:00:00
0002|0002|09:00:00
0002|0003|0001
0002|0004|99999999 
0002|0005|Smith, John
0002|0006|00000001
0002|0007|Shipping Clerk
0002|0008|01/01/2001
0002|0009|01/01/2001
....

This was first published in March 2003

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.