Store data from a table into excel sheet and email

Hi all,
I am just wondering, i m not sure where to start. I want to insert data from a table into an excel spread sheet.
I'm working on a stored procedure with 3 input parameters:
1. the actual query
2. userid
3. the column headers (comma separated) - these will be in the same order as the outer select statement in the query itself. I will use the column headers for the respective columns in Excel worksheet.
When the proc is executed, the excel is populated. If the record count is > 65536, then I need to create multiple worksheets in the same excel file.
How can i do that? Can any body please help with this..?

We are doing like this ( Not sure whether it is the best method available)
--Get the output of the query (Since the number of columns is not fixed you would have to use dbms_sql package)
--loop through the output and write into a file, for example test.csv, using UTL_FILE package
--load the file into a blob variable(we are doing it by loading it into a table)
--For mailing You can use the below package
http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/Utl_Smtp_Sample.html
Mailing code we are using is given below:
CREATE OR REPLACE procedure xls_mail(
    p_sender     varchar2, -- sender, example: 'Me <[email protected]>'
    p_recipients varchar2, -- recipients, example: 'Someone <[email protected]>'
    p_subject    varchar2, -- subject
     p_text           varchar2, -- text
     p_filename      varchar2, -- name of xls file
     p_blob           blob         -- xls file
) is
  conn      utl_smtp.connection;
  i number;
  len number;
BEGIN
  conn := demo_mail.begin_mail(
    sender     => p_sender,
    recipients => p_recipients,
    subject    => p_subject,
    mime_type  => demo_mail.MULTIPART_MIME_TYPE);
  demo_mail.begin_attachment(
    conn         => conn,
    mime_type    => 'application/xls',
    inline       => TRUE,
    filename     => p_filename,
    transfer_enc => 'base64');
    -- split the Base64 encoded attachment into multiple lines
   i   := 1;
   len := DBMS_LOB.getLength(p_blob);
   WHILE (i < len) LOOP
      IF(i + demo_mail.MAX_BASE64_LINE_WIDTH < len)THEN
         UTL_SMTP.Write_Raw_Data (conn
                                , UTL_ENCODE.Base64_Encode(
                                        DBMS_LOB.Substr(p_blob, demo_mail.MAX_BASE64_LINE_WIDTH, i)));
      ELSE
         UTL_SMTP.Write_Raw_Data (conn
                                , UTL_ENCODE.Base64_Encode(
                                        DBMS_LOB.Substr(p_blob, (len - i)+1,  i)));
      END IF;
      UTL_SMTP.Write_Data(conn, UTL_TCP.CRLF);
      i := i + demo_mail.MAX_BASE64_LINE_WIDTH;
   END LOOP;
  demo_mail.end_attachment(conn => conn);
  demo_mail.attach_text(
    conn      => conn,
    data      => p_text,
    mime_type => 'text/html');
  demo_mail.end_mail( conn => conn );
