Skip to Content
avatar image
Former Member

Exporting content of ALV grid in Web Dynpro for ABAP

Hello Experts

I have a following request which seems to be giving some headaches.

I need to export results from one of the Web Dynpro reports (ABAP) I have developed to the Excel spreadsheet. Results are stored on ALV component. Request is to add header to export file with additional information like report title, selection criteria, date when report has been executed. By default export file contains only column names and data. I have set the header for ALV grid with all extra information I need to be passed to Excel file but it does not seem to be transferred at all.

At the moment I see 2 possible solutions: 1) write my own Excel export 2) use PDF export where it is possible to set header/footer text. None of these solutions are ideal, I'd rather set header in standard Excel export. Is that even possible? Please help.



Edited by: Soltuion Manager on Apr 20, 2009 10:08 AM

Edited by: Soltuion Manager on Apr 20, 2009 10:26 AM

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Apr 20, 2009 at 08:41 AM

    Hello Michael,

    I haven't tried using the builtin functionality of ALV to achieve a similar fnctionality as yours but can suggest you a workaround for that. As how you might be already knowing you can try using the CL_WD_RUNTIME_SERVICES=>attach_file_to_response to download the contents into Excel/notepad/word. So just can modify the internal table to contain the extra information that you need. You can use the approach below for using the attach_file_to_response method:

    1) First read the table's data into an internal table.

    2) Convert the internal table data to STRING format.

    3) Now convert it into tab separated format as how desired.

    4) Convert this STRING format to XSTRING format

    5) Make use of the attach_file_to_response method.



    METHOD onactionon_submit .
      DATA: lv_node TYPE REF TO if_wd_context_node,
            lt_mara TYPE if_main=>elements_mara,
            wa_mara TYPE if_main=>element_mara,
            lead_selection_index TYPE i,
            mara_string  TYPE string,
            mara_xstring TYPE xstring.
      lv_node = wd_context->get_child_node( name = 'MARA' ).
      CALL METHOD lv_node->get_static_attributes_table
          table = lt_mara.
      LOOP AT lt_mara INTO wa_mara.
        CONCATENATE mara_string
                    cl_abap_char_utilities=>cr_lf INTO mara_string
                                            SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
    ** Now you need to add the column headers & the desired extra information through coding to 
    ** mara_string
          text   = mara_string
          buffer = mara_xstring.
      CL_WD_RUNTIME_SERVICES=>attach_file_to_response(  i_filename  = 'TEMP.XLS'
                                                        i_content   = mara_xstring
                                                        i_mime_type = 'EXCEL' ).

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member


      Thanks for your suggestion but as I mentioned it is not ideal solution here (I donu2019t want to re-invent the wheel if it is not necessary). I used ALV component hoping that it will accommodate all basic needs without having to do custom coding. If it will turn out that there is no way to set header in standard Excel export I will have to write my own export or use PDF export. I will wait and see if someone else will come up with other ideas.



  • Apr 21, 2009 at 12:11 AM

    The ALV export to Excel is pretty much as you see it. I don't believe there is any other way to influence it. You will likely have to fall back on one of your two options - custom Excel export or PDF. In NetWeaver 7.0 Enhancement Package 2 we are adding a new option to the ALV export - Crystal Reports. It, like the PDF exporter, does allow you to set the report headers.

    Add comment
    10|10000 characters needed characters exceeded