Downloding from internal table to excel

Hi All,
I am using ole concept to download data from internal table to excel because i want to fill few records with colors and few with bold etc.
But this ole concept is downloading to excel line by line and taking much time.
How can i improve the performance in this concept or is there any other concept please let me know.
i am using fallowng logic to download to excel.
*Generating the Excel report in the foreground
data: h_excel type ole2_object, " Excel object
h_mapl type ole2_object, " list of workbooks
h_map type ole2_object, " workbook
start Excel
create object h_excel 'EXCEL.APPLICATION'.
set property of h_excel 'Visible' = 1.
get list of workbooks, initially empty
call method of h_excel 'Workbooks' = h_mapl.
perform err_hdl.
add a new workbook
call method of h_mapl 'Add' = h_map.
perform err_hdl.
output column headings to active Excel sheet
perform fill_cell using 1 1 1 000 'Job Name'(001).
perform fill_cell using 1 2 1 000 'Variant'(002).
perform fill_cell using 1 3 1 000 'Description'(003).
perform fill_cell using 1 4 1 000 'Run Date'(004).
perform fill_cell using 1 5 1 000 'Run Time'(005).
perform fill_cell using 1 6 1 000 'Duration'(006).
perform fill_cell using 1 7 1 000 'Spool'(007).
perform fill_cell using 1 8 1 000 'Records Upl'(008).
perform fill_cell using 1 9 1 000 'Error'(009).
perform fill_cell using 1 10 1 000 'Total'(010).
perform fill_cell using 1 11 1 000 'Action'(011).
perform fill_cell using 1 12 1 000 'ReRun'(012).
loop at t_final.
copy datato active EXCEL sheet
h = sy-tabix + 1.
perform fill_cell using h 1 0 000 t_final-jobname.
perform fill_cell using h 2 0 000 t_final-variant.
perform fill_cell using h 3 0 000 t_final-description.
perform fill_cell using h 4 0 000 t_final-strtdate.
perform fill_cell using h 5 0 000 t_final-strttime.
perform fill_cell using h 6 0 000 t_final-duration.
perform fill_cell using h 7 0 000 t_final-listident.
perform fill_cell using h 8 0 000 t_final-rec_upl.
perform fill_cell using h 9 0 000 t_final-rec_err.
perform fill_cell using h 10 0 000 t_final-rec_tot.
if t_final-comment eq 'job did not run'.
perform fill_cell using h 11 0 200 t_final-comment.
elseif t_final-rec_err eq 0.
perform fill_cell using h 11 0 000 t_final-comment.
else.
perform fill_cell using h 11 0 200 t_final-comment.
endif.
perform fill_cell using h 12 0 000 t_final-rerun.
endloop.
CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
call method of h_excel 'Worksheets' = h_mapl." EXPORTIN G #1 = 2.
perform err_hdl.
add a new workbook
call method of h_mapl 'Add' = h_map exporting #1 = 2.
perform err_hdl.
tell user what is going on
set property of h_map 'NAME' = 'COPY'.
loop at t_final.
copy flights to active EXCEL sheet
h = sy-tabix + 1.
perform fill_cell using h 1 0 000 t_final-jobname.
perform fill_cell using h 2 0 000 t_final-variant.
perform fill_cell using h 3 0 000 t_final-description.
perform fill_cell using h 4 0 000 t_final-strtdate.
perform fill_cell using h 5 0 000 t_final-strttime.
perform fill_cell using h 6 0 000 t_final-duration.
perform fill_cell using h 7 0 000 t_final-listident.
perform fill_cell using h 8 0 000 t_final-rec_upl.
perform fill_cell using h 9 0 000 t_final-rec_err.
perform fill_cell using h 10 0 000 t_final-rec_tot.
if t_final-comment eq 'job did not run'.
perform fill_cell using h 11 0 200 t_final-comment.
elseif t_final-rec_err eq 0.
perform fill_cell using h 11 0 000 t_final-comment.
else.
perform fill_cell using h 11 0 200 t_final-comment.
endif.
perform fill_cell using h 12 0 000 t_final-rerun.
endloop.
free object h_excel.
perform err_hdl.
*& Form ERR_HDL
outputs OLE error if any *
form err_hdl.
if sy-subrc <> 0.
write: / 'Batch Job Automation Carried Out Succesfully'.
stop.
endif.
endform. " ERR_HDL .
FORM FILL_CELL *
sets cell at coordinates i,j to value val boldtype bold *
form fill_cell using i j bold col val.
call method of h_excel 'Cells' = h_zl exporting #1 = i #2 = j.
perform err_hdl.
set property of h_zl 'Value' = val .
perform err_hdl.
get property of h_zl 'Font' = h_f.
perform err_hdl.
set property of h_f 'Bold' = bold .
perform err_hdl.
set property of h_f 'Color' = col.
perform err_hdl.
endform. "FILL_CELL

