ALV download to EXCEL with column headings etc.
Getting data from a grid to EXCEL can be done in "List" mode vis system==>save etc but it's not particularly user friendly and in any case if you are displaying a nice ALV why should the user have to switch into LIST mode anyway.
Anyway here's a decent way to do it and it gives great formatted column headings etc etc.
1) in the ON_TOOLBAR method add this code
method ON_TOOLBAR.
type-pools icon.
CLEAR ls_toolbar.
MOVE 0 TO ls_toolbar-butn_type.
MOVE 'EXCEL' TO ls_toolbar-function.
MOVE space TO ls_toolbar-disabled.
MOVE icon_xxl TO ls_toolbar-icon.
MOVE 'Excel' TO ls_toolbar-quickinfo.
MOVE 'EXCEL' TO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.
2) In the ON_USER_COMMAND method add the following
(if you have a class defined with SE24 you don't need the commented code).
method ON_USER_COMMAND.
FOR EVENT before_user_command OF cl_gui_alv_grid
IMPORTING
e_ucomm
sender.
CASE e_ucomm.
....... other toolbar funcs if you have any
WHEN 'EXCEL'.
CALL METHOD me->download_to_excel.
ENDCASE.
endmethod.
3) code this method to download to EXCEL
method DOWNLOAD_TO_EXCEL.
FIELD-SYMBOLS:
<fs0> TYPE STANDARD TABLE,
<fs1> TYPE STANDARD TABLE.
ASSIGN g_outtab1->* TO <fs0>.
ASSIGN g_fldcat1->* TO <fs1>.
CALL FUNCTION 'LVC_TRANSFER_TO_KKBLO'
EXPORTING
it_fieldcat_lvc = <fs1>
is_layout_lvc = m_cl_variant->ms_layout
is_tech_complete = ' '
IMPORTING
es_layout_kkblo = ls_layout
et_fieldcat_kkblo = lt_fieldcat.
LOOP AT lt_fieldcat INTO lt_fieldcat_wa.
CLEAR lt_fieldcat_wa-tech_complete.
IF lt_fieldcat_wa-tabname IS INITIAL.
lt_fieldcat_wa-tabname = '1'.
MODIFY lt_fieldcat FROM lt_fieldcat_wa.
ENDIF.
l_tabname = lt_fieldcat_wa-tabname.
ENDLOOP.
CALL FUNCTION 'ALV_XXL_CALL'
EXPORTING
i_tabname = l_tabname
is_layout = ls_layout
it_fieldcat = lt_fieldcat
i_title = sy-title
TABLES
it_outtab = <fs0>
EXCEPTIONS
fatal_error = 1
no_display_possible = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
endmethod.
You get nice column headings etc and decently formatted EXCEL spreadsheet.
For Office 2007 I think you need to apply a SAP note but it certainly works with OFFICE 2003 which is what we are still using.
Cheers
jimbo
Getting data from a grid to EXCEL can be done in "List" mode vis system==>save etc but it's not particularly user friendly and in any case if you are displaying a nice ALV why should the user have to switch into LIST mode anyway.
Anyway here's a decent way to do it and it gives great formatted column headings etc etc.
1) in the ON_TOOLBAR method add this code
method ON_TOOLBAR.
type-pools icon.
CLEAR ls_toolbar.
MOVE 0 TO ls_toolbar-butn_type.
MOVE 'EXCEL' TO ls_toolbar-function.
MOVE space TO ls_toolbar-disabled.
MOVE icon_xxl TO ls_toolbar-icon.
MOVE 'Excel' TO ls_toolbar-quickinfo.
MOVE 'EXCEL' TO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.
2) In the ON_USER_COMMAND method add the following
(if you have a class defined with SE24 you don't need the commented code).
method ON_USER_COMMAND.
FOR EVENT before_user_command OF cl_gui_alv_grid
IMPORTING
e_ucomm
sender.
CASE e_ucomm.
....... other toolbar funcs if you have any
WHEN 'EXCEL'.
CALL METHOD me->download_to_excel.
ENDCASE.
endmethod.
3) code this method to download to EXCEL
method DOWNLOAD_TO_EXCEL.
FIELD-SYMBOLS:
<fs0> TYPE STANDARD TABLE,
<fs1> TYPE STANDARD TABLE.
ASSIGN g_outtab1->* TO <fs0>.
ASSIGN g_fldcat1->* TO <fs1>.
CALL FUNCTION 'LVC_TRANSFER_TO_KKBLO'
EXPORTING
it_fieldcat_lvc = <fs1>
is_layout_lvc = m_cl_variant->ms_layout
is_tech_complete = ' '
IMPORTING
es_layout_kkblo = ls_layout
et_fieldcat_kkblo = lt_fieldcat.
LOOP AT lt_fieldcat INTO lt_fieldcat_wa.
CLEAR lt_fieldcat_wa-tech_complete.
IF lt_fieldcat_wa-tabname IS INITIAL.
lt_fieldcat_wa-tabname = '1'.
MODIFY lt_fieldcat FROM lt_fieldcat_wa.
ENDIF.
l_tabname = lt_fieldcat_wa-tabname.
ENDLOOP.
CALL FUNCTION 'ALV_XXL_CALL'
EXPORTING
i_tabname = l_tabname
is_layout = ls_layout
it_fieldcat = lt_fieldcat
i_title = sy-title
TABLES
it_outtab = <fs0>
EXCEPTIONS
fatal_error = 1
no_display_possible = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
endmethod.
You get nice column headings etc and decently formatted EXCEL spreadsheet.
For Office 2007 I think you need to apply a SAP note but it certainly works with OFFICE 2003 which is what we are still using.
Cheers
jimbo
Similar Messages
-
Download to Excel with Column Headings.
Hi All,
I have a very small issue.I want to download the Data from an internal table to an Excel Sheet Along with the Column heading of the corresponding Field...
I tried with ws_excel and gui_download... not reached to any conclusion,,,I cant go for OLE technique as i have huge amount of data in my internal table.
If anyone have faced the same problem ...please suggest something.
Thanks in advance,
Mayank.Hi,
Once I also faced the same problem.It was solved by the below coding.In my coding i_download is the internal table with two fields werks and matnr .w_download is its workarea.
PARAMETERS p_file LIKE rlgrap-filename.
"File name
Local Variable declaration
DATA lv_file TYPE string.
lv_file = p_file.
PERFORM f1710_populate_heading.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = lv_file
filetype = 'ASC'
write_field_separator = 'X'
TABLES
data_tab = i_download
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc = 0.
MESSAGE i000 WITH text-005. "File downloded successfully
ELSE.
CASE sy-subrc.
WHEN 1.
MESSAGE i000 WITH text-014.
WHEN 21.
MESSAGE i000 WITH text-071.
ENDCASE.
ENDIF.
ENDFORM. " f1500_download_data
*& Form f1710_populate_heading
Populate header records
FORM f1710_populate_heading.
CLEAR w_download.
Design the text element to handle maximum length of
the output
w_download-werks = text-001.
w_download-matnr = text-002.
INSERT w_download INTO i_download INDEX 1.
ENDFORM. " f1710_populate_heading
Hope this is clear.
If your problem is solved,could you please reward useful answers and close the thread.
Rgds,
J.Jayanthi -
Download internal table with column headings
Hai Friends,
How can i download the internal table with column headings?. i used to download and do some manual calculations to cross check the output.Hello,
You can do this with GUI_DOWNLOAD where you can provide seperate table for fieldnames.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
FILENAME =
FILETYPE = 'ASC'
APPEND = ' '
WRITE_FIELD_SEPARATOR = ' '
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
IMPORTING
FILELENGTH =
TABLES ---> Table for sending column headings
DATA_TAB =
FIELDNAMES =
Hope this helps!
Thanks,
Augustin. -
Details: Numbers not translating an Excel document with column headings where the text is rotated counter clockwise 90 degrees with-in the cell. Can you tell me how I can rotate the contents with-in a cell?
Numbers does not have rotated text within cells. You can place a text box over the cell that has rotated text but you cannot rotate text within a cell.
-
Hi,
I have a problem with regards to the ALV download to excel. I have an ALV grid with 40 columns and i need to download the output to an excel file. But after downloading the ALV output, i noticed that some columns are already on the next line. i need to have all columns to be in the same line. Does anyone have an idea how to prevent columns to be printed in the next line?
Thanks in advance!
Kind regards,
MerriamLooks like Note 855314 has a workaround ... my be more.
Of course (yuk!), write you own download.
Best!
Jim -
I need to see some sample source code of a report with column headings and detail data. I can't get my column titles in the header to line up with the detail no matter what I do. Can anyone spare me a good sample?
I have tried to use tables to specify both col headings and detail, but no chance to get them to line up. There has to be a way. I can't use the report builder because I need more control of when page breaks print, what data is on each line, etc. Hopefully some kind soul out there has a good sample.
Thanks!
DaveYour MBP is actually a mid-2010, not a 2008. That's what the 6,2 model indicates.There's an issue with the graphics module on that machine. There was a program in place to replace the motherboard within 3 years of purchase, but you're probably outside of that. Some folks have supposedly gotten theirs changed outside of that period, so you can try.
http://support.apple.com/kb/TS4088?viewlocale=en_US&locale=en_US
What you can do to use it is download gfxstatus from http:gfx.io and force the graphics to Intel. That would affect your work with Final Cut, but at least you might be able to use the machine. -
How can I disenable the EXCEL field format when use ALV download to excel ?
Dear friends,
I have a problem with the ALV download to EXCEL. One field Value in ALV is like u2018-abcdeu2026u2019.the character u201C-u201Cis the first position in field value.when I download the value to EXCEL,the field value u2018-abcdeu2026u2019 changed u2018=-abcdeu2026u2019 in EXCEL.how can I remove u2018=u2019 in EXCEL when I down to excel used ALV.
I add a space in u2018 -abcdeu2026u2019,So this value can be download to Excel .
Have you any solve method?
User does not use excel logo button to download.
User use Local fileu2026 button to download
Thanks
Sunadd a single quote to the beginning of the field.
like: '-abcde
in excel it will be shown as : -abcde -
Download to Excel with Header but one field data is repeating
Hi All,
I'm downloading to Excel with Header. But One field is repeating and another is not. This is happening only when I use 'CONCATENATE ' . With Out this key usage data download to excel is correct. But CONCATENATE is required as constant need to add before the one field.
My coding is as below.
DATA: BEGIN OF IT_FINAL OCCURS 0,
P1(10) TYPE C,
SI(19) type c,
END OF IT_FINAL.
DATA : BEGIN OF IT_HEADER OCCURS 0,
TITLE(100) TYPE C,
END OF IT_HEADER,WA_HEADER LIKE IT_HEADER.
loop at it_final.
CONCATENATE '894412' it_final-SI INTO IT_FINAL.
modify it_final.
endloop.
CLEAR:WA_HEADER.
WA_HEADER-TITLE = 'Mat No'.
APPEND WA_HEADER TO IT_HEADER.
CLEAR:WA_HEADER.
WA_HEADER-TITLE = 'Serial'.
APPEND WA_HEADER TO IT_HEADER.
CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
EXPORTING
FILE_NAME = P_FILE " path offile where u need to download
TABLES
DATA_TAB = IT_FINAL
FIELDNAMES = IT_HEADER.
CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
EXPORTING
FILE_NAME = P_FILE " path offile where u need to download
TABLES
DATA_TAB = IT_FINAL
FIELDNAMES = IT_HEADER.
Excel OUT PUT:
Mat No Serial
11Z52321 8944126000
11Z52394 8944126000
11Z52395 8944126000
Thank You,
Pranithahi,
it would have been better if u hve opt for creating workarea for ur internal table.
Try to use "clear it_final" after
CONCATENATE '894412' it_final-SI INTO IT_FINAL.
n also change the modify statement :
modify it_final transporting SI .
hope this will surely help you
Regards,
Punit
Edited by: punit raval on Aug 26, 2011 2:55 PM -
ALV download to Excel--Problem with Column Headers
Hi,
I have created a dynamic internal table and displaying it as ALV using SALV classes. Problem is that when I download this ALV to Excel I'm not getting Column headings same as they are in ALV display.
I mean in Excel it is showing Column headings taken from domain or data element.
While creating dynamic table i'm passing short/ Medium & Long text too. Still it is not working.
Any kinda help is appreciated.
Thanks & Regards,
Vivek Gaur
Edited by: Vivek Gaur on Nov 4, 2009 2:04 PMLook I cant actually post the code as it is divided in some global classes and main program. But i can elaborate the steps little further:
1: I have created a field catalog for Dynamic internal table. In it i have passed every necessary field along with short/medium/Long texts.
2: I fill up this dynamic table with data.
3: I assign a field symbol to this dynamic internal table.
4: I pass this field symbol to the factory method of CL_SALV_TABLE Class.
Thats it buddy..Hope u have understood my problem. -
Reg: ALV report download to excel currency columns
Hi All,
While downloading the alv report to excel, currency fields with negative sign(less than 0) is downloading without negative sign.
And field catalog wad declared as 'CURR' field for that particular column, if I declared as 'CHAR', i am getting shortdump.
Can any one tell me how to get the negative sign.
Thanks in advance.Hi,
Do you use ALV to excel standard functionality or your own code to excel?
Please provide more information.
Thanks, -
ALV download to EXCEL -- probs with SAPGUI 6.40 and EXCEL 2007
I have a method in an ALV grid which performs a dowload to excel
Here's the method
method download_to_excel.
field-symbols:
<fs0> type standard table,
<fs1> type standard table.
assign g_outtab1->* to <fs0>.
assign g_fldcat1->* to <fs1>.
call function 'LVC_TRANSFER_TO_KKBLO'
exporting
it_fieldcat_lvc = <fs1>
is_layout_lvc = m_cl_variant->ms_layout
is_tech_complete = ' '
importing
es_layout_kkblo = ls_layout
et_fieldcat_kkblo = lt_fieldcat.
loop at lt_fieldcat into lt_fieldcat_wa.
clear lt_fieldcat_wa-tech_complete.
if lt_fieldcat_wa-tabname is initial.
lt_fieldcat_wa-tabname = '1'.
modify lt_fieldcat from lt_fieldcat_wa.
endif.
l_tabname = lt_fieldcat_wa-tabname.
endloop.
call function 'ALV_XXL_CALL'
exporting
i_tabname = l_tabname
is_layout = ls_layout
it_fieldcat = lt_fieldcat
i_title = sy-title
tables
it_outtab = <fs0>
exceptions
fatal_error = 1
no_display_possible = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type 'S' number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endmethod.
Basically the method converts the GRID table I'm displaying into the format requred for FMOD ALV_XXL_CALL' -- the field catalog is slightly different but no big deal here.
This works fine when downloading to EXCEL 2003 but short dumps when trying to do the same thing for EXCEL 2007.
Workstation is running Windows XP / SP2 build 2600 in both cases.
Any fixes etc or should I stick with EXCEL 2003 until forced to upgrade.
Cheers
jimboHi all
Seems the problem disappeared after applying the latest patch to SAP_GUI 6.40.
I haven't tried SAP_GUI 7.0 yet.
Thanks anyway
Cheers
jimbo -
ALV Download to Excel Column Colors Problem
Hi Experts,
I've encountered a problem in downloading records from ALV display to excel file.
The file is downloaded SUCESSFULLY however. When I opened the downloaded file, some columns were filled up with color(yellow) and other fields are not.
Do anyone have an idea why?I have 21 Columns columns. The first 16 columns are filled with yellow colors...
-
Download ALV output to excel with formatting
Hi All,
i want to download ALV output to excel sheet and the uneditable fields in ALV oputput should be locked (uneditable) in excel also.
Can you please tell me approach to achieve this functionality?
Thanks in advance.Thanks Vamsi. Your Suggestion was helpful.
I have used excel integration and used SET PROPERTY OF (COLUMN) 'LOCKED' = 1.
For more details refer below mentioned link.
http://webcache.googleusercontent.com/search?q=cache:SoY6hFC17PoJ:wiki.sdn.sap.com/wiki/display/Snippets/Download%2BData%2Binto%2BMultiple%2BSheet%2BExcel%2BDocument%2Bwith%2BNon%2BEditable%2BColumns%2B(Password%2Bprotected)%2BUsing%2BABAP%2BOLESetPropertynoteditableexcelsapABAP&cd=1&hl=en&ct=clnk&gl=in&source=www.google.co.in (http://webcache.googleusercontent.com/search?q=cache:SoY6hFC17PoJ:wiki.sdn.sap.com/wiki/display/Snippets/Download%2BData%2Binto%2BMultiple%2BSheet%2BExcel%2BDocument%2Bwith%2BNon%2BEditable%2BColumns%2B%28Password%2Bprotected%29%2BUsing%2BABAP%2BOLESetPropertynoteditableexcelsapABAP&cd=1&hl=en&ct=clnk&gl=in&source=www.google.co.in -
ALV output download to excel with top of page
Hi,
i want to download ALV grid output to excel sheet including the top of page. i am using the icon in application tool bar. but only data's are download to excel sheet. i cannot download the top of page. with out write coding in program can we download it. if yes pls explain.
thanks.I'm sorry but I can't find FM with DOWNLOAD_EXCEL_*.
I want to know more detail thing.
plz. give answer to me anytime.
I'm waiting..
Edited by: Kwang Seop Kim on Sep 26, 2008 6:57 AM -
ALV / Download to Excel - columns transposed
A developer on my team has this problem:
We have a ALV report that gives the user the option to download to excel.
The report has columns.
A,B,C,D (for example)
but when the user exports to excel ("List > Export > Spreadsheet > Table")
they get
A, <b>C, B</b>, D
Dose anyone know why this happens? We have checked various sites and found OSS note 358644.
Are we on the right track? Or is there an easy answer to this.
Thanks in advance.Hi Kyle,
I too faced the same problem lon back. But what we
found is for currency, date and amount fields it is
moving to last.
You also checl the standard program BCALV_GRID_01.
If you download you can see the same thing happens
here also.
Check in your case whether B is date, amout or numeric field.
Thanks & Regards,
Siri.
Kindly award points if the answer is useful.
Maybe you are looking for
-
How do I transfer a site to another member to use?
How do I transfer a site to another member to use?
-
Is it possible to create a LOV opening a "search window" in wich the user can search and select the value he wants and have back the value in the main form ? Any suggestion will be appreciated. TIA Tullio
-
Why will iMovie allow editing of some songs and not others?
I've downloaded a number of songs directly from iTunes onto my ipad2. Why can I edit one song I downloaded and not others in I movie? I don't get it. These songs are from the same album, so if its a copyright issue what's the deal? Help me please!
-
hello: i have an ATT sim card in the phone, then i get this error message, Error 1015
-
Finder keeps opening/crashing 10.6.8
Hi, upon startup my finder constantly opens and crashes and I figured the easiest way for me to resolve this issue is if I revert back with time machine. The problem is, I can't access time machine because finder isn't functioning properly. If I acce