END;

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

  • How to I convert data from oracle database into excel sheet

    how to I convert data from oracle database into excel sheet.
    I need to import columns and there datas from oracle database to microsoft excel sheet.
    Please let me know the different ways for doing this.
    Thanks.

    asktom.oracle.com has an excellent article on writing a PL/SQL procedure that dumps data to an Excel spreadsheet-- search for 'Excel' and it'll come up.
    You can also use your favorite connection protocol (ODBC, OLE DB, etc) to connect from Excel to Oracle and pull the data out that way.
    Justin

  • 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

  • Facing a Problem while downloading the data from ALV Grid to Excel Sheet

    Hi Friends,
    Iam facing a problem while downloading the data from ALV Grid to excel sheet. This is working fine in Development server , when comes to Quality and Production servers I have this trouble.
       I have nearly 11 fields in ALV Grid and out of which one is PO number of length 10 , all the ten numbers are visible in the excel sheet if we download it from development server but when we download it from Quality or Production it is showing only 9 numbers.
    Can any one help me out in this case.

    hi...
    if this problems happens dont display the same internal as u finally got.
    just create new internal table without calling any standard data elements and domains... but the new internal table s similar like ur final internal table and move all the values to new int table.
    for eg.
    ur final internal int table for disp,
         data : begin of itab occur 0,
                        matnr like mara-matnr,
                   end of itab.
    create new like this,
               data : begin of itab occur 0,
                        matnr(12) type N,
                   end of itab.

  • How to bind the data from user table into user report

    Hi All,
      Please assist me to bind the data from user table into user report. I did create an user table with data and create a user report template (using Query Print Layout). How can I display my data into report format which I created before? Any sample program or document I can refer?
    Platform: SAPB1 2005A
    Add On Language: VB.Net 2003
    Thanks.
    rgds
    ERIC

    Hi Ibai,
      Thanks for your feed back. I give you an example.
    Let say now i wanna print employee list, so i will go
    1. Main Menu -> Reports -> HR -> Employee List
    2. Choose the Selection Criteria -> OK
    3. Matrix will display (Employee List)
    4. I can print the report click on print button
    5. Printing report
    My target
    1. Main Menu -> Eric_SubMenu -> Employee List
    2. Matrix will display (Employee List)
    3. Print button
    4. Print report
    My problem
    Now I would like to use my own report format. My own report format means I wanna add on my logo or do some customization within the employee report. So how I am going to do? I only able to display the employee list in matrix. How do I create a new report format and display it.
    Thanks.
    rgds
    ERIC

  • How to download data from abap-ouput to excel sheet with logo

    how to download data from abap-ouput to excel sheet with standard logo
    Edited by: Harish Kasyap on Nov 18, 2008 8:19 AM
    Edited by: Harish Kasyap on Nov 18, 2008 8:20 AM

    For saving the report you can goto System -> List -> Save -> Local File -> Location where you want to save in your presentation server.
    You can also give a option in your selection screen to save the file to Presentation server using FM GUI_DOWNLOAD.
    Hope it helps.
    Thanks,
    Jayant.

  • Loading data from multiple tables to multiple sheets of excel using SSIS

    I have a requirement in which I want to load data from 13 tables to 13 respective sheets of single excel file using SSIS.
    Can anyone know SSIS logic for developing package for this?

    see similar example here
    http://visakhm.blogspot.in/2013/09/exporting-sqlserver-data-to-multiple.html
    In your case you need to use loop to iterate through tables
    First get list of tables in a object variable created in SSIS using INFORMATION_SCHEMA.TABLES view
    Then add a for each loop based on ADO.NET variable enumerator to iterate through tables and inside loop follow method as in the above link to create the sheet first and populate it.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to Export data from a Table to Excel using PL/SQL Code

    Hi,
    I need to export data from a table to the excel sheet using PL/SQL script.
    could you pls provide with custom codes or sample procedures.
    Bobby

    http://asktom.oracle.com/pls/ask/f?p=4950:8:7947129213057862756::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:728625409049

  • Error while downloading data from internal table into XML file

    hi all,
    i developed a program to download data from into internal table to xml file like this.
    tables: mara.
    parameters: p_matnr like mara-matnr.
    data: begin of itab_mara occurs 0,
                matnr like mara-matnr,
                ernam like mara-ernam,
                aenam like mara-aenam,
                vpsta like mara-vpsta,
          end of itab_mara.
    data: lv_field_seperator type c,     " value 'X',
          lv_xml_doc_name(30) type c,    " string value ‘my xml file’,
          lv_result type i.
          lv_field_seperator = 'x'.
          lv_xml_doc_name = 'my xml file'.
    types: begin of truxs_xml_line,
              data(256) type x,
          end of truxs_xml_line.
    types:truxs_xml_table type table of truxs_xml_line.
    data:lv_tab_converted_data type truxs_xml_line,
         lt_tab_converted_data type truxs_xml_table.
    data: lv_xml_file type rlgrap-filename value 'c:\simp.xml'.
    select matnr ernam aenam vpsta from mara into table itab_mara up to 5
           rows where matnr = p_matnr.
    CALL FUNCTION 'SAP_CONVERT_TO_XML_FORMAT'
    EXPORTING
       I_FIELD_SEPERATOR          = lv_field_seperator
      I_LINE_HEADER              =
      I_FILENAME                 =
      I_APPL_KEEP                = ' '
       I_XML_DOC_NAME             = lv_xml_doc_name
    IMPORTING
       PE_BIN_FILESIZE            = lv_result
      TABLES
        I_TAB_SAP_DATA             = itab_mara
    CHANGING
       I_TAB_CONVERTED_DATA       = lt_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.
    open dataset lv_xml_file for output in binary mode.
    loop at lt_tab_converted_data into lv_tab_converted_data.
    transfer lv_tab_converted_data to lv_xml_file.
    endloop.
    close dataset lv_xml_file.
    this program is syntactically correct and getting executed, but when i open the target xml file it is showing the following error.
    The XML page cannot be displayed
    Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
    XML document must have a top level element. Error processing resource 'file:///C:/simp.xml'.
    will anyone show me the possible solution to rectify this error
    thanks and regards,
    anil.

    Hi,
    Here is a small sample program to convert data in an internal table into XML format and display it.
    DATA: itab  TYPE TABLE OF spfli,
          l_xml TYPE REF TO cl_xml_document.
    * Read data into a ITAB
    SELECT * FROM spfli INTO TABLE itab.
    * Create the XML Object
    CREATE OBJECT l_xml.
    * Convert data in ITAB to XML
    CALL METHOD l_xml->create_with_data( name = 'Test1'
                                         dataobject = t_goal[] ).
    * Display XML Document
    CALL METHOD l_xml->display.
    Here are some other sample SAP programs to handle XML in ABAP:
    BCCIIXMLT1, BCCIIXMLT2, and BCCIIXMLT3.
    Hope this helps,
    Sumant.

  • Dump data from a table into wwv_flow_files

    HI,
    Could you help me, to take data from a table, and insert it into blob_content in wwv_flow_files; and data should be stored in a .txt file
    regards,
    Rajesh

    Alex Nuijten wrote:
    But in case of APEX, that might be a really bad idea to insert metadata in the apex repository:
    http://joelkallman.blogspot.com/2010/01/perils-of-modifying-application-express.html
    This is not really an APEX metadata table, Alex. As far as I recall, it is a standard mod_plsql documents table that handles file uploads. One can also insert a document into the table dkirectly using an INSERT as it pretty straight forward.
    Not exactly sure why though as the doc download procedure needs a LOB or CLOB.. and it does not care from what table you create it from - or whether you do it on the fly.
    But still, you make an important point of using application/system objects for the purpose they have been designed for. And in this case, creating your own documents table may be a lot better.

  • Retrive data from two tables into one internal table.

    Hi SDN,
    I am downloading the Assets data from two tables ANLA,ANLZ.
    there is a common field ANL1in both tables and i have to retrive the data by using anl1 into the internal table.
    can you please send me the SELECT Syntax for this probl.....
    Thank you & Regards,
    Manoj

    Hi manoj,
    Please see the following sample code. But kindly don't use join as it may hamper ur performance. No trouble in using two select query.
    data: begin of itab occurs 0,
            BUKRS like anla-BUKRS,
            ANLN1 like anla-ANLN1,
           BDATU like anlz-BDATU,
            end of itab.
    select anlabukrs anlaANLN1 anlzBDATU  into corresponding fields of table itab from anla inner join anlz on anlaanl1 eq anlz~anl1 where (logexp).
    Please come back for any clarification.
    Thanks and Regards,
    saurabh

  • Inserting data from one table into another table using PL/SQL

    HI,
    I am trying to insert values from one table into another using PL procedure, the values I want to retrieve from the table riverside1 are charac_id and charac_type and insert these values into another table called riverside2 , the stored procedure zorgs_gorfs(x,y) accepts two parameters which are 2 charac_id's of d characters in riverside1 then using insert statements inserts these characters from riverside1 into riverside2.
    CREATE OR REPLACE PROCEDURE zorgs_gorfs(x IN NUMBER, y IN NUMBER) AS
         BEGIN
              INSERT INTO riverside2
                   (charac_id)
              VALUES
                   (x);
    INSERT INTO riverside2
                   (charac_id)
              VALUES
                   (y);
          END zorgs_gorfs;
    /This works but the problem im having is that when I also try to insert the charac_type as well as the charac_id it doesnt work below is the code:
    CREATE OR REPLACE PROCEDURE zorgs_gorfs(x IN NUMBER, y IN NUMBER) AS
         BEGIN
              INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id = x);
          END zorgs_gorfs;
    /can someone kindly sort me out

    modify this sql
    INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id = x);as
    INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id in ( x,y));But my suggestion would be consider revising your approach. It does not look that good.
    Thanks,
    karthick.

  • Is it possible to store dat from word file into a table

    Hi Experts,
    I have an Office UI element on my web dynpro View. It is selected as MS Word. Now I want to save data from this word file to a table in SAP. Can we have a data element which can store such type of large data. Please suggest.
    Regards,
    Vaibhav Tiwari.

    >But we can't have a table attribute of this type
    Actually you can.  You can define a database column as RAW STRING.  This is exactly the same as a XSTRING variable and in your SQL statement you just pass it an XSTRING.  It will store the entire contents of the XSTRING as a single column in the database.  Large size is not a problem.

  • Data from word tables to excel master spreadsheet

    Hello, I'm looking to take data from my damage report forms that come in maybe 20 times a week. This data needs to goto a master excel spreadsheet. I've managed to find a macro that does this but it does not paste it into excel the way I require and also
    extracts data I do not require.
    The word document contains a column of headings on the left, these will be the master spreadsheet sheet column headers. These will be on the spreadsheet already so I don't need them copied. 
    The other  two columns contains the data I will need to xfer to excel. I was thinking bookmarks can help here but I'm unsure if these will save over from the original template?
    So,  if there is some code out there that can help, brilliant. It will be an excel macro in the master spreadshee. TThat takestthe datadfrom the active word doc or by selecting the word doc in its folder. 
    Fingers crossed.
    Joseph 

    Hi Joseph,
    You should be able to run below code to get the data out of the Tabel(s) of a Word Document from within Excel.
    You can modify the code accordingly to your needs to specify the range where you want the data to be copied.
    I have already slightly modified the code to skip the header information.
    Sub ImportWordTable()
    Dim wdDoc As Object
    Dim wdFileName As Variant
    Dim TableNo As Integer 'table number in Word
    Dim iRow As Long 'row index in Excel
    Dim iCol As Integer 'column index in Excel
    wdFileName = Application.GetOpenFilename("Word files (*.docx),*.docx", , _
    "Browse for file containing table to be imported")
    If wdFileName = False Then Exit Sub '(user cancelled import file browser)
    Set wdDoc = GetObject(wdFileName) 'open Word file
    With wdDoc
    TableNo = wdDoc.tables.Count
    If TableNo = 0 Then
    MsgBox "This document contains no tables", _
    vbExclamation, "Import Word Table"
    ElseIf TableNo > 1 Then
    TableNo = InputBox("This Word document contains " & TableNo & " tables." & vbCrLf & _
    "Enter table number of table to import", "Import Word Table", "1")
    End If
    With .tables(TableNo)
    'copy cell contents from Word table cells to Excel cells
    ' start with row 2 to skip headers
    For iRow = 2 To .Rows.Count
    For iCol = 1 To .Columns.Count
    ' Define starting point here
    Cells(iRow - 1, iCol) = WorksheetFunction.Clean(.cell(iRow, iCol).Range.Text)
    Next iCol
    Next iRow
    End With
    End With
    Set wdDoc = Nothing
    End Sub
    The source is this link:
    Export Word Table in Excel
    Also this Forum is more for generic Excel questions, for better response post in Excel For Developer Forum.
    Hope this helps,
    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.

Maybe you are looking for

  • Once and for all

    Ok guys and girls, first let me apologize for starting yet another install link, but I am still confused after reading every link so far. I also am have the problem with itunes and quicktime opening for like a second and then closing. I don't have No

  • Consuming a sap web service via jde 4.5.7 (ecc 6.0)

    Hi all, I have a question here, if u could help me, i have to call a sap webeservice via jde , but before i test a jde example by calling a public web service which is not a sap web service , i used to  give  url  as: connThread.get("http://www.webse

  • Open Add Item Form as Dialog

    Hi All - I have a custom button on the click of which I am trying to open a Add Item form. When the display form opens I want to hide all the masterpage items( viz. Quick Launch, header, foooter, etc). I tried below but it's not opening and giving er

  • Open PDF in full Reader and not web browser

    Hi I am currently designing an internal help page with PDF forms - Is there anyway to open a pdf web page link in Internet explorer and open the PDF in the full Adobe x reader and not the internet browser version from inside the form itself? Thanks i

  • Strange error in CHM

    Hi, I am getting a strange problem in RoboHelp CHM file. I am using RoboHelp X5. After compiling the CHM I placed in a network folder for others to access. In this CHM I have only "Contents" tab and "Search" tab. No other check boxes are selected in