FM GUI_DOWNLOAD

Hi
I am using FM 'GUI_DOWNLOAD' to download the data in Excel format. Now i am able to download the data in proper format bur unable to download the header of the columns. Can anyone have solution to this??

Yes, it is possible to download column headers with GUI_DOWNLOAD. To do this,
you must provide the parameter FIELDNAMES with a corresponding table:
This table must be a single-line table.
The following is a corresponding "showcase" source code:
REPORT reportname.
"    Declaration of Line Type: SPFLI                                  *
TYPES: BEGIN OF line_type,
         field1 LIKE spfli-carrid,
         field2 LIKE spfli-connid,
         field3 LIKE spfli-cityfrom,
       END OF line_type.
"    Declaration of Table Type                                        *
TYPES tab_type TYPE STANDARD TABLE OF line_type.
"    Declaration of internal Table                                    *
DATA: itab  TYPE tab_type.
"    Declaration of workarea                                          *
DATA: wa   TYPE line_type.
"    Declaration of Fieldnames                                        *
DATA: BEGIN OF colnames OCCURS 0,
        col(10) TYPE c,
      END OF colnames.
"    One Colname per line                                             *
colnames-col = 'Column1'. APPEND colnames.
colnames-col = 'Column2'. APPEND colnames.
colnames-col = 'Column3'. APPEND colnames.
START-OF-SELECTION.
   "    Get the data and fill the workarea                             *
   SELECT carrid connid cityfrom
     FROM spfli
     INTO (wa-field1, wa-field2, wa-field3).
     APPEND wa TO itab.
   ENDSELECT.
   IF sy-subrc <> 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.
   "    Now download the itab with fieldnames:                         *
   "    By using dat_mode and fieldseparator                           *
   CALL FUNCTION 'GUI_DOWNLOAD'
     EXPORTING
       filename              = 'C:\TEMP\test.txt'
       filetype              = 'ASC'
       dat_mode              = 'X'
       write_field_separator = 'X'
     TABLES
       data_tab              = itab
       fieldnames            = colnames
     EXCEPTIONS
       OTHERS                = 1.
   if sy-subrc <> 0.
     message i398(00) with 'Error: ' sy-subrc 'during gui_download!'.
   endif.

