RET_CALL_NOT_FLUSHED when using OLE

Hi,
    i have an urgent problem about OLE.
    i run an abap report to download an excel template to the local and when  calling the method document->save_copy_as , the exporting parameter 'ERROR' return an error 'RET_CALL_NOT_FLUSHED'.
    This problem occurs in the VISTA,  but when i run the report in the WINDOWS XP , everything is ok.
    my source code is:
     CLEAR object_id.
  object_id = 'ZHRIS058'.
  CALL FUNCTION 'SAP_OI_LOAD_MIME_DATA'
    EXPORTING
      object_id        = object_id
    IMPORTING
      data_size        = doc_size
      document_format  = doc_format
      document_type    = doc_type
    TABLES
      data_table       = doc_table
    EXCEPTIONS
      object_not_found = 1
      internal_error   = 2
      OTHERS           = 3.
  call method cl_gui_cfw=>flush .
  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
         WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  IF doc_size NE 0.
    CALL METHOD factory->get_document_proxy
      EXPORTING
        document_type  = doc_type
      IMPORTING
        document_proxy = document
        retcode        = retcode.
    call method cl_gui_cfw=>flush .
    CALL METHOD c_oi_errors=>show_message
      EXPORTING
        type = 'E'.
    call method cl_gui_cfw=>flush .
    CALL METHOD document->play_document_from_table
      EXPORTING
        document_table = doc_table[]
        document_size  = doc_size
        no_flush       = 'X'
      IMPORTING
        retcode        = retcode.
    call method cl_gui_cfw=>flush .
data: l_error type ref to I_OI_ERROR.
CALL METHOD DOCUMENT->SAVE_COPY_AS
  EXPORTING
    FILE_NAME   = 'C:\$tmp.xls'
    NO_FLUSH    = 'X'
    PROMPT_USER = ' '
  IMPORTING
    <b>ERROR       = l_error   "here is the error message</b>
    RETCODE     = retcode.
    CALL METHOD c_oi_errors=>show_message
      EXPORTING
        type = 'E'.
    PERFORM close_doc.
    PERFORM close_factory.
  ELSE.
    MESSAGE 'No document selected' TYPE 'E'.
  ENDIF.
    hope your advice. thanks.
         qiuguo

Just try with below before printing & opening the document. Refer to the examples SAPREDIT*
                 Call Method cl_gui_cfw=>Flush
                    Exceptions
                      Others = 0.

