Skip to Content
avatar image
Former Member

FM for downloading to an Excel file

I want to download an internal table data to an excel sheet.Which FM should i use also tell me how should each column value go under the appropriate field name.

Regards,

Linda

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

8 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 04, 2008 at 07:10 AM

    hiii

    use following FM

    ..here need to pass internal table like i_output in following code..and column of excel sheet will arrange data as per the fields of internal table.

    FORM get_download_data USING p_pfile .
    
      DATA:
        lw_file TYPE string .
                                           " File Path
        lw_file = p_pfile.
    
    
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
    *   BIN_FILESIZE                    = BIN_FILESIZE
          filename                        = lw_file
          filetype                        = 'DBF'
    *   APPEND                          = ' '
       write_field_separator           = 'X'
    *   HEADER                          = '00'
    *   TRUNC_TRAILING_BLANKS           = 'X'
    *   WRITE_LF                        = 'X'
    *   COL_SELECT                      = 'X'
    *   COL_SELECT_MASK                 = p_col_sel
    *   DAT_MODE                        = ' '
    *   CONFIRM_OVERWRITE               = ' '
    *   NO_AUTH_CHECK                   = ' '
    *   CODEPAGE                        = ' '
    *   IGNORE_CERR                     = ABAP_TRUE
    *   REPLACEMENT                     = '#'
    *   WRITE_BOM                       = ' '
    *   TRUNC_TRAILING_BLANKS_EOL       = 'X'
    *   WK1_N_FORMAT                    = '0'
    *   WK1_N_SIZE                      = ' '
    *   WK1_T_FORMAT                    = ' '
    *   WK1_T_SIZE                      = ' '
    * IMPORTING
    *   FILELENGTH                      = FILELENGTH
        TABLES
          data_tab                        = i_output
          fieldnames                      = i_final
        EXCEPTIONS
          file_write_error                = 1
          no_batch                        = 2
          gui_refuse_filetransfer         = 3
          invalid_type                    = 4

    regards

    twinkal

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 07:07 AM

    Hi,

    FM,

    GUI_DOWNLOAD.

    Regards

    Adil

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 07:08 AM

    Hi,

    Use function module GUI_DOWNLOAD.

    Check this sample code

    REPORT  z_file_download.
    DATA: w_name(90) TYPE c.
    DATA:
      BEGIN OF fs_flight,
        carrid   LIKE sflight-carrid,
        connid   LIKE sflight-connid,
        fldate   LIKE sflight-fldate,
        price    LIKE sflight-price,
        currency LIKE sflight-currency,
      END OF fs_flight.
    DATA:
      t_flight LIKE
         TABLE OF
               fs_flight.
    
    
    START-OF-SELECTION.
      SELECT carrid
             connid
             fldate
             price
             currency
        FROM sflight
        INTO TABLE t_flight
       WHERE carrid IN s_carrid.
    
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename                = 'D:\flight.xls'
          filetype                = 'ASC'
          write_field_separator   = 'X'
        TABLES
          data_tab                = t_flight
        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 EQ 0.
        MESSAGE 'Download successful' TYPE 'I'.
      ENDIF.
      IF sy-subrc NE 0.
    *  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    

    Regards

    Abhijeet

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 07:11 AM

    Hi,

    use FM

    FORM f10_getfile.

    CALL FUNCTION 'F4_FILENAME'

    EXPORTING

    program_name = syst-cprog

    dynpro_number = syst-dynnr

    • FIELD_NAME = ' '

    IMPORTING

    file_name = p_pfile.

    and pass this in GUI_DOWNLOAD FM

    FORM f400_dwnloadmatdata .

    DATA:

    lw_file1 TYPE string . " File Path

    lw_file1 = p_filep.

    CALL FUNCTION 'GUI_DOWNLOAD'

    EXPORTING

    • BIN_FILESIZE = BIN_FILESIZE

    filename = lw_file1

    filetype = 'DBF'

    • APPEND = ' '

    write_field_separator = 'X'

    it will give you browsing facility for file and then it will download data at that place only ..no need to hard code that file path

    You can also find the similar thread below

    download excel file

    Manish

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 07:11 AM

    Hi Linda,

    use the function module

    ALSM_EXCEL_TO_INTENAL_TABLE

    you can get it

    Regards,

    Chinna

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 04, 2008 at 07:17 AM

    Hi Linda,

    Check the code below...

    PARAMETERS : p_dload TYPE rlgrap-filename.
    DATA : w_dload TYPE string.
     
    TYPES : BEGIN OF ty_kna1,      " structure
            kunnr TYPE kna1-kunnr,
            name1 TYPE kna1-name1,
            ort01 TYPE kna1-ort01,
            land1 TYPE kna1-land1,
            END OF ty_kna1.
     
    DATA :  it_kna1 TYPE TABLE OF ty_kna1.  "body
     
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dload.
      PERFORM f_dload.
    START-OF-SELECTION.
     
      PERFORM f_extract.
      PERFORM f_download.  " download file to presentation server
    *&---------------------------------------------------------------------*
    *&      Form  f_dload
    *&---------------------------------------------------------------------*
    FORM f_dload .
      CALL FUNCTION 'F4_FILENAME'
    * EXPORTING
    *   PROGRAM_NAME        = SYST-CPROG
    *   DYNPRO_NUMBER       = SYST-DYNNR
    *   FIELD_NAME          = ' '
        IMPORTING
          file_name           = p_dload
                 .
     
    ENDFORM.                    " f_dload
    *&---------------------------------------------------------------------*
    *&      Form  f_extract
    *&---------------------------------------------------------------------*
    FORM f_extract .
      SELECT kunnr
              name1
              ort01
              land1 FROM kna1 INTO TABLE it_kna1 .
    ENDFORM.                    " f_extract
     
    *&---------------------------------------------------------------------*
    *&      Form  f_download
    *&---------------------------------------------------------------------*
    FORM f_download .
      w_dload = p_dload.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
    *   BIN_FILESIZE                    =
          filename                        = w_dload
       filetype                        = 'ASC'
    *   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                        = it_kna1
    *   FIELDNAMES                      =
     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 ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDFORM.                    " f_download

    With Regards..

    Always Learner

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 07:17 AM

    Use FM SAP_CONVERT_TO_XLS_FORMAT

    Regards,

    Prashant

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 04, 2008 at 07:19 AM

    PLz user Follwing Method

    CALL METHOD cl_gui_frontend_services=>file_save_dialog

    EXPORTING

    window_title = l_window_title

    default_extension = 'XLS'

    • DEFAULT_FILE_NAME =

    • FILE_FILTER =

    • INITIAL_DIRECTORY =

    CHANGING

    filename = l_filename

    path = l_path

    fullpath = l_fullpath

    • USER_ACTION =

    EXCEPTIONS

    cntl_error = 1

    error_no_gui = 2

    not_supported_by_gui = 3

    OTHERS = 4.

    IF sy-subrc <> 0.

    EXIT.

    ENDIF.

    regards

    Rajesh

    Add comment
    10|10000 characters needed characters exceeded