Skip to Content
author's profile photo Former Member
Former Member

FileDownload in CSV Format

I have used the FileDownload option to download the file by seeing WDR_TEST_EVENTS. Using that i am downloading the file in TXT format. But i want the file in CSV Format. How can i get this ?

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    Posted on Oct 13, 2008 at 11:40 AM

    Hi Manjunath,

    Below is the solution if you aren't to use the FileDownload UI element.

    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.

    You can also go through[ this link|http://saptechnical.com/Tutorials/WebDynproABAP/Export/toexcel.htm] for a similar example.

    Regards,

    Uday

    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
        IMPORTING
          table = lt_mara.
    
      LOOP AT lt_mara INTO wa_mara.
        CONCATENATE mara_string
                    wa_mara-matnr
                    wa_mara-ersda
                    wa_mara-ernam
                    wa_mara-matkl
                    wa_mara-meins
                    cl_abap_char_utilities=>newline INTO mara_string
                                            SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
      ENDLOOP.
    
      CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
        EXPORTING
          text   = mara_string
        IMPORTING
          buffer = mara_xstring.
    
    
      wdr_task=>client_window->client->attach_file_to_response(  i_filename  = 'TEMP.DOC'
                                                                 i_content   = mara_xstring
                                                                 i_mime_type = 'WORD' ).
    ENDMETHOD.

    The above is the code to export the Internal Table to Word Document. You can proceed as shown below for Excel & NOTEPAD formats.

    To Export the Internal Table to Text File:

    WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(
        I_FILENAME    = 'WDP.txt'
        I_CONTENT     =  mara_xstring
        I_MIME_TYPE   = 'NOTEPAD' ).

    To Export the Internal Table to Excel File:

    WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(
        I_FILENAME    = 'Excel.xls'
        I_CONTENT     =  mara_xstring
        I_MIME_TYPE   = 'EXCEL' ).

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 13, 2008 at 11:39 AM

    Hi Manjunath,

    Please check this thread and check the code given by Henry.

    file-download-wd4a

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.