Download to Excel Function in ALV

Hai Friends,
I am using the following methods to download the report to an Excel Sheet from ALV.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
CALL FUNCTION 'GUI_DOWNLOAD'
The report is downloaded to Excel but the Column names are not displayed. It is displaying as F1, F2, F3..................
How can i solve this?.

Hi,
    Please check with the sample code below:
*"Excel sheet header
    CLEAR e_excel.
    MOVE text-001 TO e_excel-var1.
    MOVE text-002 TO e_excel-var2.
    APPEND e_excel TO t_excel.
    CLEAR e_excel.
    UNASSIGN <fs_t_final>.
    REFRESH t_excel.
    LOOP AT t_final
    ASSIGNING <fs_t_final>.
      CHECK <fs_t_final> IS ASSIGNED.
*"Data continued after the header part
        MOVE <fs_t_final>-var1 TO e_excel-var1.
        MOVE <fs_t_final>-var2 TO e_excel-var2.
        APPEND e_excel TO t_excel.
        CLEAR e_excel.
data: w_savetitle TYPE string,
        w_filname  TYPE string,
        w_filename TYPE string,
        w_path      TYPE string,
        w_fpath      TYPE string.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
      EXPORTING
        window_title         = w_savetitle
      CHANGING
        filename             = w_filname
        path                 = w_path
        fullpath             = w_fpath
      EXCEPTIONS
        cntl_error           = 1
        error_no_gui         = 2
        not_supported_by_gui = 3
        OTHERS               = 4.
CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                = w_filename
        filetype                = ASC
        write_field_separator   =
        codepage                =
      TABLES
        data_tab                = t_excel
      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.

