Application Development and Automation 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: 
Read only

Problem while down loading ALV list into excel sheet.

Former Member
0 Likes
495

Hi All,

Iam facing problem while down loading the ALV list to Excel sheet by Choosing 'Spread sheet button' ( Ctrl + Shift + F7 ).

The order of the fields in my list and in my excel sheet are not matching.

All my date, quantity and currency fields are downloading at the last of excel sheet .

Thanks in advance.

Brahma Reddy

4 REPLIES 4
Read only

Former Member
0 Likes
437

why don't u use the grid

Read only

Former Member
0 Likes
437

Brahma,

That is the way that SAP built the ALV grid's download. You will find numerous threads about this.

If you need to change this order, you must create soem custom functionality using OLE Automation.

Read only

0 Likes
437

John,

can you tell me how to go about OLE automation.

Brahma Reddy

Read only

0 Likes
437

Easiest way is not code the OLE automation directly... but let SAP do it for you.

I would add a custom DOWNLOAD button to your screen and implement this code with (note - you can get much fancier output by creating the OLE Automation yourself - but much more work):

REPORT ZR_DOWNLOAD_TO_EXCEL.

tables: vbak.

data: begin of lt_data_tab occurs 0,

vbeln like vbak-vbeln,

kunnr like vbak-kunnr,

ernam like vbak-ernam,

end of lt_data_tab.

data: l_filename type STRING.

data: outname type RLGRAP-FILENAME.

data: sname type RLGRAP-FILENAME.

data: begin of col_headers occurs 0,

text(10),

end of col_headers.

SELECTION-SCREEN BEGIN OF BLOCK ONE WITH FRAME TITLE TEXT-001.

selection-screen: skip 1.

parameters: cb_hdrs as checkbox.

SELECTION-SCREEN END OF BLOCK ONE.

start-of-selection.

select vbeln kunnr ernam up to 50 rows

from vbak into table lt_data_tab.

move 'c:\excel_demo' to outname.

if cb_hdrs = 'X'.

move 'Order #' to col_headers-text.

append col_headers.

move 'Sold-to #' to col_headers-text.

append col_headers.

move 'Created By' to col_headers-text.

append col_headers.

CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'

EXPORTING

file_name = outname

data_sheet_name = sname

TABLES

data_tab = lt_data_tab

fieldnames = col_headers

EXCEPTIONS

file_not_exist = 1

filename_expected = 2

communication_error = 3

ole_object_method_error = 4

ole_object_property_error = 5

invalid_pivot_fields = 6

download_problem = 7

OTHERS = 8.

IF sy-subrc <> 0.

  • MESSAGE s000(zz) WITH 'Export to Excel failed.'.

ENDIF.

else.

CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'

EXPORTING

file_name = outname

data_sheet_name = sname

TABLES

data_tab = lt_data_tab

  • fieldnames = col_headers

EXCEPTIONS

file_not_exist = 1

filename_expected = 2

communication_error = 3

ole_object_method_error = 4

ole_object_property_error = 5

invalid_pivot_fields = 6

download_problem = 7

OTHERS = 8.

IF sy-subrc <> 0.

  • MESSAGE s000(zz) WITH 'Export to Excel failed.'.

ENDIF.

endif.