Similar Messages

  • Filename in gui_download and ws_download

    Hi Friends..
    if i using like this..
    concatenate 'C:\'
                  syst-date
                  '.xls'
        into mc_filename.
    in program and gave the mc_filname as a filename in the function module.its working fine in ws_download but it was not working in gui_download function module.
    so please give your valuable suggetion regarding this..
    Thanks
    Gowrishankar

    Hi Gowrishankar,
    In WS_DOWNLOAD Function module Filename type is char but
    In GUI_DOWNLOAD Function module Filename type is string.
    so it is going to dump. first change the type of filename in your program
    Plzz reward if it is helpful,
    Mahi.

  • Issue in conversion of output file from alv to csv file using GUI_DOWNLOAD

    hi,
    I am using GUI_DOWNLOAD to convert the internal table that am getting as the output of an alv into a csv(comma separated file) file.I am using the following code but its not generating a csv file instead it is generating a normal space delimited file.
    The code is as follows:
    data : lv_fname type string.
    lv_fname = 'C:\Users\pratyusha_tripathi\Desktop\status8.csv'. " Provide the file path & file name with CSV extention
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    filename = lv_fname " File name including path, give CSV as extention of the file
    FILETYPE = 'DAT'
    WRITE_FIELD_SEPARATOR = '#' " Provide comma as separator
    tables
    data_tab = ITAB " Pass the Output internal table
    FIELDNAMES =
    EXCEPTIONS
    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.
    Kindly let me know what changes can be made to make my code work.Also can GUI_download be used for batch processing and storing the output in application server?
    Thanks ,
    Pratyusha

    Hi,
    the short text description for WRITE_FIELD_SEPARATOR is "Separate Columns by Tabs in Case of ASCII Download", so why do you expect a comma?
    Try SAP_CONVERT_TO_CSV_FORMAT and then download.
    And no, GUI_DOWNLOAD is only for download via SAP GUI to a users computer.
    Best regards,
    Oliver

  • Issue in GUI_DOWNLOAD

    Hi Experts,
    We are using GUI_DOWNLOAD function module to download data into presentation server in ECC6.
    DATA: T_DATX(300) OCCURS 500 WITH HEADER LINE.
    T_DATX is the one we are passing to FM which contains data to be downloaded.
    In 4.7 version, we have used DATA: _T(1) TYPE x VALUE '09' as field seperator.
    but its not accepting in ECC6 after upgrade. so to overcme this, we have used DATA: T(1) TYPE C VALUE CLABAP_CHAR_UTILITIES=>VERTICAL_TAB. but still its not downloading properly into cells in the excel sheet.
    its downloading single record into single cell. How come I overcome this.
    Pls advice. I have given the below code for your reference.
    DATA: T_DATX(300) OCCURS 500 WITH HEADER LINE.
    Modification ECC 6.0 Release Upgrade START *
    DATA: _T(1) TYPE x VALUE '09'.
      DATA: T(1) TYPE C VALUE CLABAP_CHAR_UTILITIES=>VERTICAL_TAB.
    Modification ECC 6.0 Release Upgrade END *
    *data: _t(1) type c value ';'.
      DATA: _REPID LIKE SY-REPID
           ,_COMP  LIKE RSTRUCINFO OCCURS 10 WITH HEADER LINE
           ,_IDX   LIKE SY-TABIX
           ,F_TYPE(1)
      FIELD-SYMBOLS: <FS>.
      _REPID = SY-REPID.
      CALL FUNCTION 'GET_COMPONENT_LIST'
           EXPORTING
                PROGRAM    = _REPID
                FIELDNAME  = TABNAME
           TABLES
                COMPONENTS = _COMP
           EXCEPTIONS
                OTHERS     = 1.
      LOOP AT _COMP.
        CONCATENATE T_DATX _COMP-COMPNAME T INTO TDATX.
      ENDLOOP.
      APPEND T_DATX.
      CLEAR T_DATX.
      LOOP AT T_EX.
        _IDX = 1.
        ASSIGN COMPONENT IDX OF STRUCTURE TEX TO <FS>.
        DO.
          CONCATENATE T_DATX <FS> T INTO TDATX.
          _IDX = _IDX + 1.
          ASSIGN COMPONENT IDX OF STRUCTURE TEX  TO <FS> .
          IF SY-SUBRC <> 0. EXIT. ENDIF.
        ENDDO.
        APPEND T_DATX.
        CLEAR T_DATX.
      ENDLOOP.
    Regards,
    Sujatha

    Hi Sujatha,
    As suggested by previous poster, you should use horizontal tab as a separator (or a comma) to get a tab-delimited/CSV type format that you can open in Excel. However, instead of building the output table yourself as text lines, I'd simply pass the actual output table to function GUI_DOWNLOAD in parameter DATA_TAB, use table FIELD_NAMES for the column headers (looks like you want those based on your coding) and then set the FILE_TYPE parameter to 'DAT'.
    Best wishes, harald

  • Issue with filename in gui_download fn module

    Hi,
    i have an issue with the filename of text file that was dowloaded using gui_download fn module.
    PARAMETERS : p_file TYPE rlgrap-filename.
    CONCATENATE s_laufd-low6(2) s_laufd-low4(2) INTO gv_dt.
    CONCATENATE 'HINL' gv_dt '.001' INTO p_file.
    START-OF-SELECTION.
      DATA: v_file TYPE string.
      v_file = p_file.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename                = v_file
          filetype                = 'ASC'
          append                  = 'X'
        TABLES
          data_tab                = it_tab[]
        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.
    data is downloaded into the textfile with filename as HINL2411 truncating the decimal part.
    How can i get the filename along with the decimal part as HINL2411.001.
    Thanks

    Hi ,
    Declare p_file  as TYPE string

  • How to get some character as a field separator while in GUI_DOWNLOAD ?

    Hi Friends,
    I have to download data from an internal table to a text file. The field separator
    between the fields should be comms (,). So, after getting the data into internal table i'm calling the Function Module GUI_DOWNLOAD. Now using this function module can i insert a comma spearator between the fields, if not what is the other way to do it?

    Hi,
    Its not possible to give the field separator as ',' directly with gui_download from you internal table.
    Below is the example through which you can achieve the following,
    this is a tested program and is working fine on the system....
    so you can use the logic to achieve the following result.... hope this logic helps you to achieve your functionality....
    DATA:
    BEGIN OF fs,
       col1(6) TYPE c,
       col2(4) TYPE c,
       col3 TYPE c,
       END OF fs.
    DATA :
    BEGIN OF line,
    line(255) TYPE c,
    END OF line.
    DATA: itab LIKE TABLE OF fs,
          itab2 LIKE TABLE OF line.
    DEFINE m_tab.
      clear fs.
      fs-col1 = &1.
      fs-col2 = &2.
      fs-col3 = &3.
      append fs to itab.
    END-OF-DEFINITION.
    m_tab '006000' '0010' 'J'.
    m_tab '006000' '0010' 'J'.
    m_tab '006000' '0010' 'M'.
    m_tab '006000' '0010' 'M'.
    m_tab '006000' '0010' 'O'.
    m_tab '006000' '0010' 'O'.
    m_tab '006000' '0010' 'T'.
    m_tab '006000' '0010' 'T'.
    LOOP AT itab INTO fs.
      CONCATENATE fs-col1
                  fs-col2
                  fs-col3
             INTO line
    SEPARATED BY ','.
      APPEND line TO itab2.
    ENDLOOP.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
    *   BIN_FILESIZE                    =
        filename                        = 'C:\filename.txt'
    *   FILETYPE                        = 'ASC'
    *   APPEND                          = ' '
    *   WRITE_FIELD_SEPARATOR           = ' '
    *   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                      = ' '
    *   WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE
    *   SHOW_TRANSFER_STATUS            = ABAP_TRUE
    * IMPORTING
    *   FILELENGTH                      =
      TABLES
        data_tab                        = itab2
    *   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.
      WRITE sy-subrc.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Regards,
    Siddarth

  • Move negative sign (minus) to left side of value in gui_download

    Hi,
    While downloading data using gui_download I want to bring the negative sign to the left side of the value. Is this possible?
    Regrads,
    Madhu

    Hi,
    Use FM
    CALL FUNCTION  'CLOI_PUT_SIGN_IN_FRONT'
    Regards.
    Eshwar.

  • How to put the header in excel file in GUI_DOWNLOAD

    Hi,
    I have a requirement , Which I m downloading the contents of internal table using the GUI_DOWNLOAD  in excel format, I need to keep the first line of the excel sheet as a header, Can any one suggest how to go for this,

    Hello,
    You can have the data in the data tab & field name in the field tab. And so you can download both the field name and the value for the same using the FM u2013 GUI_DOWNLOAD (File type should be u2018ASCu2019).
    Hope, you need additional information to be added as the header.
    One option: You can call the GUI_UPLOAD twice.
    First one with the header in the data tab.
    Second one with the option append = u2018Xu2019 with the actual data and header and pass the same above file name as input.
    Also, there is a solved forum already exists but with a different solution. You can go through the below link also:
    Re: GUI_DOWNLOAD with Header
    Regards,
    Selva K.

  • Add double quotes (") surrounding each field in GUI_DOWNLOAD

    Experts,
    Does anyone know if it is possible to add double quotes (") to all fields in .txt file using FM GUI_DOWNLOAD besides manually concatenate the quotes into each field before calling the FM?
    For example, output need to be:
    "0000123" "NAME1" "   200.00"
    Any advice is greatly appreciated.
    Best regards,
    Minami

    If you are interested, here is a complete solution.
    report zrich_0001.
    data: it001 type table of t001.
    data: xt001 type t001.
    data: iflatf type table of string.
    data: xflatf type string.
    data: filename type string.
    data: field_value type string.
    field-symbols: <fs>.
    * Selection Screen
    selection-screen begin of block b1 with frame title text-002 .
    parameters: p_file type localfile default
                'C:Test.txt'.
    selection-screen end of block b1.
    start-of-selection.
      select * into table it001 from t001.
      loop at it001 into xt001.
        do.
          assign component sy-index of structure xt001 to <fs>.
          if sy-subrc <> 0.
            exit.
          endif.
          concatenate '"' <fs> '"' into field_value.
          if sy-index = 1.
            xflatf = field_value.
          else.
            concatenate xflatf field_value into xflatf separated by space.
          endif.
        enddo.
          append xflatf to iflatf.
      endloop.
      filename = p_file.
      call method cl_gui_frontend_services=>gui_download
             exporting
                  filename                = filename
                  filetype                = 'ASC'
             changing
                  data_tab                = iflatf.
    Regard,
    Rich Heilman

  • How to give path at runtime in GUI_DOWNLOAD

    Hi experts,
    I have a below given parameter on the selection screen:
    SELECTION-SCREEN: BEGIN OF BLOCK b5 WITH FRAME TITLE text-005.
    PARAMETERS: p_path LIKE RLGRAP-FILENAME modif id ZF1.
    SELECTION-SCREEN: END OF BLOCK b5.
    I am using the FM GUI_DOWNLOAD in my report.
    My requirement is that I need to pass the path given
    in p_path in this FM, i.e. I need not hard code the path in the
    FM parameter 'filename', but need to pass it at runtime.
    How can this functionality be achieved?
    Thanks,
    Ajay.

    Hi Ajay,
    check the below code i hope it will help you.
    SELECTION-SCREEN BEGIN OF BLOCK upfile WITH FRAME TITLE text-009.
    PARAMETERS: p_file     TYPE rlgrap-filename OBLIGATORY.       "Source  file name
    SELECTION-SCREEN END OF BLOCK upfile.
    *AT SELECTION-SCREEN
    Browse source file name
      AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
       PERFORM f_browse_file CHANGING p_file.
    FORM f_browse_file CHANGING p_p_file.
      DATA: it_l_filetab  TYPE filetable,
            wa_l_filetab  TYPE file_table,
            l_rc          TYPE i.
      CLEAR it_l_filetab.
    Browsing file
      CALL METHOD cl_gui_frontend_services=>file_open_dialog
        CHANGING
          file_table              = it_l_filetab
          rc                      = l_rc
        EXCEPTIONS
          file_open_dialog_failed = 1
          cntl_error              = 2
          error_no_gui            = 3
          not_supported_by_gui    = 4
          OTHERS                  = 5.
      IF sy-subrc IS NOT INITIAL.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ELSE.
        READ TABLE it_l_filetab INTO wa_l_filetab INDEX 1.
        IF sy-subrc IS INITIAL.
          p_p_file = wa_l_filetab-filename.
        ENDIF. " sy-subrc  Read
      ENDIF. " sy-subrc-call method
    ENDFORM.                    " f_browse_file
    START-OF-SELECTION.
    *Upload File
      PERFORM f110_upload_from_pc.
    FORM f110_upload_from_pc .
    DATA :  lv_file TYPE rlgrap-filename.
      DATA :  l_files TYPE string,
              l_ret   TYPE abap_bool.
      CLEAR  it_file_data.
      lv_file = p_file.
      l_files = p_file.
      CONSTANTS: c_tab    TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
      CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename                = l_files
          filetype                = 'ASC'
          has_field_separator     = c_tab
         codepage                = '6300'
         READ_BY_LINE            = 'X'
         replacement             = '-'
        TABLES
          data_tab                = i_tab_order
        EXCEPTIONS
          file_open_error         = 1
          file_read_error         = 2
          no_batch                = 3
          gui_refuse_filetransfer = 4
          invalid_type            = 5
          no_authority            = 6
          unknown_error           = 7
          bad_data_format         = 8
          header_not_allowed      = 9
          separator_not_allowed   = 10
          header_too_long         = 11
          unknown_dp_error        = 12
          access_denied           = 13
          dp_out_of_memory        = 14
          disk_full               = 15
          dp_timeout              = 16
          OTHERS                  = 17.
      IF sy-subrc <> 0.
        MESSAGE 'Error in upload'(008) TYPE 'I' DISPLAY LIKE 'E' .
        LEAVE TO LIST-PROCESSING.
      ENDIF.
    ENDFORM.                    " f_UPLOAD_FROM_PC
    I hopr this will helps you
    Regards,
    Tarun
    Edited by: Devalla T Kumar on Dec 29, 2009 9:54 AM

  • Getting error COMPUTE_INT_TIMES_OVERFLOW in GUI_DOWNLOAD

    Hi Experts,
    I am using server SRM 7.0
    and support package is  SAP_ABA     701     0007     SAPKA70107     Cross-Application Component
    I am getting dump in GUI_DOWNLOAD Function module
    This is ST22
    In the current program "SAPLSFES", multiplying the numbers 21550 and
    131070 (using the operation '*' or 'MULTIPLY') resulted in a value
    greater than 2147483647 or smaller than -2147483648. This
    results in a whole number overflow.
    Runtime Errors         COMPUTE_INT_TIMES_OVERFLOW
    Except.                CX_SY_ARITHMETIC_OVERFLOW
    Trigger Location of Exception
        Program                                 SAPLSFES
        Include                                 LSFESU17
        Row                                     517
        Module type                             (FORM)
        Module Name                             MASS_DOWNLOAD
    and its coming because of this
      514   if prc_filetype = 'BIN' and bin_filesize ne 0.
      515     tablesize = bin_filesize.
      516   else.
    >>>>>     tablesize = lines * record_length.
      518     binfilesize_lcl = tablesize.
      519   endif.
    Please tell me is there any Patch or note for it .
    Thanks & Regards
    Prashant Guta

    Hi Rogério Ribeiro,
    Thanks for Reply .
    I can not reduce file because  i am downloading Web Dynpro component by the download prgram given in Sap Link.
    so Web Dynpro component is big thats why prblem is coming .
    Thanks & Regards
    Prashant Gupta

  • How to use '|' delimited as seprator in GUI_DOWNLOAD ? Plz suggest me ,,

    how to use '|' delimited as seprator in GUI_DOWNLOAD ? Plz suggest me ,,
    i want the output should be seprated by '|' delimited when i download the file.

    Hi,
    We will pass the seperator to the WRITE_FIELD_SEPARATOR parameter as
    CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
    filename = v_file
    write_field_separator = '|'
    TABLES
    data_tab = itab[] . "Our internal talbe filled with data
    Re: Why Function GUI_DOWNLOAD can create XML file but not a flat file?
    Award points if useful
    Thanks,
    Ravee...

  • Actions - How to replace GUI_DOWNLOAD and CL_GUI_FRONTEND_SERVICES= FILE_SA

    Hi,
    In sap gui was trigered action whih is using smartform and then output was being downloaded and saved as using:
    CALL FUNCTION 'GUI_DOWNLOAD' - to
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
    After the ubgrade this action is not working in web ui.
    Anyone knows how to change this to work in web ui?
    Thank you in advance

    Hi Tanja Lukovic 
    Pls check the settings defined in the SPRO path CRM->Basic settings->actions under this select your relevant application area and check whether any start/schedule conditions are not met (check in conditions) , apart from this reason there could be other reasons also pls check the trigger  processing type (it should be smart form print).
    if the actions are already created , you can change actions and conditions.
    Thanks & Regards
    Raj

  • Looking for some assistancte in GUI_DOWNLOAD

    Hi there,
    See I have this exercise I have to do here. Basically I have to create a program that will download the contects of SBOOK to my pc. I have to use GUI_DOWNLOAD in this exercise. Also, the user will have to input the path and file name of the file to be downloaded to. I have place appropriate error message on the screen as well but I'm not sure how to do this.Being relatively new to this, I tried looking for some samples and this is what I came up so far.
    REPORT  ZISTANZS_TRNG_EX9C.
    TABLES: SBOOK.
    PARAMETERS: FILEINP(30) DEFAULT 'c:\TEMP\wee.txt' OBLIGATORY.
    DATA: BEGIN OF ITAB OCCURS 100.
          INCLUDE STRUCTURE SBOOK.
    DATA: END OF ITAB.
    CALL FUNCTION 'GUI_DOWNLOAD'
         EXPORTING
             FILENAME            = FILEINP
             FILETYPE            = 'ASC'
             write_field_separator = 'X'
         TABLES
             DATA_TAB            = ITAB
         EXCEPTIONS
             FILE_OPEN_ERROR     = 1
             FILE_WRITE_ERROR    = 2
             OTHERS              = 3.
    Unfortunately, it doesn't work though. It keeps saying that my FILENAME is not the same data type as FILEINP? I'm asking for some assistance in how this can be properly solved? Any help would be appreciated /

    Hi,
    Please refer the code below:
    * File download, uses older techniques but achieves a perfectly
    * acceptable solution which also allows the user to append data to
    * an existing file.
      PARAMETERS: p_file like rlgrap-filename.
    * Internal table to store export data
      DATA: begin of it_excelfile occurs 0,
       row(500) type c,
       end of it_excelfile.
      DATA: rc TYPE sy-ucomm,
            ld_answer TYPE c.
      CALL FUNCTION 'WS_QUERY'
           EXPORTING
                query    = 'FE'  "File Exist?
                filename = p_file
           IMPORTING
                return   = rc.
      IF rc NE 0.                       "If File alread exists
        CALL FUNCTION 'POPUP_TO_CONFIRM'
          EXPORTING
    *          TITLEBAR              = ' '
    *          DIAGNOSE_OBJECT       = ' '
               text_question         = 'File Already exists!!'
               text_button_1         = 'Replace'
    *          ICON_BUTTON_1         = ' '
               text_button_2         = 'New name'
    *          ICON_BUTTON_2         = ' '
    *          DEFAULT_BUTTON        = '1'
    *          DISPLAY_CANCEL_BUTTON = 'X'
    *          USERDEFINED_F1_HELP   = ' '
    *          START_COLUMN          = 25
    *          START_ROW             = 6
    *          POPUP_TYPE            =
          IMPORTING
               answer                = ld_answer
    *     TABLES
    *         PARAMETER              =
          EXCEPTIONS
              text_not_found         = 1
              OTHERS                 = 2.
    * Option 1: Overwrite
        IF ld_answer EQ '1'.
          CALL FUNCTION 'GUI_DOWNLOAD'
            EXPORTING
    *            BIN_FILESIZE            =
                 filename                = p_file        "File Name
                 filetype                = 'ASC'
    *       IMPORTING
    *            FILELENGTH              =
            TABLES
                data_tab                = it_excelfile   "Data table
            EXCEPTIONS
                file_write_error        = 1
                no_batch                = 2
                gui_refuse_filetransfer = 3
                invalid_type            = 4
                OTHERS                  = 5.
          IF sy-subrc <> 0.
            MESSAGE i003(zp) WITH
                     'There was an error during Excel file creation'(200).
            exit. "Causes short dump if removed and excel document was open
          ENDIF.
    * Option 2: New name.
        ELSEIF ld_answer EQ '2'.
          CALL FUNCTION 'DOWNLOAD'
            EXPORTING
                 filename            = p_file          "File name
                 filetype            = 'ASC'           "File type
    *             col_select          = 'X'            "COL_SELECT
    *             col_selectmask      = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
    *                                                   "COL_SELECTMASK
                 filetype_no_show    = 'X'     "Show file type selection?
    *       IMPORTING
    *             act_filename        = filename_dat
            TABLES
                 data_tab            = it_excelfile    "Data table
    *            fieldnames          =
            EXCEPTIONS
                 file_open_error     = 01
                 file_write_error    = 02
                 invalid_filesize    = 03
                 invalid_table_width = 04
                 invalid_type        = 05
                 no_batch            = 06
                 unknown_error       = 07.
        ENDIF.
      ELSE.                               "File does not alread exist.
        CALL FUNCTION 'GUI_DOWNLOAD'
          EXPORTING
    *          BIN_FILESIZE            =
               filename                = p_file         "File name
               filetype                = 'ASC'          "File type
    *     IMPORTING
    *          FILELENGTH              =
          TABLES
               data_tab                = it_excelfile   "Data table
          EXCEPTIONS
               file_write_error        = 1
               no_batch                = 2
               gui_refuse_filetransfer = 3
               invalid_type            = 4
               OTHERS                  = 5.
        IF sy-subrc <> 0.
          MESSAGE i003(zp) WITH
                   'There was an error during Excel file creation'(200).
          exit. "Causes short dump if removed and excel document was open
        ENDIF.
      ENDIF.
    Thanks,
    Sriram Ponna.

  • Use 3 internal table in GUI_Download

    Hello expert,
    i have 3 internal table: gt_header, gt_body and gt_footer. how can i used all 3 in gui_download fm. here is my sample code:
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename              = gv_file_name
          filetype              = 'ASC'
        TABLES
          data_tab              = gt_header.
    here i can only pass one internal table.
    Help please?

    Hi Hassim,
    Maybe you can declare another internal table, with all fields is type C and length as you wanted.
    Loop those three itabs, append to this new itab. then call this FM download.
    regards,
    Archer

  • Coloring a line in 'GUI_DOWNLOAD'

    Hi all,
       Now i am doing one report. In that, I am downloading the output into Excel file using 'GUI_DOWNLOAD' FM. Now i want to color the first record of my excel. Can u guide me.
    Thanks in advance.
    Rajkumar P.

    Hi,
    Refer the below code,
    TYPE-POOLS ole2.
    DATA: wf_cell_from TYPE ole2_object,
          wf_cell_from1 TYPE ole2_object,
          wf_cell_to TYPE ole2_object,
          wf_cell_to1 TYPE ole2_object,
          wf_int TYPE ole2_object ,
          wf_excel TYPE ole2_object,       " Excel object
          wf_mapl TYPE ole2_object,        " list of workbooks
          wf_map TYPE ole2_object,         " workbook
          wf_worksheet TYPE ole2_object,   " Worksheet
          wf_cell TYPE ole2_object,        " Cell Range
          wf_cell1 TYPE ole2_object,
          wf_range TYPE ole2_object,       " Range of cells to be formatted
          wf_range2 TYPE ole2_object,
          wf_column1 TYPE ole2_object.     " Column to be Autofit
    DATA: wf_format TYPE ole2_object.
    DATA: BEGIN OF t_hex,
          l_tab TYPE x,
          END OF t_hex.
    DATA: wf_deli(1) TYPE c.            "delimiter
    TYPES: t_data1(1500) TYPE c,
           int_ty TYPE TABLE OF t_data1. "line type internal table
    *All the data was prepared as line type internal tables for faster
    *download
    DATA: int_matl TYPE int_ty ,
          int_matl1 TYPE int_ty ,
          wa_matl TYPE t_data1.
    TYPES: BEGIN OF ty_mara,
           matnr TYPE matnr,
           mtart TYPE mtart,
           matkl TYPE matkl,
           meins TYPE meins,
           END OF ty_mara.
    DATA: int_mara TYPE STANDARD TABLE OF ty_mara,
          wa_mara TYPE ty_mara.
    FIELD-SYMBOLS: <fs> .
    DATA: wc_sheets LIKE sy-index.  "no.of sheets
    DATA: it_tabemp TYPE filetable,
           gd_subrcemp TYPE i.
    CONSTANTS wl_c09(2) TYPE n VALUE 09.
    CLEAR wc_sheets.
    DEFINE ole_check_error.
      if &1 ne 0.
        message e001(zz) with &1.
        exit.
      endif.
    END-OF-DEFINITION.
    SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-001.
    PARAMETERS: p_file   LIKE rlgrap-filename.
    SELECTION-SCREEN END OF BLOCK block1.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
      REFRESH: it_tabemp.
      CALL METHOD cl_gui_frontend_services=>file_open_dialog
        EXPORTING
          window_title      = 'Select File'
          default_filename  = '*.xls'
          initial_directory = 'C:\'
          multiselection    = ' '  "No multiple selection
        CHANGING
          file_table        = it_tabemp
          rc                = gd_subrcemp.
      LOOP AT it_tabemp INTO p_file.
      ENDLOOP.
    START THE EXCEL APPLICATION
      CREATE OBJECT wf_excel 'EXCEL.APPLICATION'.
      PERFORM err_hdl.
    PUT EXCEL IN FRONT
      SET PROPERTY OF wf_excel  'VISIBLE' = 1.
      PERFORM err_hdl.
    INFORM USER OF THE CURRENT STATUS
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
        EXPORTING
          percentage = 0
          text       = text-i08
        EXCEPTIONS
          OTHERS     = 1.
    CREATE AN EXCEL WORKBOOK OBJECT
      CALL METHOD OF wf_excel 'WORKBOOKS' = wf_mapl.
      PERFORM err_hdl.
      CALL METHOD OF wf_mapl 'ADD' = wf_map.
      PERFORM err_hdl.
      PERFORM f_material_details.
      GET PROPERTY OF wf_excel 'ActiveSheet' = wf_map.
      GET PROPERTY OF wf_excel 'ActiveWorkbook' = wf_mapl.
      CALL FUNCTION 'FLUSH'
        EXCEPTIONS
          cntl_system_error = 1
          cntl_error        = 2
          OTHERS            = 3.
      IF sy-subrc = 0.
        CALL METHOD OF wf_map 'SAVEAS'
          EXPORTING #1 = p_file.
       #2 = 1.
      ENDIF.
      MESSAGE s001(zbhi) WITH 'Complete downloading'.
    CALL METHOD OF wf_mapl 'CLOSE'.
    CALL METHOD OF wf_excel 'QUIT'.
      FREE OBJECT wf_mapl.
      FREE OBJECT wf_map.
      FREE OBJECT wf_excel.
      MESSAGE s001(zbhi) WITH 'Complete downloading'.
    *&      Form  ERR_HDL
          text
    FORM err_hdl.
      IF sy-subrc <> 0.
        WRITE: / 'OLE ERROR: RETURN CODE ='(i10), sy-subrc.
        STOP.
      ENDIF.
    ENDFORM.                    "ERR_HDL
    *-- End of Program
    *&      Form  f_material_details
          text
    -->  p1        text
    <--  p2        text
    FORM f_material_details .
      DATA: lv_lines TYPE i.
    *Assign the Delimiter to field  symbol.
      ASSIGN wf_deli TO <fs> TYPE 'X'.
      t_hex-l_tab = wl_c09.
      <fs> = t_hex-l_tab.
      CLEAR int_matl.
      REFRESH int_matl.
      SELECT matnr
           mtart
           matkl
           meins
          FROM mara
          INTO CORRESPONDING FIELDS OF TABLE int_mara.
    *first the headings will be displayed  in the excel sheet
      CONCATENATE 'Material Number'
      'Material type'
      'Material Group'
      'Base Unit of Measure'
      INTO wa_matl
      SEPARATED BY wf_deli.
      APPEND wa_matl TO int_matl.
      LOOP AT int_mara INTO wa_mara.
        CONCATENATE wa_mara-matnr
                    wa_mara-mtart
                    wa_mara-matkl
                    wa_mara-meins
                    INTO wa_matl
                    SEPARATED BY wf_deli.
        APPEND wa_matl TO int_matl.
        CLEAR wa_matl.
      ENDLOOP.
    *Copyng thae same contents to another table to display in
    *new sheet
      MOVE int_matl TO int_matl1.
      wc_sheets = 1.
    *-- activating the worksheet and giving a  name to it
      CALL METHOD OF wf_excel 'WORKSHEETS' = wf_worksheet
        EXPORTING
        #1 = wc_sheets.
      CALL METHOD OF wf_worksheet 'ACTIVATE'.
      SET PROPERTY OF wf_worksheet 'NAME' = 'Material Details'.
    *--formatting the cells
      CALL METHOD OF wf_excel 'Cells' = wf_cell_from
        EXPORTING
        #1 = 1
        #2 = 1.
      DESCRIBE TABLE int_matl LINES lv_lines.
      CALL METHOD OF wf_excel 'Cells' = wf_cell_to
        EXPORTING
        #1 = lv_lines
        #2 = 1.
    *--range of cells to be formatted (in this case 1 to 4)
      CALL METHOD OF wf_excel 'Range' = wf_cell
        EXPORTING
        #1 = wf_cell_from
        #2 = wf_cell_to.
    *--formatting the cells
      CALL METHOD OF wf_excel 'Cells' = wf_cell_from1
        EXPORTING
        #1 = 1 "row
        #2 = 1. "column
      DESCRIBE TABLE int_matl LINES lv_lines.
      CALL METHOD OF wf_excel 'Cells' = wf_cell_to1
        EXPORTING
        #1 = 1
        #2 = 4.
      CALL METHOD OF wf_excel 'Range' = wf_cell1
        EXPORTING
        #1 = wf_cell_from1
        #2 = wf_cell_to1.
      SET PROPERTY OF wf_cell 'NumberFormat' = wf_format.
      CALL METHOD OF wf_cell1 'INTERIOR' = wf_int. "Setting the color from for range of cells
      SET PROPERTY OF wf_int 'ColorIndex' = 5.
      SET PROPERTY OF wf_int 'Pattern' = 1.
      DATA l_rc TYPE i.
    *DATA download into excel first sheet
      CALL METHOD cl_gui_frontend_services=>clipboard_export
        IMPORTING
          data                 = int_matl[]
        CHANGING
          rc                   = l_rc
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          OTHERS               = 4.
      CALL METHOD OF wf_worksheet 'Paste'.
      CALL METHOD OF wf_excel 'Columns' = wf_column1.
      CALL METHOD OF wf_column1 'Autofit'.
      FREE OBJECT wf_column1.
    ENDFORM.                    " f_material_details
    Regards,
    Manoj Kumar P

Maybe you are looking for