Similar Messages

  • Download to Excel" function cuts off leading zeros in string

    When a text column contains leading zeros for example "000250" the download to Excel stores the string as "250" in the spreadsheet
    I am unable to find a log about this
    thanks Muthanna

    1) Click on the fx button of the column in question. Enter this:
    '<span style="display:none">&nbsp</span>' ||  columnname Between the double quotes, type display:none
    2) Click on the Data Format tab and change the type to HTML.
    Edited by: David_T on Sep 14, 2010 8:25 AM
    (Edited to make the instructions clearer.)
    Edited by: David_T on Sep 14, 2010 9:54 AM

  • Cuts off leading zeros in a report column when "Download to Excel" function

    Hello
    When a text column contains leading zeros for example "000250" the download to Excel stores the string as "250" in the spreadsheet. I am using a column which is a string.(varchar)
    Can somebody suggest me , how to go ahead with it
    Thanks
    Edited by: user647228 on Sep 11, 2008 1:40 PM
    Edited by: user647228 on Sep 11, 2008 1:42 PM

    (To Vins) Actually, concatenating a space doesn't do it. When the file is downloaded into Excel, the leading space is ignored and it the leading zeroes are still trimmed.
    To user647228: A non-space character needs to be concatenated. Regarding what character to append, I would give the following consideration: If the users are content with seeing an added character to the "number," you can append say an underscore "_" and Excel will download the number properly. It's fairly unobtrusive and can be "visually ignored."
    If the end user insists on gettin rid of the extra character once the file is downloaded, I would append a character that is rarely, if not never, used in the report. (This ensures or mitigates replacing other instances of the character.) Then you can do a Replace All in Excel to replace the extra character with a single apostrophe. The single apostrophe will be interpreted by Excel to mean "text" and the appearance will change to exactly what is desired.
    Note: Replacing the extraneous character with a space for example, will result in the leading zeroes being again lopped off by Excel...

  • Downloading to Excel Sheet from ALV display

    Hi Friends,
    Here i am displaying data in ALV grid. i want to download data to excel file . My data is stored in a field symbol.Could you please tell me how to download this? Currently i am trying with
    CALL FUNCTION 'OLE_SERVER_CHECK'
    CALL FUNCTION 'XXL_SIMPLE_API'
    But i am not getting the result.
    Thanks.

    Download a report to excel with format (border, color cell, etc)
    Try this program...
    Code:
    REPORT ZTEST NO STANDARD PAGE HEADING.
    this report demonstrates how to send some ABAP data to an
    EXCEL sheet using OLE automation.
    INCLUDE OLE2INCL.
    handles for OLE objects
    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
    TABLES: SPFLI.
    DATA  H TYPE I.
    table of flights
    DATA: IT_SPFLI LIKE SPFLI OCCURS 10 WITH HEADER LINE.
    *&   Event START-OF-SELECTION
    START-OF-SELECTION.
    read flights
      SELECT * FROM SPFLI INTO TABLE IT_SPFLI UP TO 10 ROWS.
    display header
      ULINE (61).
      WRITE: /     SY-VLINE NO-GAP,
              (3)  'Flg'(001) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (4)  'Nr'(002) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (20) 'Von'(003) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (20) 'Nach'(004) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP,
              (8)  'Zeit'(005) COLOR COL_HEADING NO-GAP, SY-VLINE NO-GAP.
      ULINE /(61).
    display flights
      LOOP AT IT_SPFLI.
      WRITE: / SY-VLINE NO-GAP,
               IT_SPFLI-CARRID COLOR COL_KEY NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CONNID COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CITYFROM COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-CITYTO COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP,
               IT_SPFLI-DEPTIME COLOR COL_NORMAL NO-GAP, SY-VLINE NO-GAP.
      ENDLOOP.
      ULINE /(61).
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-007
           EXCEPTIONS
                OTHERS     = 1.
    start Excel
      CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
    PERFORM ERR_HDL.
      SET PROPERTY OF H_EXCEL  'Visible' = 1.
    CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING #1 = 'c:\kis_excel.xls'
    PERFORM ERR_HDL.
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-008
           EXCEPTIONS
                OTHERS     = 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.
    tell user what is going on
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-009
           EXCEPTIONS
                OTHERS     = 1.
    output column headings to active Excel sheet
      PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
      PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
      PERFORM FILL_CELL USING 1 3 1 'Von'(003).
      PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
      PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
      LOOP AT IT_SPFLI.
    copy flights to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
        PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
        PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
        PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
        PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
      ENDLOOP.
    changes by Kishore  - start
    CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
      CALL METHOD OF H_EXCEL 'Worksheets' = H_MAPL." EXPORTING #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'.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
         EXPORTING
              PERCENTAGE = 0
               TEXT       = TEXT-009
           EXCEPTIONS
                OTHERS     = 1.
    output column headings to active Excel sheet
      PERFORM FILL_CELL USING 1 1 1 'Flug'(001).
      PERFORM FILL_CELL USING 1 2 0 'Nr'(002).
      PERFORM FILL_CELL USING 1 3 1 'Von'(003).
      PERFORM FILL_CELL USING 1 4 1 'Nach'(004).
      PERFORM FILL_CELL USING 1 5 1 'Zeit'(005).
      LOOP AT IT_SPFLI.
    copy flights to active EXCEL sheet
        H = SY-TABIX + 1.
        PERFORM FILL_CELL USING H 1 0 IT_SPFLI-CARRID.
        PERFORM FILL_CELL USING H 2 0 IT_SPFLI-CONNID.
        PERFORM FILL_CELL USING H 3 0 IT_SPFLI-CITYFROM.
        PERFORM FILL_CELL USING H 4 0 IT_SPFLI-CITYTO.
        PERFORM FILL_CELL USING H 5 0 IT_SPFLI-DEPTIME.
      ENDLOOP.
    changes by Kishore  - end
    disconnect from Excel
         CALL METHOD OF H_EXCEL 'FILESAVEAS' EXPORTING  #1 = 'C:\SKV.XLS'.
      FREE OBJECT H_EXCEL.
      PERFORM ERR_HDL.
          FORM FILL_CELL                                                *
          sets cell at coordinates i,j to value val boldtype bold       *
    FORM FILL_CELL USING I J BOLD 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.
    ENDFORM.
    *&      Form  ERR_HDL
          outputs OLE error if any                                       *
    -->  p1        text
    <--  p2        text
    FORM ERR_HDL.
    IF SY-SUBRC <> 0.
      WRITE: / 'Fehler bei OLE-Automation:'(010), SY-SUBRC.
      STOP.
    ENDIF.
    ENDFORM.                    " ERR_HDL
    Regards,
    Pavan

  • Download to Excel file from ALV Grid

    Hi,
    I'm having a problem in downloading ALV Grid to excel file. The problem are the numbers are not in float format. I want them all in float format. Numbers in thousands are formatted with comma and decimals but numbers less than thousands are not in decimals.
    Ex:
    5 should be 5.00.
    In ALV, this number is being displayed as 5.00 but when downloaded it displayed as 5 only.

    Did you mention the INTTYPE and Decimals in the fieldcatalog for those fields.
    INTTYPE = 'P'.
    DECIMALS_OUT = '3'.
    try this..
    also
    use the Option
    short cut CTRLSHFTF9 option
    Local File->Spreadsheet->  and save it to excel file.

  • Download to excel sheet from ALV Grid report

    Hi,
    I need to download 3 lakhs of data to excel sheet but the constraint is that excel is having max limit of 65000 line items.
    So i need to know the way in which i can create more than one sheet in excel while downloading so that each sheet can hold upto 65000 line items.
    i need to create atleast 6 sheets in excel while downloading from report.
    please help.

    Hi,
    While downloading the data, it will prompt you save the list in file - Uncoverted, Spreadsheet, Rich text format, HTML format, Copy to Clipboard.
    Why don't you try using Uncoverted format and give extension as .txt file.
    So that you can download all 3 lacs of records.
    Even if you use any FM, it will indirectly use excel for downloading and it will have restriction of having 65000 records only.
    Thanks,
    Sriram Ponna.

  • Field value is truncated while downloading to excel sheet from ALV report

    Hi All,
    I developed ALV report and displaying output.
    In that output i had a filed VBRP-PRODH filed.
    In the output it is coming correctly but while i click downlaod to excel the valus is truncted.
    for Example the value for VBRP-PRODH is 03322764170100201
    while downlaoding this one to excel it is showing 3322764170100200
    Any inputs please..
    Regards
    Jai

    Wrong forum..post in ABAP

  • Cant use Export to Excel functionality for ALV if I add a custom button

    Hi,
      I have added a custom button the the ALV toolbar by creating a GUI status and using the USER_COMMAND event. However. Now I dont the get the standard ALV toolbar with all the options for sorting, exporting to excel etc.
      Can someone show me how I can do both, add my own button to the toolbar as well as use ALV Grid toolbar. Currently the ALV grid standard toolbar has disappeared
    Thanks for reading

    Hello,
    I am not sure how you are creating your ALV report.  If you are using FM REUSE_ALV_GRID_DISPLAY there is a parameter callled I_CALLBACK_PF_STATUS .  Read the documentation for this field from the doc for the FM.  It tells you to copy a standard PF status from fucn group SLVC_FULLSCREEN and then add your new button to that staus.
    If you are using class CL_SALV_MODEL_BASE there is a method called set_screen_status that lets you do a similar thing - copy an existing PF status and add your button.
    Hope that helps
    Regards
    Greg Kern

  • ALV Report Error while downloading to Excel

    Hi All,
    when i downloading to Excel from a alv grid following message has been displayed.
    Template not found in BDS  - Layout: Template-
    Guid:
    please give me any solution to download the report to excel
    Thanks & Regards
    Ramu G

    Hi,
    Standard Function code for Download to Excel Icon used  '&VEXCEL'(Microsoft Excel) instead of '&XXL'(Spreadsheet...) it solved my problem.
    Thanks & Regards
    Ramu Ganji

  • Download-to-excel vs. web print to excel

    There is an old how-to guide about downloading web report to Excel and it worked fine. Now we are implementing the web print to Excel function. However, two concerns:
    1) what's the advantage of web print to excel over download to excel function?
    2) in web print to excel, the header is fine but the cells of rows are all aligned in first column vertically! I only imported the classes and used the HELP class but did not configure the XML tags.

    Using the old How to guide (2.0B) you will only download the data on the screen, if you had multiple pages it will not download any of those extra pages.
    The new Excel print is based on MS Office HTML, here you have more options for setting print options by default in the template, like page orientation, repeating column headers, paper size (legal, A4 etc..), report header etc... you can also have a print specific template using the device types.
    One more advantage over the 3.0B Excel download is if you use Table APIs for manipulating data it will be taken into account with the new soltuion. This also supports multiple data providers.
    Thanks.

  • Download To Excel in PL/SQL

    Hi,
    Through my PL/SQL code for Download To Excel functionality, If fetch record count is more than 2k then sometime I get below mentioned error:
    ORA-22288: file or LOB operation FILEOPEN failed
    No such file or directory ORA-06512: at "SYS.DBMS_LOB", line 805
    ORA-06512: at "NCPCORE.NCP_BRANCH_CAMPUS_REC_PKG", line 1799
    What could be the reason for the same?

    82MT wrote:
    Hi,
    Through my PL/SQL code for Download To Excel functionality, If fetch record count is more than 2k then sometime I get below mentioned error:
    ORA-22288: file or LOB operation FILEOPEN failed
    No such file or directory ORA-06512: at "SYS.DBMS_LOB", line 805
    ORA-06512: at "NCPCORE.NCP_BRANCH_CAMPUS_REC_PKG", line 1799
    What could be the reason for the same?
    bug in the code
    How do I ask a question on the forums?
    https://forums.oracle.com/message/9362002#9362002

  • Reg: ALV output download using excel option

    Hi Team,
    I  created  a report using ALV Function modules, I want to download in  Excel sheet the  output list. i am trying to download but i am not getting proper values. I am populating around 50 fileds.
    is there any settings for these download.
    <<removed by moderator>>
    Thanks & Regards,
    Mahendar patha.

    hi mahendra;
    use this step-by-step procedure it will help u a lot:
    Firstly export  the data to memory using the FM LIST_FROM_MEMORY.
    CALL FUNCTION 'LIST_FROM_MEMORY'
    TABLES
    listobject = t_listobject
    EXCEPTIONS
    not_found = 1
    OTHERS = 2.
    IF sy-subrc 0.
    MESSAGE e000(su) WITH text-001.
    ENDIF.
    then i converted it into ASCII using LIST_TO_ASCI,
    CALL FUNCTION 'LIST_TO_ASCI'
    TABLES
    listasci = t_xlstab
    listobject = t_listobject
    EXCEPTIONS
    empty_list = 1
    list_index_invalid = 2
    OTHERS = 3.
    IF sy-subrc NE 0.
    MESSAGE e003(yuksdbfzs).
    ENDIF.
    This gives the data in ASCII format separated by '|' and the header has '-', dashes. If you use this internal table directly without any proccesing in SO_NEW_DOCUMENT_ATT_SEND_API1, then you will not get a good excel sheet attachment. To overcome this limitation, i used cl_abap_char_utilities=>newline and cl_abap_char_utilities=>horizontal_tab to add horizontal and vertical tabs to the internal table, replacing all occurences of '|' with
    cl_abap_char_utilities=>horizontal_tab.
    Set the doc_type as 'XLS', create the body and header using the packing_list and pass the data to be downloaded to SO_NEW_DOCUMENT_ATT_SEND_API1 as contents_bin.
    This will create an excel attachment.
    Sample code for formatting the data for the attachment in excel format.
    u2022     Format the data for excel file download
    LOOP AT t_xlstab INTO wa_xlstab .
    DESCRIBE TABLE t_xlstab LINES lw_cnt.
    CLEAR lw_sytabix.
    lw_sytabix = sy-tabix.
    u2022     If not new line then replace '|' by tabs
    IF NOT wa_xlstab EQ cl_abap_char_utilities=>newline.
    REPLACE ALL OCCURRENCES OF '|' IN wa_xlstab
    WITH cl_abap_char_utilities=>horizontal_tab.
    MODIFY t_xlstab FROM wa_xlstab .
    CLEAR wa_xlstab.
    wa_xlstab = cl_abap_char_utilities=>newline.
    IF lw_cnt NE 0 .
    lw_sytabix = lw_sytabix + 1.
    u2022     Insert new line for the excel data
    INSERT wa_xlstab INTO t_xlstab INDEX lw_sytabix.
    lw_cnt = lw_cnt - 1.
    ENDIF.
    CLEAR wa_xlstab.
    ENDIF.
    ENDLOOP.
    Sample code for creating attachment and sending mail:
    FORM send_mail .
    u2022     Define the attachment format
    lw_doc_type = 'XLS'.
    u2022     Create the document which is to be sent
    lwa_doc_chng-obj_name = 'List'.
    lwa_doc_chng-obj_descr = w_subject. "Subject
    lwa_doc_chng-obj_langu = sy-langu.
    u2022     Fill the document data and get size of message
    LOOP AT t_message.
    lt_objtxt = t_message-line.
    APPEND lt_objtxt.
    ENDLOOP.
    DESCRIBE TABLE lt_objtxt LINES lw_tab_lines.
    IF lw_tab_lines GT 0.
    READ TABLE lt_objtxt INDEX lw_tab_lines.
    lwa_doc_chng-doc_size = ( lw_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt ).
    lwa_doc_chng-obj_langu = sy-langu.
    lwa_doc_chng-sensitivty = 'F'.
    ELSE.
    lwa_doc_chng-doc_size = 0.
    ENDIF.
    u2022     Fill Packing List For the body of e-mail
    lt_packing_list-head_start = 1.
    lt_packing_list-head_num = 0.
    lt_packing_list-body_start = 1.
    lt_packing_list-body_num = lw_tab_lines.
    lt_packing_list-doc_type = 'RAW'.
    APPEND lt_packing_list.
    u2022     Create the attachment (the list itself)
    DESCRIBE TABLE t_xlstab LINES lw_tab_lines.
    u2022     Fill the fields of the packing_list for creating the attachment:
    lt_packing_list-transf_bin = 'X'.
    lt_packing_list-head_start = 1.
    lt_packing_list-head_num = 0.
    lt_packing_list-body_start = 1.
    lt_packing_list-body_num = lw_tab_lines.
    lt_packing_list-doc_type = lw_doc_type.
    lt_packing_list-obj_name = 'Attach'.
    lt_packing_list-obj_descr = w_docdesc.
    lt_packing_list-doc_size = lw_tab_lines * 255.
    APPEND lt_packing_list.
    u2022     Fill the mail recipient list
    lt_reclist-rec_type = 'U'.
    LOOP AT t_recipient_list.
    lt_reclist-receiver = t_recipient_list-address.
    APPEND lt_reclist.
    ENDLOOP.
    u2022     Finally send E-Mail
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
    document_data = lwa_doc_chng
    put_in_outbox = 'X'
    commit_work = 'X'
    IMPORTING
    sent_to_all = lw_sent_to_all
    TABLES
    packing_list = lt_packing_list
    object_header = lt_objhead
    contents_bin = t_xlstab
    contents_txt = lt_objtxt
    receivers = lt_reclist
    EXCEPTIONS
    too_many_receivers = 1
    document_not_sent = 2
    document_type_not_exist = 3
    operation_no_authorization = 4
    parameter_error = 5
    x_error = 6
    enqueue_error = 7
    OTHERS = 8.
    Hope it will help you
    Regards
    Rahul sharma
    Edited by: RAHUL SHARMA on Nov 4, 2008 1:22 PM

  • Download to excel from alv grid

    I developed a alv report and I have one percentage field(say PER) in the grid.When I sum on that field PER then it comes in my formula basis.Suppose If I have 5 line items and all PER field have a value 2 then when I sum in PER column then it come 7 inseted of 10 becoze of my formula basis and it comes perfect.But my query is when I download to excel then it comes real value 10 insted of 7. here my formula basis sum which is 7 for all 5 line items is not comming. Can any body help me how will it come?
    Thanks,
    Rakesh

    Hi
    try this code----
    *&      Form  DOWNLOAD_EXCEL_TEMPLATE
          text
    -->  p1        text
    <--  p2        text
    FORM download_excel_template .
      TYPES: BEGIN OF lt_data,
                field1(20),
                field2(30),
                field3(20),
                field4(20),
                field5(20),
                field6(30),
                field7(15),
                field8(10),
                field9(10),
                field10(20),
                field11(20),
                field12(10),
                field13(20),
                field14(20),
              END OF lt_data.
      DATA: lv_file TYPE rlgrap-filename,
            li_data TYPE STANDARD TABLE OF lt_data,
            wa_data TYPE lt_data,
            lv_pathcheck type c,
            lv_file1 type string.
      wa_data-field1 = ''.
      APPEND wa_data TO li_data.
      REFRESH gi_header.
      wa_header-name = 'Company Code'.
      APPEND wa_header TO gi_header.
      wa_header-name = 'Main Asset Number'.
      APPEND wa_header TO gi_header.
      wa_header-name = 'Asset Sub Number'.
      APPEND wa_header TO gi_header.
      wa_header-name = 'Document Date'.
      APPEND wa_header TO gi_header.
      wa_header-name = 'Posting Date'.
      APPEND wa_header TO gi_header.
      wa_header-name = 'Asset Value Date'.
      APPEND wa_header TO gi_header.
      wa_header-name = 'Item Text'.
      APPEND wa_header TO gi_header.
      wa_header-name = 'Reference'.
      APPEND wa_header TO gi_header.
      wa_header-name = 'Allocation'.
      APPEND wa_header TO gi_header.
      wa_header-name = 'Amount Posted'.
      APPEND wa_header TO gi_header.
      wa_header-name = 'Percentage Rate'.
      APPEND wa_header TO gi_header.
      wa_header-name = 'Quantity'.
      APPEND wa_header TO gi_header.
      wa_header-name = 'Prior-Yr Quantity'.
      APPEND wa_header TO gi_header.
      wa_header-name = 'Curr-Yr Quantity'.
      APPEND wa_header TO gi_header.
      lv_file = gv_file.
      lv_file1 = gv_file.
      CALL METHOD cl_gui_frontend_services=>directory_exist
        EXPORTING
          directory            = lv_file1
        RECEIVING
          result               = lv_pathcheck
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          wrong_parameter      = 3
          not_supported_by_gui = 4
          OTHERS               = 5.
       FIND '.xls' IN lv_file IGNORING CASE.
      IF sy-subrc = 0.
        REPLACE '.XLS' IN lv_file WITH ' ' IGNORING CASE.
      ENDIF.
      FIND '.TXT' IN lv_file IGNORING CASE.
      IF sy-subrc = 0.
        REPLACE '.TXT' IN lv_file WITH ' ' IGNORING CASE.
      ENDIF.
      CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
        EXPORTING
          file_name                 = lv_file
          data_sheet_name           = 'DATA'
        TABLES
          data_tab                  = li_data
          fieldnames                = gi_header
        EXCEPTIONS
          file_not_exist            = 1
          filename_expected         = 2
          communication_error       = 3
          ole_object_method_error   = 4
          ole_object_property_error = 5
          invalid_pivot_fields      = 6
          download_problem          = 7
          OTHERS                    = 8.
      IF sy-subrc <> 0.
        MESSAGE ID gv_msgid TYPE 'E' NUMBER 002.
      ENDIF.
    ENDFORM.                    " DOWNLOAD_EXCEL_TEMPLATE
    regards,
    Prashant

  • ALV download to EXCEL -- probs with SAPGUI 6.40 and EXCEL 2007

    I have a method in an ALV grid which performs a dowload to excel
    Here's the method
    method download_to_excel.
    field-symbols:
           <fs0> type standard table,
           <fs1> type standard table.
        assign g_outtab1->* to <fs0>.
        assign g_fldcat1->* to <fs1>.
           call function  'LVC_TRANSFER_TO_KKBLO'
          exporting
            it_fieldcat_lvc   = <fs1>
        is_layout_lvc     = m_cl_variant->ms_layout
             is_tech_complete  = ' '
          importing
            es_layout_kkblo   = ls_layout
            et_fieldcat_kkblo = lt_fieldcat.
        loop at lt_fieldcat into lt_fieldcat_wa.
          clear lt_fieldcat_wa-tech_complete.
          if lt_fieldcat_wa-tabname is initial.
            lt_fieldcat_wa-tabname = '1'.
            modify lt_fieldcat from lt_fieldcat_wa.
          endif.
          l_tabname = lt_fieldcat_wa-tabname.
        endloop.
        call function 'ALV_XXL_CALL'
             exporting
                  i_tabname           = l_tabname
                  is_layout           = ls_layout
                  it_fieldcat         = lt_fieldcat
                  i_title             = sy-title
             tables
                  it_outtab           = <fs0>
             exceptions
                  fatal_error         = 1
                  no_display_possible = 2
                  others              = 3.
        if  sy-subrc <> 0.
          message id sy-msgid type 'S' number sy-msgno
                 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        endif.
    endmethod.
    Basically the method converts the GRID table I'm displaying into the format requred for FMOD ALV_XXL_CALL' -- the field catalog is slightly different but no big deal here.
    This works fine when downloading to  EXCEL 2003 but short dumps when trying to do the same thing for EXCEL 2007.
    Workstation is running Windows XP / SP2 build 2600 in both cases.
    Any fixes etc or should I stick with EXCEL 2003 until forced to upgrade.
    Cheers
    jimbo

    Hi all
    Seems the problem disappeared after applying the latest patch to SAP_GUI 6.40.
    I haven't tried SAP_GUI 7.0 yet.
    Thanks anyway
    Cheers
    jimbo

  • ALV  download to EXCEL  with column headings etc.

    Getting data from a grid to EXCEL can be done in "List" mode vis system==>save etc but it's not particularly user friendly and in any case if you are displaying a nice ALV why should the user have to switch into LIST mode anyway.
    Anyway here's a decent way to do it and it gives great formatted column headings etc etc.
    1) in the ON_TOOLBAR method add this code
    method ON_TOOLBAR.
    type-pools icon.
    CLEAR ls_toolbar.
    MOVE  0 TO ls_toolbar-butn_type.
        MOVE 'EXCEL' TO ls_toolbar-function.
        MOVE  space TO ls_toolbar-disabled.
        MOVE  icon_xxl TO ls_toolbar-icon.
        MOVE 'Excel' TO ls_toolbar-quickinfo.
        MOVE  'EXCEL' TO ls_toolbar-text.
        APPEND ls_toolbar TO e_object->mt_toolbar.
    2) In the ON_USER_COMMAND method add the following
    (if you have a class defined with SE24 you don't need the commented code).
    method ON_USER_COMMAND.
           FOR EVENT before_user_command OF cl_gui_alv_grid
           IMPORTING
             e_ucomm
             sender.
    CASE e_ucomm.
         .......   other toolbar funcs if you have any
          WHEN 'EXCEL'.
            CALL METHOD me->download_to_excel.
        ENDCASE.
    endmethod.
    3) code this method to download to EXCEL
    method DOWNLOAD_TO_EXCEL.
    FIELD-SYMBOLS:
           <fs0> TYPE STANDARD TABLE,
           <fs1> TYPE STANDARD TABLE.
        ASSIGN g_outtab1->* TO <fs0>.
        ASSIGN g_fldcat1->* TO <fs1>.
           CALL FUNCTION  'LVC_TRANSFER_TO_KKBLO'
          EXPORTING
            it_fieldcat_lvc   = <fs1>
        is_layout_lvc     = m_cl_variant->ms_layout
             is_tech_complete  = ' '
          IMPORTING
            es_layout_kkblo   = ls_layout
            et_fieldcat_kkblo = lt_fieldcat.
        LOOP AT lt_fieldcat INTO lt_fieldcat_wa.
          CLEAR lt_fieldcat_wa-tech_complete.
          IF lt_fieldcat_wa-tabname IS INITIAL.
            lt_fieldcat_wa-tabname = '1'.
            MODIFY lt_fieldcat FROM lt_fieldcat_wa.
          ENDIF.
          l_tabname = lt_fieldcat_wa-tabname.
        ENDLOOP.
        CALL FUNCTION 'ALV_XXL_CALL'
             EXPORTING
                  i_tabname           = l_tabname
                  is_layout           = ls_layout
                  it_fieldcat         = lt_fieldcat
                  i_title             = sy-title
             TABLES
                  it_outtab           = <fs0>
             EXCEPTIONS
                  fatal_error         = 1
                  no_display_possible = 2
                  OTHERS              = 3.
        IF  sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
    endmethod.
    You get nice column headings etc and decently formatted EXCEL spreadsheet.
    For Office 2007 I think you need to apply a SAP note but it certainly works with OFFICE 2003 which is what we are still using.
    Cheers
    jimbo

    Getting data from a grid to EXCEL can be done in "List" mode vis system==>save etc but it's not particularly user friendly and in any case if you are displaying a nice ALV why should the user have to switch into LIST mode anyway.
    Anyway here's a decent way to do it and it gives great formatted column headings etc etc.
    1) in the ON_TOOLBAR method add this code
    method ON_TOOLBAR.
    type-pools icon.
    CLEAR ls_toolbar.
    MOVE  0 TO ls_toolbar-butn_type.
        MOVE 'EXCEL' TO ls_toolbar-function.
        MOVE  space TO ls_toolbar-disabled.
        MOVE  icon_xxl TO ls_toolbar-icon.
        MOVE 'Excel' TO ls_toolbar-quickinfo.
        MOVE  'EXCEL' TO ls_toolbar-text.
        APPEND ls_toolbar TO e_object->mt_toolbar.
    2) In the ON_USER_COMMAND method add the following
    (if you have a class defined with SE24 you don't need the commented code).
    method ON_USER_COMMAND.
           FOR EVENT before_user_command OF cl_gui_alv_grid
           IMPORTING
             e_ucomm
             sender.
    CASE e_ucomm.
         .......   other toolbar funcs if you have any
          WHEN 'EXCEL'.
            CALL METHOD me->download_to_excel.
        ENDCASE.
    endmethod.
    3) code this method to download to EXCEL
    method DOWNLOAD_TO_EXCEL.
    FIELD-SYMBOLS:
           <fs0> TYPE STANDARD TABLE,
           <fs1> TYPE STANDARD TABLE.
        ASSIGN g_outtab1->* TO <fs0>.
        ASSIGN g_fldcat1->* TO <fs1>.
           CALL FUNCTION  'LVC_TRANSFER_TO_KKBLO'
          EXPORTING
            it_fieldcat_lvc   = <fs1>
        is_layout_lvc     = m_cl_variant->ms_layout
             is_tech_complete  = ' '
          IMPORTING
            es_layout_kkblo   = ls_layout
            et_fieldcat_kkblo = lt_fieldcat.
        LOOP AT lt_fieldcat INTO lt_fieldcat_wa.
          CLEAR lt_fieldcat_wa-tech_complete.
          IF lt_fieldcat_wa-tabname IS INITIAL.
            lt_fieldcat_wa-tabname = '1'.
            MODIFY lt_fieldcat FROM lt_fieldcat_wa.
          ENDIF.
          l_tabname = lt_fieldcat_wa-tabname.
        ENDLOOP.
        CALL FUNCTION 'ALV_XXL_CALL'
             EXPORTING
                  i_tabname           = l_tabname
                  is_layout           = ls_layout
                  it_fieldcat         = lt_fieldcat
                  i_title             = sy-title
             TABLES
                  it_outtab           = <fs0>
             EXCEPTIONS
                  fatal_error         = 1
                  no_display_possible = 2
                  OTHERS              = 3.
        IF  sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
    endmethod.
    You get nice column headings etc and decently formatted EXCEL spreadsheet.
    For Office 2007 I think you need to apply a SAP note but it certainly works with OFFICE 2003 which is what we are still using.
    Cheers
    jimbo

Maybe you are looking for

  • Automatic Block refresh without execute_query

    Can I have my block refresh automatically without doing an execute query ? I would like to refresh only the lines that got changed or updated in the DB by another process. -Ramesh

  • Users using server with netinfo database security. Better/Worse than Ldap?

    Hello, I have a small department of Mac users and I am in the process of setting them up to access a new Mac os/x 10.4 server. I created the accounts for the users in the local netinfo database with access rights granted to network shares via groups.

  • Error when assigning serial no to VA41 contract

    Greetings. I would like to capture serial number in my service contract @ VA41 But when I enter the serial number of a item and attempt to save, I am getting the following error. <Green Light> Correct data via menu path Extras->TechnicalObject <Red L

  • ITunes has stopped working, how do I fix it?

    I was just able to connect to iTunes yesterday and now today I tried it and I am getting the following message - iTunes has stopped working I am running Windows 7 I have updated and am running the most current version of iTunes I have restarted my co

  • How can you delete an app without losing saved data/progress?

    How can you delete an app without losing saved data/progress? Is there a way through iCloud? I have an 8gb 4th gen iPod touch. I have a lot of music, so with 8gb, space is limited. Some apps I have take up 20-30 MB. Some of these games I don't play t