Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to Download/Upload data form multiple sheets Excel file??

Former Member
0 Kudos

Hi Everyone,

I am using a ECC 6.0 system, and I need to download routing data to Excel file( which should have two sheets to display routing header and operation data ) for users to view, and if they made any change to the routing data in the Excel, I must update it into SAP.

The question is, I don't have much exp on developing ABAP programs with Excel, so I am not sure which technique fits this requirement best, DOI? OLE? or just call some FM?

Any suggestion would be highly appreciated. If possible pls show me some sample codes or links...

Thx,

Richard

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

For uploading data from Excel to internal table in report.


data:
  t_kna1 type table of alsmex_tabline,
  fs_kna1 like line of t_kna1,
  t_cust type table of type_s_kna1,
  fs_cust like line of t_cust.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
   EXPORTING
     FILENAME  = 'C:\Documents and Settings\kirankumarbu\book1.xls'
     I_BEGIN_COL                   = 1
     I_BEGIN_ROW                   = 1
     I_END_COL                     = 3
     I_END_ROW                     = 2
   TABLES
     INTERN                        = t_kna1
  EXCEPTIONS
    INCONSISTENT_PARAMETERS       = 1
    UPLOAD_OLE                    = 2
    OTHERS                        = 3
           .
 IF SY-SUBRC <> 0.
 message 'not open' type 'S'.
 ENDIF.

 loop at t_kna1 into fs_kna1.
 write:/ fs_kna1-row,
         fS_kna1-col,
         fs_kna1-value.
 case w_count.
 when 1.
 fs_cust-kunnr = fs_kna1-value.
 when 2.
 fs_cust-land1 = fs_kna1-value.
 when 3.
 fs_cust-name1 = fs_kna1-value.
 append fs_cust to t_cust. " Here t_cust contains the data from excel data
 w_count = 0.                    
 endcase.
 w_count = w_count + 1.
endloop.

For downloading File from internal table to EXCEL you can use.

GUI_DOWNLOAD Function module.

I hope it helps.

Regards and Best wishes.

11 REPLIES 11

Former Member
0 Kudos

Hi,

For uploading data from Excel to internal table in report.


data:
  t_kna1 type table of alsmex_tabline,
  fs_kna1 like line of t_kna1,
  t_cust type table of type_s_kna1,
  fs_cust like line of t_cust.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
   EXPORTING
     FILENAME  = 'C:\Documents and Settings\kirankumarbu\book1.xls'
     I_BEGIN_COL                   = 1
     I_BEGIN_ROW                   = 1
     I_END_COL                     = 3
     I_END_ROW                     = 2
   TABLES
     INTERN                        = t_kna1
  EXCEPTIONS
    INCONSISTENT_PARAMETERS       = 1
    UPLOAD_OLE                    = 2
    OTHERS                        = 3
           .
 IF SY-SUBRC <> 0.
 message 'not open' type 'S'.
 ENDIF.

 loop at t_kna1 into fs_kna1.
 write:/ fs_kna1-row,
         fS_kna1-col,
         fs_kna1-value.
 case w_count.
 when 1.
 fs_cust-kunnr = fs_kna1-value.
 when 2.
 fs_cust-land1 = fs_kna1-value.
 when 3.
 fs_cust-name1 = fs_kna1-value.
 append fs_cust to t_cust. " Here t_cust contains the data from excel data
 w_count = 0.                    
 endcase.
 w_count = w_count + 1.
endloop.

For downloading File from internal table to EXCEL you can use.

GUI_DOWNLOAD Function module.

I hope it helps.

Regards and Best wishes.

0 Kudos

Hi Kumar,

Thx very much for your answer!!!

But it's a pity that both the two FM can not dealing with multiple sheets Excel. Seems we need to find some other solution...

I am trying to test whether we can use the FM: 'TEXT_CONVERT_XLS_TO_SAP' to satisfy this case.

I will share the code if it works.

Best Regards,

Richard

0 Kudos

Good day Richard,

Just check this one it might help.

Link[Multiple sheets|http://wiki.sdn.sap.com/wiki/display/Snippets/DownloadDataintoMultipleSheetExcelDocumentwithNonEditableColumns(Passwordprotected)UsingABAP+OLE]

Regards and Best wishes.

0 Kudos

Thanks Kumar,

I will do some investigation on that link. And I want to find a best solution to the case.

Have a nice weekend!

Richard

0 Kudos

Hi Kumar

your link helps me a lot!

OLE is a good choice for solving such kind of questions.

I would love to share the codes, but it's too long...

anyone need it, just contact me:-)

Best Regards,

Richard

0 Kudos

Richard,

I have two internal tables and need to transfer two worksheets in single excel application. I've done this . Now i need to have the same in unix server . User will download the file from unix server to local desktop and if he opens he should have two sheets in single application with two inetrnal table contents.

At present i can able to create a file with single sheet in unix server , i need to create with two sheets...

Pls let me know how to do it?

Regards,

Krishna.

0 Kudos

Hi Moorthy,

I tried to use OLE to generate multiple sheets Excel and save it on the Application Server, but I failed.

So i am sorry to tell you I don't know how to solve the case.

But I have an idea, that is, use the OLE to generate excel and save it on a local path in user's computer, and call the Method:

cl_gui_frontend_services=>GUI_UPLOAD, to transfer the Excel to Unix server, and after that call cl_gui_frontend_services=>FILE_DELETE to delete the local Excel... It may be your last choice....

Good luck,

Richard

0 Kudos

HI,

I require the code as I have the same issue.

0 Kudos

Hi

Pls show me more detail of your issue, as I can give your the related codes...

If you need sample code of OLE, I think kiran kumar has show us a good one in above post.

Good Luck,

Richard

0 Kudos

Hi,

I also have similar requirement, and i tried opening the link you gave but its coming page not found .

Please provide me link again. Any help will be appreciated.

Regards

Swati

UweFetzer_se38
Active Contributor
0 Kudos

Another suggestion: try project ABAP 2 XLSX (on SAP Code Exchange https://cw.sdn.sap.com/cw/groups/abap2xlsx )

Best regards
Uwe Fetzer (@se38)