Application Development 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: 

Download classical report output to an excel file

Former Member
0 Kudos

Hi all,

I want to download the output of classical report to an excel file. I have used the following function:

CONCATENATE 'e:\' 'sap.txt' INTO fna.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = fna

FILETYPE = 'ASC'

tables

data_tab = it_final.

IF sy-subrc = 0.

  • MESSAGE s005 with fna.

ENDIF.

now this function is coverting the output into a normal text file in a notepad.. When I give the file type as 'XLS', it gives an error saying that the value of parameter filetype is not correct.

please tell me about what can be the possible method for fulfilling my requirement

Regards,

Nikita

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI,

Give the file name as SAP.xls not SAP.txt.

Give FILETYPE = 'ASC'.

Regards

Sumit Agarwal

7 REPLIES 7

Former Member
0 Kudos

HI,

Give the file name as SAP.xls not SAP.txt.

Give FILETYPE = 'ASC'.

Regards

Sumit Agarwal

naveen_inuganti2
Active Contributor
0 Kudos

Hi....

Giving sample code...

data: p_file type string,
        p_path type string.

  perform fill_titles.                 <------ fill the titile table here
      p_file = 'file.xls'.
    call method cl_gui_frontend_services=>file_save_dialog
      exporting
        default_file_name    = p_file
      changing
        filename             = p_path
        path                 = p_path
        fullpath             = p_file
      exceptions
        cntl_error           = 1
        error_no_gui         = 2
        not_supported_by_gui = 3
        others               = 4.

    if sy-subrc <> 0.
      message id sy-msgid type sy-msgty number sy-msgno
                 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
    if p_file is initial.
      message 'failed' type 'E'.
    endif.

    call function 'gui_download'
        exporting
*           BIN_FILESIZE                    =
          filename                        = p_file
          filetype                        = 'dat'
*           APPEND                          = ' '
          write_field_separator           = 'x'
*           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'
*           WK1_N_FORMAT                    = ' '
*           WK1_N_SIZE                      = ' '
*           WK1_T_FORMAT                    = ' '
*           WK1_T_SIZE                      = ' '
*         IMPORTING
*           FILELENGTH                      =
        tables
          data_tab                        = i_hold
          fieldnames                      = titles_it
       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 ne 0.
      
    endif.
  endif.

Thanks,

Naveen.I

Former Member
0 Kudos

Hi Nikita,

If you want to download an Excel file for the o/p

Then let the FILETYPE = 'ASC'.

Make changes to the variable fna

Make it CONCATENATE 'e:\' 'sap.xls' INTO fna.

This will help

Regards,

Prashant

Former Member
0 Kudos

hii

your code is correct jst check with following code too and try changing FILETYPE as DBF.

DATA:
    lw_file TYPE string .
                                       " File Path
    lw_file = p_pfile. -----------------------> give file as .XLS type
  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                        = lw_file
      filetype                        = 'DBF'
   write_field_separator           = 'X'
    IMPORTING
    FILELENGTH                      = FILELENGTH
    TABLES
      data_tab                        = i_output
      fieldnames                      = i_final

regards

twinkal

narin_nandivada3
Active Contributor
0 Kudos

Hi NIKITA,

Everything you had done is fine except CONCATENATE 'e:\' 'sap.txt' INTO fna.

change it as CONCATENATE 'e:\' 'sap.xls' INTO fna.

This would solve your issue.

Good luck

Narin

Former Member
0 Kudos

Hi nikita,

dont change filetype.

just change the file name to .xls

Former Member
0 Kudos

Thank u sumit n thank u all for solving my problem... I was doing a silly mistake..

cheers,

Nikita