Hi,
You are populating the Cells one by one from the internal table, and all of them are coloured and font is bold. the method is OK, but when the amount of data is huge - it is going to take a longer time. May be the performance will improve a little if you turn the visibility off.
I ll suggest you to use ALV_XXL_CALL, it can color the key columns, at the same time you can have colored headings - and the performance is good. It is the same function module called when you do a "Export to Excel" from an ALV grid. But you can compain about the Font characteristics - as this does not change the Font size etc.
Your code has got a lot of freedom as long as the formatting is concerned - for bigger data - i ll suggest you to use a WS_DOWNLOAD kind of a function module to get the data at once in the presentation server and then call Excel methods and do the formatting.

Similar Messages

  • Gui_download for transferring the data from internal table to excel sheet.

    hi all,
    i am using gui_download for transferring the data from internal table to excel sheet.
    I have a internal table with 3 columns col1,col2,col3 and I am getting the file at the specified path,but my problem is that,in the excel sheet(path specified) all the 3 columns values are printed in one column.Please help me.
    Thanks in advance.

    Hi Venkata,
    plz use FM 'SAP_CONVERT_TO_XLS_FORMAT' :
      call function 'SAP_CONVERT_TO_XLS_FORMAT'
        exporting
    *   I_FIELD_SEPERATOR          =
    *   I_LINE_HEADER              =
          i_filename                 = p_file
    *   I_APPL_KEEP                = ' '
        tables
          i_tab_sap_data             = t_mbew
    * CHANGING
    *   I_TAB_CONVERTED_DATA       =
    * EXCEPTIONS
    *   CONVERSION_FAILED          = 1
    *   OTHERS                     = 2
      if sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      endif.
    Hope this helps,
    Erwan

  • Download data from internal table to excel sheet from the background

    Hello Experts,
    I have written a code where the data is stored in the internal table . Now when i run this code in the background i want this internal table data to get downloaded in the excel sheet. The function module GUI_DOWNLAOD is not supported in the background. So is there any other function module that can be used or is there any other way to do this
    Thanks in advance

    Hi Aditya,
    I would provide you 2 advice:
    1. save the file on the application server as text file and the fileds in it separated by TAB,you can download the file whenever you want and open it with excel.
    2.generate excel files and send it to the email address whatever you specify in the selection-screen.
    Thanks,
    Sam

  • Downloading from Internal table to Excel

    Hi All,
    My requirement is download to Excel sheet, but in my internal table i have more than 95,000 record
    (max limit in Excel sheet is 65535).
    Please help me out by providing your solutions.
    note: here i know one solution, by splitting into two files but no.of records are mis-macthing.
            and one more issue when uploading the file we need to mention two file names.
            hope this is not suggesstable.
    Thanks in Advance
    Madhavi.

    hi,
        try this
    Parameters: P_file like RLGRAP-FILENAME.
    data : begin of int_head occurs 0,
    Filed1(20) type c,                     " Header Data
    end of int_head.
    data : begin of int_data occurs 0,
    Field1(20) type c,                     " Data
    Field2(20) type c,
    Field3(20) type c,
    Field4(20) type c,
    end of int_data.
    int_head-Filed1 = 'Sales Ord'.
    APPEND int_head.
    CLEAR  int_head.
    int_head-Filed1 = 'Sold-to-Party'.
    APPEND int_head.
    CLEAR  int_head.
    int_head-Filed1 = 'Purchase Ord'.
    APPEND int_head.
    CLEAR  int_head.
    int_head-Filed1 = 'Ship-to-Party'.
    APPEND int_head.
    CLEAR  int_head.
    int_data-field1 = '1JOHN'.
    int_data-field2 = '2TOM'.
    int_data-field3 = '3BRAD'.
    int_data-field4 = '4PETER'.
    Append int_data.
    Clear int_data.
    CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
    EXPORTING
    file_name = p_file " path offile where u need to download
    CREATE_PIVOT = 0
    DATA_SHEET_NAME = ' '
    PIVOT_SHEET_NAME = ' '
    PASSWORD = ' '
    PASSWORD_OPTION = 0
    TABLES
    PIVOT_FIELD_TAB =
    data_tab = int_data "internal table with data
    fieldnames = int_head "internal table with header
    EXCEPTIONS
    file_not_exist = 1
    filename_expected = 2
    communication_error = 3
    ole_object_method_error = 4
    ole_object_property_error = 5
    invalid_filename = 6
    invalid_pivot_fields = 7
    download_problem = 8
    OTHERS = 9
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

  • Download Internal table to Excel with different Tabs -  ole2_object

    Hi All,
    I am using  ole2_object to download the data from internal table to Excel file. As per different values in sorting key, data will be downloading in different tab in same Excel file.
    In my internal table one field is of character type and some times contains number as value.
    e.g.  itab-code = ‘000002’.
    While downloading to Excel, Excel consider this value as numeric and remove the leading zero.
    Any suggestions for how to set format property as ‘Text’ for this cell, will highly appreciated.
    Sample  code -
       data: gs_excel type ole2_object,
             gs_wbooklist type ole2_object,
             gs_application type ole2_object,
             gs_wbook type ole2_object,
             gs_activesheet type ole2_object,
             gs_sheets type ole2_object,
             gs_newsheet type ole2_object,
             gs_cell type ole2_object.
       create object gs_excel 'EXCEL.APPLICATION'.
       get property of gs_excel 'workbooks' = gs_wbooklist.
       get property of gs_wbooklist 'Application' = gs_application.
       set property of gs_application 'SheetsInNewWorkbook' = 1.
       call method of gs_wbooklist 'Add' = gs_wbook.
       get property of gs_application 'ActiveSheet' = gs_activesheet.
       set property of gs_activesheet 'Name' = datasheet_name.
      call method of gs_excel 'Cells' = gs_cell exporting #1 = v_row           
                                              #2 = v_col.
      set property of gs_cell 'value' = <f>.
    GET PROPERTY OF gs_cell 'Font' = gs_Font.
    SET PROPERTY OF gs_Font 'Bold' = 1 .
    Thanks.
    Regards,
    Meenakshi.

    Hello,
    Just concatenate ' infont of the fields, which you want to treat as a text.
    Like,
    itab-code = '00002'.
    concatenate '''' itab-code  into itab-code.
    modify itab.
    You can also set the text properties of the cell by,
      SET PROPERTY OF gs_cell 'NumberFormat' = '@' .
    but, it will remove the leading zeros and set the format as text.
    Regards,
    Naimesh

  • Downloding Internal Table to Excel Issue

    Hi guys,
    I want to know how can i download an internal table to excel, in which i have only one field declare as string. The values in the string are delimiter by # and i want to separated it in the excel in columns.
    Ej.
    DATA: BEGIN OF t_asc_file OCCURS 100,
            string TYPE string,
          END OF t_asc_file,
          it_asc_file LIKE t_asc_file OCCURS 0,
          wa_asc_file like line of it_asc_file.
    CONCATENATE wa_asc_file-string '#Importe#Mon.Soc.PA#Base Emisora %' INTO wa_asc_file-string.
      APPEND wa_asc_file TO it_asc_file.
      CALL METHOD cl_gui_frontend_services=>gui_download
        EXPORTING
    *      BIN_FILESIZE              = BIN_FILESIZE
          filename                = fullpath
          filetype                = 'ASC'
    *      APPEND                    = APPEND
          WRITE_FIELD_SEPARATOR = 'X' "CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
    *      HEADER                    = HEADER
    *      TRUNC_TRAILING_BLANKS     = TRUNC_TRAILING_BLANKS
    *      WRITE_LF                  = WRITE_LF
    *      COL_SELECT                = COL_SELECT
    *      COL_SELECT_MASK           = COL_SELECT_MASK
    *      DAT_MODE                  = DAT_MODE
    *      CONFIRM_OVERWRITE         = CONFIRM_OVERWRITE
    *      NO_AUTH_CHECK             = NO_AUTH_CHECK
    *      CODEPAGE                  = '1160' "CODEPAGE
    *      IGNORE_CERR               = IGNORE_CERR
    *      REPLACEMENT               = '#'
    *      WRITE_BOM                 = WRITE_BOM
    *      TRUNC_TRAILING_BLANKS_EOL = TRUNC_TRAILING_BLANKS_EOL
        IMPORTING
          filelength              = wa_filelength
        CHANGING
          data_tab                = it_asc_file
        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
          not_supported_by_gui    = 22
          error_no_gui            = 23
          OTHERS                  = 24.
    This code only downloads all the information into the first column of excel.
    Thanks in advance.
    Eric

    Hi Guys,
    I know that the GUI_DOWNLOAD automatically creates the fields in separated columns when you have the internal table already separated by the fields you need.
    In this case the fields that i need to download will vary from time to time, so i thought it was better to declare my internal table with one field as string. I debug the download option that has SAP in transaction KEU5, and it does work. This transaction has an internal table with one field declare as string, and each field is separated by "#".
    I don't see the reason why it works in the standard and not for me, but in order to save time, i will create generic fields to my internal table.
    Regards,
    Eric
    PD. If somebody knows how to resolve this problem would be highly apreciated.

  • Regarding downloading data into excel from internal table

    hi all ,
    i'm using the function module  SAP_CONVERT_TO_XLS_FORMAT to download data of internal table into excel . now i need to know . when user presses the button for downlading it should download after downloading if he again tries to download it in the same  should not allow him to download or  it should refresh the excel of the speecific path and then it should downlaod . please let me know how  make it.

    Hi,
    Use below FM
    call function 'MS_EXCEL_OLE_STANDARD_DAT'
    exporting
    file_name = p_file " path offile where u need to download
    CREATE_PIVOT = 0
    DATA_SHEET_NAME = ' '
    PIVOT_SHEET_NAME = ' '
    PASSWORD = ' '
    PASSWORD_OPTION = 0
    tables
    PIVOT_FIELD_TAB =
    data_tab = <dyn_table>  "internal table with data
    *fieldnames = int_head "internal table with header
    exceptions
    file_not_exist = 1
    filename_expected = 2
    communication_error = 3
    ole_object_method_error = 4
    ole_object_property_error = 5
    invalid_filename = 6
    invalid_pivot_fields = 7
    download_problem = 8
    others = 9
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    Regards,
    Prashant

  • How to download internal table to excel sheet

    I have a requirement to download nearly 8 to 10 internal tables to excel sheets(for each internal table one excel sheet) without displaying the diolog box showing open and save buttons.
    scenario :
      I will enter the path name like this -   C:\myfolder\Custom_programs.xls.
                                                            C:\myfolder\Custom_tables.xls.
                                                            (File name does not exit..it has to created inside the    
                                                                specified folder)
      in submit button I populate 2 internal tables say it1 and it2. then I need to move the tables contents to the path I have specified above.
    attach_file_to_response method is not working for the above reqt since it is showing the dialog box.
    Please provide a suitable solution...

    Please ignore all the responders that are stating that you can use GUI_DOWNLOAD from Web Dynpro ABAP.  As you found out, this absolutely will not work, since this function module and other download logic like it depends upon a connection to the SAPGUI. People posting to use the GUI_DOWNLOAD from WDA need to learn a little more about the architecture of WDA before they go posting incorrect repsonses in the forum. I have little tollerance for people posting outright incorrect information in the WDA Forum.
    What you want to do - download silent - is not easily done from WDA.  There are rules about how web applications must behave in a browser.  Normal HTML/JavaScript does not allow silent downloads for security reasons.  Obviously there are many untrustworthy websites on the internet that you wouldn't want to allow to directly access your local machine.  WDA must live within these same browser limitations.
    SAP has done some work using a Java Applet to get around some of these security issues.  This funcitonality comes in NetWeaver 7.01.  It is the AcfUpDownload UI element:
    http://help.sap.com/saphelp_nw70ehp1/helpdata/en/47/b9157c878a2d67e10000000a42189c/frameset.htm
    However it is designer for usage with the Content or KPro server - so even it might not meet your needs.

  • Function Module to Download Internal table in EXCEL

    Hi All,
    I need a Function Module to download the Internal table to Excel File.
    I Have used SAP_CONVERT_TO_XLS_FORMAT,
    but this function modules are using GUI_Download indirectly.
    I dont want to use GUI_DOWNLOAD as i am going to call this Function Module in Portal.
    So pls anybody has this type of function module.
    Thanks & Regards,
    Dhruv Shah

    Hello Dhruv.
    In Agreement with Deniz.
    It is required to Export the query as an excel file.
    [SAP HELP Library - Standard Reference - Exporting as a CSV File / MS Excel 2000 File|http://help.sap.com/saphelp_nw04/helpdata/en/d2/11a28fc26d4042a6d230a9783152f2/content.htm]
    [SDN - Reference - Error in "Export to Microsoft Excel" from Portal|Error in "Export to Microsoft Excel" from Portal;
    Hope this works out well.
    Good Luck & Regards.
    Harsh Dave

  • Downloading data from internal table to xls file leading zeros are not disp

    Hai abap gurus,
    when i am downloading data from internal table to excle file. some field values in a column are with leading zeros and some others dont have leading zeros.but in the output it is showing without leading zeros. then how to get with exact values.
    Ex:
    <b>ECC Code.</b>
    045234
      88567
    098456 
    but output is giving like this:
    45234
    88567
    98456
    how to get the actual values.....
    plz help me in this matter.

    Dear Kiran,
    Those field in the internal table having Leading Zeroes, make those fields' datatype as character.
    Then use the function module to download the content of the internal table to the excel file.
    Regards,
    Abir
    Don't forget to Reward Points  *

  • Download internal table to Excel sheet

    Hi,
    I am trying a sampole program to download an internal table to excel and am
    uisng the Fm GUI_DOWNLOAD for the same. But how do I ensure that each column
    of internal will be aligned as columns in the excel sheet to. I a trying to do
    that with a separator but I am not able to figure out.
    Below is my code.
    REPORT  z_excel_download.
    DATA : it_mara TYPE STANDARD TABLE OF mara WITH HEADER LINE.
    DATA : BEGIN OF it_file OCCURS 0,
           data(2000),
           END OF it_file.
    SELECT * FROM mara INTO TABLE it_mara UP TO 100 ROWS.
    LOOP AT it_mara.
      CONCATENATE it_mara-matnr
                  it_mara-ersda
                  it_mara-ernam
                  it_mara-pstat
                  it_mara-mtart
                  it_mara-mbrsh INTO it_file-data SEPARATED BY '/t'.
      APPEND it_file.
    ENDLOOP.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
      BIN_FILESIZE                    =
        filename                        = 'C:\Documents and Settings\XXXXXX\Desktop\test.xls'
      TABLES
        data_tab                        = it_file
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Thanks.

    Hi Varun,
    On SDN are plenty of post where you can find the answer to your problem.
    Please try the following code that I found here several years ago to resolve your problem.
    Regards,
    Eric
    REPORT Excel.
    TABLES:
      sflight.
    * header data................................
    DATA :
      header1 LIKE gxxlt_p-text VALUE 'Suresh',
      header2 LIKE gxxlt_p-text VALUE 'Excel sheet'.
    * Internal table for holding the SFLIGHT data
    DATA BEGIN OF t_sflight OCCURS 0.
            INCLUDE STRUCTURE sflight.
    DATA END   OF t_sflight.
    * Internal table for holding the horizontal key.
    DATA BEGIN OF  t_hkey OCCURS 0.
            INCLUDE STRUCTURE gxxlt_h.
    DATA END   OF t_hkey .
    * Internal table for holding the vertical key.
    DATA BEGIN OF t_vkey OCCURS 0.
            INCLUDE STRUCTURE gxxlt_v.
    DATA END   OF t_vkey .
    * Internal table for holding the online text....
    DATA BEGIN OF t_online OCCURS 0.
            INCLUDE STRUCTURE gxxlt_o.
    DATA END   OF t_online.
    * Internal table to hold print text.............
    DATA BEGIN OF t_print OCCURS 0.
            INCLUDE STRUCTURE gxxlt_p.
    DATA END   OF t_print.
    * Internal table to hold SEMA data..............
    DATA BEGIN OF t_sema OCCURS 0.
            INCLUDE STRUCTURE gxxlt_s.
    DATA END   OF t_sema.
    * Retreiving data from sflight.
    SELECT * FROM sflight
             INTO TABLE t_sflight.
    * Text which will be displayed online is declared here....
    t_online-line_no    = '1'.
    t_online-info_name  = 'Created by'.
    t_online-info_value = 'SURESH KUMAR PARVATHANENI'.
    APPEND t_online.
    * Text which will be printed out..........................
    t_print-hf     = 'H'.
    t_print-lcr    = 'L'.
    t_print-line_no = '1'.
    t_print-text   = 'This is the header'.
    APPEND t_print.
    t_print-hf     = 'F'.
    t_print-lcr    = 'C'.
    t_print-line_no = '1'.
    t_print-text   = 'This is the footer'.
    APPEND t_print.
    * Defining the vertical key columns.......
    t_vkey-col_no   = '1'.
    t_vkey-col_name = 'MANDT'.
    APPEND t_vkey.
    t_vkey-col_no   = '2'.
    t_vkey-col_name = 'CARRID'.
    APPEND t_vkey.
    t_vkey-col_no   = '3'.
    t_vkey-col_name = 'CONNID'.
    APPEND t_vkey.
    t_vkey-col_no   = '4'.
    t_vkey-col_name = 'FLDATE'.
    APPEND t_vkey.
    * Header text for the data columns................
    t_hkey-row_no = '1'.
    t_hkey-col_no = 1.
    t_hkey-col_name = 'PRICE'.
    APPEND t_hkey.
    t_hkey-col_no = 2.
    t_hkey-col_name = 'CURRENCY'.
    APPEND t_hkey.
    t_hkey-col_no = 3.
    t_hkey-col_name = 'PLANETYPE'.
    APPEND t_hkey.
    t_hkey-col_no = 4.
    t_hkey-col_name = 'SEATSMAX'.
    APPEND t_hkey.
    t_hkey-col_no = 5.
    t_hkey-col_name = 'SEATSOCC'.
    APPEND t_hkey.
    t_hkey-col_no = 6.
    t_hkey-col_name = 'PAYMENTSUM'.
    APPEND t_hkey.
    * populating the SEMA data..........................
    t_sema-col_no  = 1.
    t_sema-col_typ = 'STR'.
    t_sema-col_ops = 'DFT'.
    APPEND t_sema.
    t_sema-col_no = 2.
    APPEND t_sema.
    t_sema-col_no = 3.
    APPEND t_sema.
    t_sema-col_no = 4.
    APPEND t_sema.
    t_sema-col_no = 5.
    APPEND t_sema.
    t_sema-col_no = 6.
    APPEND t_sema.
    t_sema-col_no = 7.
    APPEND t_sema.
    t_sema-col_no = 8.
    APPEND t_sema.
    t_sema-col_no = 9.
    APPEND t_sema.
    t_sema-col_no = 10.
    t_sema-col_typ = 'NUM'.
    t_sema-col_ops = 'ADD'.
    APPEND t_sema.
    CALL FUNCTION 'XXL_FULL_API'
      EXPORTING
    *   DATA_ENDING_AT          = 54
    *   DATA_STARTING_AT        = 5
       filename                = 'TESTFILE'
       header_1                = header1
       header_2                = header2
       no_dialog               = 'X'
       no_start                = ' '
        n_att_cols              = 6
        n_hrz_keys              = 1
        n_vrt_keys              = 4
       sema_type               = 'X'
    *   SO_TITLE                = ' '
      TABLES
        data                    = t_sflight
        hkey                    = t_hkey
        online_text             = t_online
        print_text              = t_print
        sema                    = t_sema
        vkey                    = t_vkey
    EXCEPTIONS
       cancelled_by_user       = 1
       data_too_big            = 2
       dim_mismatch_data       = 3
       dim_mismatch_sema       = 4
       dim_mismatch_vkey       = 5
       error_in_hkey           = 6
       error_in_sema           = 7
       file_open_error         = 8
       file_write_error        = 9
       inv_data_range          = 10
       inv_winsys              = 11
       inv_xxl                 = 12
       OTHERS                  = 13
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

  • FM to download internal table to excel

    Hi all,
         I want to download my internal table into excel sheet. For this i am using FM
    <b>GUI_DOWNLOAD</b>. But in my internal table each record is of around <b>400</b> char. length. I think because of this the downloaded <b>content is not proper</b> i.e. in junk format. Please sugest some solution for this.
    Regards,
    Vinod.

    Hi Vinod,
    Try this program.Just copy and paste this program....
    REPORT zpck_download_to_excel .
    INCLUDE ole2incl.
    DATA: w_cell1 TYPE ole2_object,
               w_cell2 TYPE ole2_object.
    *--- Ole data Declarations
    DATA: h_excel TYPE ole2_object,      " Excel object
          h_mapl TYPE ole2_object,       " list of workbooks
          h_map TYPE ole2_object,        " workbook
          h_zl TYPE ole2_object,         " cell
          h_f TYPE ole2_object,          " font
          gs_interior TYPE ole2_object,  " Pattern
          worksheet TYPE ole2_object,
          h_cell TYPE ole2_object,
          h_cell1 TYPE ole2_object,
          range TYPE ole2_object,
          h_sheet2 TYPE ole2_object,
          h_sheet3 TYPE ole2_object,
          gs_font TYPE ole2_object,
          flg_stop(1) TYPE c.
    Internal table Declaration
    DATA : t_excel_t076m LIKE t076m OCCURS 0 WITH HEADER LINE.
    TYPES: data1(1500) TYPE c,
           ty TYPE TABLE OF data1.
    DATA: it TYPE ty WITH HEADER LINE,
          it_2 TYPE ty WITH HEADER LINE.
    DATA: rec TYPE sy-tfill,
          deli(1) TYPE c,
          l_amt(18) TYPE c.
    DATA: BEGIN OF hex,
            tab TYPE x,
          END OF hex.
    DATA: l_rc TYPE i.
    FIELD-SYMBOLS: <fs> .
    CONSTANTS cns_09(2) TYPE n VALUE 09.
    ASSIGN deli TO <fs> TYPE 'X'.
    hex-tab = cns_09.
    <fs> = hex-tab.
    DATA gv_sheet_name(20) TYPE c .
    M A C R O Declaration
    DEFINE ole_check_error.
      if &1 ne 0.
        message e002(zz) with &1.
        exit.
      endif.
    END-OF-DEFINITION.
    Fetching Data
    SELECT * FROM t076m INTO TABLE t_excel_t076m.
    LOOP AT t_excel_t076m.
      CONCATENATE
              t_excel_t076m-parart
              t_excel_t076m-konto
              t_excel_t076m-mwart
              t_excel_t076m-mwsatz
              t_excel_t076m-land1
              t_excel_t076m-mwskz
              INTO it
              SEPARATED BY deli.
      APPEND it.
      CLEAR it.
    ENDLOOP.
    IF h_excel-header = space OR h_excel-handle = -1.
    start Excel
      CREATE OBJECT h_excel 'EXCEL.APPLICATION'.
    ENDIF.
    *--- get list of workbooks, initially empty
    CALL METHOD OF h_excel 'Workbooks' = h_mapl.
    SET PROPERTY OF h_excel 'Visible' = 1.
    add a new workbook
    CALL METHOD OF h_mapl 'Add' = h_map.
    Name of the T076
    gv_sheet_name = 'T076M'.
    GET PROPERTY OF h_excel 'ACTIVESHEET' = worksheet.
    SET PROPERTY OF worksheet 'Name' = gv_sheet_name .
    CALL METHOD cl_gui_frontend_services=>clipboard_export
      IMPORTING
        data = it[]
      CHANGING
        rc = l_rc
      EXCEPTIONS
        cntl_error = 1
        error_no_gui = 2
        OTHERS = 4.
    Get the First row and col
    CALL METHOD OF h_excel 'Cells' = w_cell1
      EXPORTING
        #1 = 1
        #2 = 1.
    Get the 255 row and col
    CALL METHOD OF h_excel 'Cells' = w_cell2
      EXPORTING
        #1 = 5000
        #2 = 6.
    Select the Data
    CALL METHOD OF h_excel 'Range' = range
      EXPORTING
        #1 = w_cell1
        #2 = w_cell2.
    CALL METHOD OF range 'Select'.
    CALL METHOD OF worksheet 'Paste'.
    *--- disconnect from Excel
    FREE OBJECT h_zl.
    FREE OBJECT h_mapl.
    FREE OBJECT h_map.
    FREE OBJECT h_excel.
    Hope it helps you.
    Reward points if helpful.
    Regards,
    Chitra.

  • Download data from internal table to flat file.

    I need to download the data from Internal table to Flat file. can any one suggest how to do it? i suppose WS_Download OR GUI_DOWNLOAD.
    but if it is please guide me how to use this.
    is thre any other F.M. please provide the information.
    Thanks in advance

    Hi,
    Try this,
    * 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.
    Regards,
    Raghav

  • Conversion of internal table into excel file format &put it on app server

    Hi,
    My requirement is to convert the internal table into excel file format and I have to store it on application server so that administrator can send the file thr e-mail attachment.
    So, please let me know how to convert the records of internal table and store it on application server in Excel file format.
    TIA,
    Nitin

    Hi,
      Use FM GUI_DOWNLOAD to download the data from inernal table to excel sheet.
    Then Using tcode CG3Z u can transfer file to application server.
    *&      Form  sub_download
          text
    -->  p1        text
    <--  p2        text
    FORM sub_download.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
        BIN_FILESIZE                    =
          filename                        = p_path
         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_final
        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.                    " sub_download
    Otherwise use OPEN DATASET and TRANSFER statement to download data from internal table to direct application server
    Regards,
    Prashant

  • How to download leading zeros from internal table to XL file

    Hi,
    i am dowanloading data from interna table to XL file using GUI_DOWNLOAD FM. i want download the leading zeros  also into xl file
    EX: 012345
    at present only "12345" is down loading into XL file. But i want "012345" into XL file.
    Please help me.

    Hi,
    Can you try with DBF format(Pass FILETYPE = 'DBF'? I remember that in this format data will be downloaded in database storage format. Just check and update if it works!!!
    This is what FM documentation says.
    'DBF' :
    The data is downloaded in dBase format. With this format, the data types are stored as well, For this reason, import problems can be avoided - for example, problems with Microsoft Excel. In particular, you can avoid problems with the interpretation of numeric values.
    Thanks,
    Vinod.

Maybe you are looking for

  • HP LaserJet M1536dnf cannot connect to internet but we are able to print wirelessly.

    I connected our HP LaserJet M1536dnf MFP via USB to our Aiport Express...  I was able locate and add it using the Print & Scan function in System Tools (and I am able to print wirelessly) but we cannot scan from our computers or use AirPrint. I pulle

  • Network shares not showing in the sidebar

    Since ugrading our clients Macs to Lion, any network shares that are managed using workgroup manager are no longer showing up in the users sidebar, and if I try to drag the share to the sidebar it stays for a second then disappears ( the sidebar pref

  • Pricing conditions

    Pricing conditions In my pricing procedure 1. Sales revenue            100000 2. Fright                             500 (Accruals) 3. Insurance                     1000 (Accruals) 4. Other expanses              200 (Accruals) Total                   

  • Payload to receiver file adapter

    Hi guys, I have a scenario where I receive a message from SAP ERP via Proxy with a SOAP attachment. The message contains data about where on a file share the file shall be placed, and the attachment contains the PDF file to be placed. As far as I kno

  • Getting (error code -6584) when starting time machine

    Hello, I have an early 2011 mbp running Lion. I tried this morning to start time machine and got the error described above. I have access to my time capsule but the program will not start. This is the first time I start time machine since installing