Skip to Content
avatar image
Former Member

How can I change the file name while using EXPORT functionality of WEB DYNPRO ALV?

Hi Everyone,

I have a requirement where I have to change the file name, while exporting ALV to excel sheet.

By default file name is 'Export.XLSX', I have to change it.

Is it possible?

Also, When I am exporting my internal table into Excel, using the below mentioned code, I always get the following warning ''The file format and extension don't match ''.

LOOP AT lt_comp_dtls INTO ls_comp_dtls.

           CONCATENATE  ls_comp_dtls-pernr

                        ls_comp_dtls-name

                        ls_comp_dtls-div_desc

                        ls_comp_dtls-div1_desc

                        ls_comp_dtls-org

                        ls_comp_dtls-cost_c

                        ls_comp_dtls-job_ttl

                        ls_comp_dtls-ch_nch

                        ls_comp_dtls-mandt_assigned

                        ls_comp_dtls-mandt_due

                        ls_comp_dtls-mandt_complete

                        ls_comp_dtls-duelt30days

                        ls_comp_dtls-duege30days

                        ls_comp_dtls-emp_email

                        ls_comp_dtls-sup_name

                        ls_comp_dtls-sup_email

                        ls_comp_dtls-pers_admin

                        cl_abap_char_utilities=>newline INTO lv_text1

                        SEPARATED BY cl_abap_char_utilities=>horizontal_tab.

           CONCATENATE  lv_text_full lv_text lv_text1 INTO lv_text_full.

CALL FUNCTION 'SDOK_MIMETYPE_GET'

           EXPORTING

             extension = '.XLS'

           IMPORTING

             mimetype  = lv_mime.



CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

           EXPORTING

             text   = lv_text_full

           IMPORTING

             buffer = lv_xtext.


CALL METHOD cl_wd_runtime_services=>attach_file_to_response

           EXPORTING

*           i_filename      = 'Download.xls'

             i_filename      = lv_filename

             i_content       = lv_xtext

             i_mime_type     = lv_mime_str "'EXCEL'

             i_in_new_window = abap_false

             i_inplace       = abap_false.

Please provide your valuable suggestions on this.

Thanks,

Faraz Khan

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Apr 04, 2016 at 08:10 AM

    Hi Faraz ,


    please try below code it may help u



    data: lv_text1 type string,

             lv_xtext type xstring.



    LOOP AT lt_comp_dtls INTO ls_comp_dtls.

               CONCATENATE  ls_comp_dtls-pernr

                            ls_comp_dtls-name

                            ls_comp_dtls-div_desc

                            ls_comp_dtls-div1_desc

                            ls_comp_dtls-org

                            ls_comp_dtls-cost_c

                            ls_comp_dtls-job_ttl

                            ls_comp_dtls-ch_nch

                            ls_comp_dtls-mandt_assigned

                            ls_comp_dtls-mandt_due

                            ls_comp_dtls-mandt_complete

                            ls_comp_dtls-duelt30days

                            ls_comp_dtls-duege30days

                            ls_comp_dtls-emp_email

                            ls_comp_dtls-sup_name

                            ls_comp_dtls-sup_email

                            ls_comp_dtls-pers_admin

                            cl_abap_char_utilities=>newline INTO lv_text1

                            SEPARATED BY cl_abap_char_utilities=>horizontal_tab.


               CONCATENATE  lv_text_full lv_text lv_text1 INTO lv_text_full.


    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

               EXPORTING

                 text   = lv_text_full

               IMPORTING

                 buffer = lv_xtext.

      WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(
    **path to the word file
      I_FILENAME = 'flight_details.xls' " here is your File Name
    * String Variable
      I_CONTENT = lv_xtext
    * File Type
      I_MIME_TYPE = 'EXCEL' ).   " this is the type of file you r exporting like "EXCEL" , "WORD",                                                                          "TXT" etc




    Thanks

    Nidhi

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Naresh,

      Thanks for your suggestion.

      I will try the code as mentioned by you and I will let you know the result.

      Thanks,

      Faraz Khan