Similar Messages

  • When Using [OLE DB] driver some arabic text appear with cutting last character

    hi
    i have a problem in crystal report when bilding report using using [OLE DB] driver some arabic text appear with cutting the last one or tow characters
    note: i'm using VBasic 6.0 , RDC and crystal report viewer

    I thought I'd post an update to this since I've narrowed down the problem.
    It turns out this is NOT a bug in Apple's Java implementation, but in the AAT rendering engine. In any application, if a user changes the style of part of an Arabic string, it breaks the font connection. I have been informed though that this has already been fixed, and should be functional when Leopard is released. ALL applications that use AAT suffer from this problem, not just Java.

  • Attention!!-don't use OLE object in Reports

    If you are planning to use or is currently using OLE objects in Reports-please don't use it as the object maynot reload in future and your report may not even open in Report Builder.I got this message when opening the report containing OLE object:
    REP-4004: Error occurred while restoring OLE object
    and it refused to open up crashing my days of work.
    The pity is I can't open my report even to remove the OLE object.

    I know that is weird.I placed the object in the same directory-but in vain.Afterall, what's the logic of putting it in the same directory after embedding it?

  • Crystal 2011 getting Logon failed IM004 error when using ODBC (RDO)

    I just installed Crystal Reports 2011 on Windows 7 Ultimate SP1.  Sporadically, but way too often (I would estimate about 60% of the time), when I go to set up an ODBC (RDO) connection or refresh an existing report and enter the password, I get the following error:
    Logon failed.
    Details: IM004:[Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle on SQL_Handle_ENV failed
    Other times, it just works, with no changed made.  It seems to work slightly more often when using the SQL Server driver (the one for SQL 2000) as opposed to the SQL Native Client or SQL Server Native Client 10.0 drivers.  But not often enough for that to be the solution.
    I have tested this with a locally installed SQL Server (on the same machine as Crystal Reports) and remote SQL Servers, with SQL 2000, 2005 and 2008.  Same results.
    I have Crystal Reports 2008 installed on the same machine and have not once had this problem.  I have tried using the same ODBC connections I already had from Crystal 2008 with Crystal 2011 and also to create new ones, same results either way.
    Is this a known issue, or is there a switch/setting I need to change to make this work consistently?  I am especially puzzled by the fact that it seems random, I have not been able to find any pattern at all.

    Hi Victoria,
    MS SQL Server 2008 has a client install now, the MDAC/WDAC doesn't install it as MS used to do with all of their OS's. CR also had to update the use of SQL Server 2008 to include the SQLNCLI10 client engine.
    I suggest, if you have not already, install the Native 10 client from either the SQL Server CD or you can download the MSI from MS's site and only use the Native 10 driver.
    MS kind of dropped ODBC and moved to OLE DB. The native client actually uses the OLE DB driver so using ODBC just puts another layer on top of OLE DB anyways. It's more convenient to use ODBC for deploying applications but it can affect performance.
    Anyways, as noted, CR 2011 is still in Ramp up mode so this issue may have been tracked. If not though you can purchase a support case, if it's a bug then you'll get a refund, if it's a limitation in MS then no refund.
    There is [SP 1 for CR 2011|https://smpdl.sap-ag.de/~sapidp/012002523100007683092011E/cr2011sp1.exe] - http://service.sap.com/sap/bc/bsp/spn/bobj_download/main.htm
    Seems to be a problem with that page right now so try again later... and apply SP 1 or wait until it goes GA and test again. If it's still an issue then you can log a case.
    Firefox just got updated and it's failing, IE works though...
    Thanks again
    Don
    Edited by: Don Williams on Jun 22, 2011 8:51 AM

  • Unable to launch a new document in winword 2007 from abap using OLE

    Dear Developers,
    We have a customized abap report which use OLE to launch a new document and display SAP data in that document. It is working on winword 2003.
    When we upgrade our version to office 2007 (winword 2007), the abap report will only launch a blank screen with no new document , no data is displayed.
    After reading OSS note 1286768, I tried with sap gui version 7.10 patch 17, but it still did not work.
    Some part of the codes below :
    CREATE OBJECT wordobj 'Word.Basic' .
    CALL METHOD OF wordobj 'AppInfo' = version EXPORTING #1 = 2.
    CALL METHOD OF wordobj 'FileNew' EXPORTING #1 = 'normal.dot'.
    CALL METHOD OF wordobj 'AppShow'.
    Do we need to install any files in SAP server to enable winword 2007?
    Do you have any tips to share?
    Thanks & regards
    Bee Khuan

    HI,
       use the following
    create object wordobj 'WORD.APPLICATION' .
      if sy-subrc ne 0 .
        message s000(su) with 'Error while creating OLE object!'.
        leave program .
      endif .
      set property of gs_word 'Visible' = '1' .
    SET PROPERTY OF gs_word 'Save' = '1' .
      get property of gs_word 'documents' = gs_documents.
      call method of gs_documents 'Add' = newdoc.
    Thanks & Regards,
    Vallamuthu. M

  • Avoid Database Login prompt when using CrystalReportViewer

    Is there a way to keep the Database Login prompt from coming up when using Crystal Reports runtime 2008 SP2? I'm using that plus Visual Studio 2008 to develop a Windows Form application to view reports on a client machine that accesses data on a seperate SQL Server 2005 machine. My customer would like to avoid having users manually enter anything everytime a report is opened with the Crystal Reports viewer.
    I've used the following code with ODBC and OLE DB report connections. When I use ODBC, the prompt comes up with Integrated Security checked which must be cleared. When I use OLE DB, the prompt comes up with Database Name blank and greyed out so I cannot manually enter it.
    Am I missing something here?
    Imports CrystalDecisions.Shared
    Imports CrystalDecisions.CrystalReports.Engine
    Imports CrystalDecisions.Windows.Forms
    Public Class Form1
        Private Sub setDatabaseLogon(ByVal myConnectionInfo As ConnectionInfo)
            Dim logOnInfos As TableLogOnInfos = CrystalReportViewer1.LogOnInfo
            For Each logOnInfo As TableLogOnInfo In logOnInfos
                logOnInfo.ConnectionInfo = myConnectionInfo
            Nex
        End Sub
        Private Sub ConfigureCrystalReports()
            Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
            setDatabaseLogon(myConnectionInfo)
            myConnectionInfo.DatabaseName = "ClearView"
            myConnectionInfo.UserID = "reports"
            myConnectionInfo.Password = "dstreports"
            myConnectionInfo.IntegratedSecurity = False
        End Sub
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ConfigureCrystalReports()
        End Sub
    End Class

    Thanks Jonathan for the tip. I tried it before and after the setDatabaseLogin call yesterday, but got the same results. I'm still going to follow your suggestion because that makes more sense.
    Turns out it was the configuration of my ODBC/System DSN that was causing the problem. I reconfigured the System DSN by clearing the check box to provide username/password and now I don't get the Database Login anymore.
    I found a different blog post that answered the OLE DB issue I was seeing where the DatabaseName was coming up blank:
    Login Error Database at Runtime
    Haven't tried it yet and probably won't because I got the Viewer to work with ODBC the way I like it.
    Thanks for the help!

  • OLE objects and OO methods - Error using OLE automation

    Hi,
    I'm developing an class to read/write excel sheets and i'm getting an error on the OLE method that is:
    on this instruction
    call method of l_obj_excel 'WORKBOOKS' = l_workb_col.
    i got a dump that give me the following error UC_OBJECTS_NOT_CONVERTIBLE
    The strange is that i've got the same code running on reports and it works fine only when passing it to a oo method i get that dump.
    Thzs in advanced to all
    Best regards
    Jaime

    hi check this..
    Report ZMULTICOLOR_TEST 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
          h_c type ole2_object.            " color
    DATA: FILENAME LIKE RLGRAP-FILENAME.
    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.
    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 200 'Carrier id'(001).
      perform fill_cell using 1 2 1 200 'Connection id'(002).
      perform fill_cell using 1 3 1 200 'City from'(003).
      perform fill_cell using 1 4 1 200 'City to'(004).
      perform fill_cell using 1 5 1 200 'Dep. Time'(005).
      loop at it_spfli.
    copy flights to active EXCEL sheet
        h = sy-tabix + 1.
        if it_spfli-carrid cs 'AA'.
          perform fill_cell using h 1 0 000255000 it_spfli-carrid.
        elseif it_spfli-carrid cs 'AZ'.
          perform fill_cell using h 1 0 168000000 it_spfli-carrid.
        elseif it_spfli-carrid cs 'JL'.
          perform fill_cell using h 1 0 168168000 it_spfli-carrid.
        elseif it_spfli-carrid cs 'LH'.
          perform fill_cell using h 1 0 111111111 it_spfli-carrid.
        elseif it_spfli-carrid cs 'SQ'.
          perform fill_cell using h 1 0 100100100 it_spfli-carrid.
        else.
          perform fill_cell using h 1 0 000145000 it_spfli-carrid.
        endif.
        if it_spfli-connid lt 400.
          perform fill_cell using h 2 0 255000255 it_spfli-connid.
        elseif it_spfli-connid lt 800.
          perform fill_cell using h 2 0 077099088 it_spfli-connid.
        else.
          perform fill_cell using h 2 0 246156138 it_spfli-connid.
        endif.
        if it_spfli-cityfrom cp 'S*'.
          perform fill_cell using h 3 0 155155155 it_spfli-cityfrom.
        elseif it_spfli-cityfrom cp 'N*'.
          perform fill_cell using h 3 0 189111222 it_spfli-cityfrom.
        else.
          perform fill_cell using h 3 0 111230222 it_spfli-cityfrom.
        endif.
        if it_spfli-cityto cp 'S*'.
          perform fill_cell using h 4 0 200200200 it_spfli-cityto.
        elseif it_spfli-cityto cp 'N*'.
          perform fill_cell using h 4 0 000111222 it_spfli-cityto.
        else.
          perform fill_cell using h 4 0 130230230 it_spfli-cityto.
        endif.
        if it_spfli-deptime lt '020000'.
          perform fill_cell using h 5 0 145145145 it_spfli-deptime.
        elseif it_spfli-deptime lt '120000' .
          perform fill_cell using h 5 0 015215205 it_spfli-deptime.
        elseif it_spfli-deptime lt '180000' .
          perform fill_cell using h 5 0 000215205 it_spfli-deptime.
        else.
          perform fill_cell using h 5 0 115115105 it_spfli-deptime.
        endif.
      endloop.
    EXCEL FILENAME
      CONCATENATE SY-REPID '_' SY-DATUM6(2) '_' SY-DATUM4(2) '_'
                  SY-DATUM(4) '_' SY-UZEIT '.XLS' INTO FILENAME.
      CALL METHOD OF H_MAP 'SAVEAS' EXPORTING #1 = FILENAME.
      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 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
    *&      Form  ERR_HDL
          outputs OLE error if any                                       *
    -->  p1        text
    <--  p2        text
    form err_hdl.
      if sy-subrc <> 0.
        write: / 'OLE-Automation Error:'(010), sy-subrc.
        stop.
      endif.
    endform.                    " ERR_HDL
    regards,
    venkat

  • Database login windows when using DataSet ( CR2008 )

    After executing this code, I get a database login window when using a DataSet, wondering why I am asked for user/pwd when using DataSets.

    Thanks Jonathan for the tip. I tried it before and after the setDatabaseLogin call yesterday, but got the same results. I'm still going to follow your suggestion because that makes more sense.
    Turns out it was the configuration of my ODBC/System DSN that was causing the problem. I reconfigured the System DSN by clearing the check box to provide username/password and now I don't get the Database Login anymore.
    I found a different blog post that answered the OLE DB issue I was seeing where the DatabaseName was coming up blank:
    Login Error Database at Runtime
    Haven't tried it yet and probably won't because I got the Viewer to work with ODBC the way I like it.
    Thanks for the help!

  • Can I use OLE in WebDynpro 4 Abap??

    I got a complicate request that need to read from an EXCEL template and edit the EXCEL.
    the Excel file can only be a normal .XLS file with macro in it,so XML don't work here.
    I try to use an OLE object to operate the excel in WD Application but an error happened when create the OLE object.     while there's no problem to create it in a normal Report program.
    is there any way to use OLE in WD Application???  otherwise i should write program to read the binary file of excel myself....

    looks to me that you need to use the UI element for office integration, standard available in wd4 abap.

  • Download to MS WORD using OLE

    Hi All,
    I am developing a program to download data to MS WORD using OLE.  I would like to know answers for my below questions,
    1) What is the equivalent ABAP code for VB macro
         Selection.Style = ActiveDocument.Styles("No Spacing")
         Issue is when i say new line it prints one blank line and then start printing. This is because of format Style = Normal.
         If i set it up as No Spacing it would resolve my issue.
    2) How to insert a bitmap image in MS WORD using OLE?
    Thanks in advance.

    Found answer by myself.
    Below is the code to add picture
    GET PROPERTY OF selection 'InlineShapes' = shapes.
    CALL METHOD OF shapes 'AddPicture'
      EXPORTING
      #1 = 'C:\Temp\untitled.bmp'
      #2 = 0
      #3 = 1.
    Below is the code for no line spacing
    SET PROPERTY OF parformat 'SpaceAfter' = 0.

  • Third Party Tool using OLE DB for OLAP

    We have built a query in BEx 7.0 Query Designer and released for access via OLE DB for OLAP to Cog nos 8 Repor Designr. 
    I am trying to see the SQL/MDX code Cog nos is sending to BW to retrieve data.  Is there a way to see what BW gets from Cog nos report on the BW side?  Just to clarify, getting this info for the BW query executing without the 3rd party tool is not useful, because we dont have any issues running the BEx query, however 3pty tool gets back bad data.  Specifically when using a query with a BEx reusable structure. 
    I have further details on the design of the query, however I am trying not to create a very long and messy thread with unnecessary info.  Please ask if those details are necessary to understand the issue.

    Here is a little more info on how the query is setup and why I think it is having a problem.....
    Query has Two Structures....
    <u>Rows:</u>
    Reusable Structure (Without Key Figures) with 20 Rows (selections and formulas) defining each line of a Financial Statement.  Structure Name is "XYZ Statement"
    <u>Colums:</u>
    Reusable Structure (With Key Figures) with 3 Columns (05/2007 Actuals, 05/2007 Plan, Variance).  Structure Name is "Comparison"
    <u>Free Characteristics:</u>
    GL Account
    Cost Center
    Other Char...
    <u>What Cognos 8 sees in the package:</u>
    In Cognos, Structure "XYZ Statement" appears as a regular dimension, the same way Free Characteristics do.  The Structure "Comparison" appears as a Key Figure, aka Measure.
    <u>How the Cognos Report is built in Report Studio:</u>
    If the report is built NOT using the dimension "XYZ Statement", regardless of whatever Free Characteristics you use from the query as a datasource, you will not get any data, however it works fine when the "XYZ Statement" dimension is used.
    <u>What I think the problem is:</u>
    I am thinking all Cognos reports build off this package MUST use the dimension "XYZ Statement" (aka Reusable Characteristic Structure in BW), other wise the query does not return any data.
    <u>How I am trying to validate this theory:</u>
    Query is the datasource for Cognos.  Executing RSRT only allows me to get details on the query execution via BW, however since the Cognos report is not returning correct data, I am trying to see what the Cognos Report is passing back to BW, to understand/validate what I think is the issue.  If this is just the way it works, then I want to validate and move on.

  • Missing results when using percentage function %GT

    Hi all,
    I'm using the percentage function in BEx. As you can see in the left two columns, it works fine when the results are higher then 0,4. All the results less than 0,4 are set to 0. In the last column I calculated the results with an Excel formula. 
    Any Idea, what the problem can be?
    4.392,080          1,5635 %          1,563481163
    997,440          0,0000 %          0,355066085
    4.761,680          1,6951 %          1,695050405
    1.260,000          0,4485 %          0,448531508
    469,600          0,0000 %          0,167166981
    280.916,720     100,0000 %          
    280.916,720     100,0000 %          
    Many thanks in advance!

    Dear Daya sagar,
      Iam tried with taht functionality  the query it self it is showing wrong and iam getting below error as result.
    Diagnosis
    The query contains a formula with the operator %RT. Therefore, the query cannot be released for OLE DB for OLAP.
    The operators %GT, %RT, %CT, SUMGT, SUMRT, SUMCT and LEAF depend on the display of the list in the BEx Analyzer. If you used OLE DB for OLAP or MDX, this formula would deliver unexpected values.
    Procedure
    Do not release the query for OLE DB for OLAP, or do not use the operators %GT, %RT, %CT, SUMGT, SUMRT, SUMCT or LEAF. You may be able to achieve the desired result by selecting constants.
    and report output is not coming.
    Thanks & Regards,
    Sathish

  • Conditional formatting using OLE in ABAP

    Hello all,
       Is it possible to apply conditional format using OLE in ABAP?? for example if the cell value is greater than 10, then make it red...
    Thanks in advance..
    Regards,
    Maya

    Yes,Since we can do conditional format based on other columns for a column:
    Assume you pulled A,B and wants to apply RED color on A
    Pull columns A,A,B (A twice) for 2nd A expression something like
    case when A>B then 1 else 0 end
    On A(1st A) Conditional format
    Add Condition->Choose 2nd A
    add value 1 and set color RED.
    Appreciate if you mark as correct/helpful

  • Opening .pdf files from forms using OLE

    Hi,
    I want to open, print , save and save as pdf files from forms using OLE . Please help me with the same.
    Thanks
    Vidya

    If you are in client/server mode, you can put an OLE container component on your form. However, be warned that this method does not work when you convert to the forms server web enabled mode. If you anticipate moving your application to the web anytime soon, my advice would be to web-enable first and then add in the feature to view .pdf (or other) files. In our client/server app, I went to a lot of trouble to add in OLE features such as you describe, and now I have to completely re-write those features for the web.

  • Create Excel sheet using OLE

    Hi All,
           Can any one help me to create an multiple excel sheet in an work book using OLE. I want to create more than 3 sheets in excel, which is default sheets in excel when we one excel.

    Hi,
    Check the below sample code.
    Here I'm downloading the same table twice into 2 different sheets for example purpose.
    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_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: BEGIN OF t_hex,
          l_tab TYPE x,
          END OF t_hex.
    DATA: wf_deli(1) TYPE c,            "delimiter
          wf_action TYPE i,
          wf_file TYPE string,
          wf_path TYPE string,
          wf_fullpath TYPE string.
    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_save_dialog
        EXPORTING
          window_title         = 'Select File'
    *      default_extension    = 'xls'
          default_file_name    = 'Material Details'
    *      with_encoding        =
          file_filter          = '*.xls'
          initial_directory    = 'C:\'
          prompt_on_overwrite  = ' '
        CHANGING
          filename             = wf_file
          path                 = wf_path
          fullpath             = wf_fullpath
          user_action          = wf_action
    *      file_encoding        =
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          OTHERS               = 4
      IF sy-subrc <> 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      IF wf_action EQ 9.
        MESSAGE 'No File have been Selected' TYPE 'S'.
      ELSE.
        p_file = wf_fullpath.
        PERFORM create_excel.
      ENDIF.
    *&      Form  create_excel
    *       text
    FORM create_excel.
      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.
    * CREATE AN EXCEL WORKBOOK OBJECT
      CALL METHOD OF wf_excel 'WORKBOOKS' = wf_mapl.
      PERFORM err_hdl.
      SET PROPERTY OF wf_excel 'SheetsInNewWorkbook' = 3. "no of sheets
      PERFORM err_hdl.
      CALL METHOD OF wf_mapl 'ADD' = wf_map.
      PERFORM err_hdl.
    *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.
      PERFORM f_material_details
      TABLES int_matl
      USING  1.
      PERFORM f_material_details
      TABLES int_matl
      USING  2.
      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.
      ENDIF.
      CALL METHOD OF wf_mapl 'CLOSE'.
      CALL METHOD OF wf_excel 'QUIT'.
      FREE OBJECT wf_mapl.
      FREE OBJECT wf_map.
      FREE OBJECT wf_excel.
    ENDFORM.                    "create_excel
    *&      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
       TABLES lint_matl
      USING l_sheet_no TYPE i.
      DATA: lv_lines TYPE i,
            lv_sheet_name(50) TYPE c.
      wc_sheets = l_sheet_no.
      CASE l_sheet_no.
        WHEN 1.
          lv_sheet_name = 'Material_sheet1'.
        WHEN 2.
          lv_sheet_name = 'Material_sheet2'.
      ENDCASE.
    *-- 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' = lv_sheet_name.
    *--formatting the cells
      CALL METHOD OF wf_excel 'Cells' = wf_cell_from
        EXPORTING
        #1 = 1
        #2 = 1.
      DESCRIBE TABLE lint_matl LINES lv_lines.
      CALL METHOD OF wf_excel 'Cells' = wf_cell_to
        EXPORTING
        #1 = lv_lines
        #2 = 4.
    *--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
        #2 = 1.
      DESCRIBE TABLE lint_matl LINES lv_lines.
      CALL METHOD OF wf_excel 'Cells' = wf_cell_to1
        EXPORTING
        #1 = lv_lines
        #2 = 1.
      CALL METHOD OF wf_excel 'Range' = wf_cell1  " Cell range for first
                                                  " column(Material)
        EXPORTING
        #1 = wf_cell_from1
        #2 = wf_cell_to1.
      SET PROPERTY OF wf_cell1 'NumberFormat' = '@' . "To disply zeros
      "in Material number
      DATA l_rc TYPE i.
    *DATA download into excel first sheet
      CALL METHOD cl_gui_frontend_services=>clipboard_export
        IMPORTING
          data         = lint_matl[]
        CHANGING
          rc           = l_rc
        EXCEPTIONS
          cntl_error   = 1
          error_no_gui = 2
          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
    Edited by: Manoj Kumar on Mar 5, 2009 11:25 AM

Maybe you are looking for