Skip to Content
author's profile photo Former Member
Former Member

Sending 5 tabs Excel through SAP

Hi All,

How could I send the 5 tabs in excel attachment frm SAP via E-mail.

Regards,

vinesh

Edited by: Siddivinesh Jogu on Jul 20, 2009 8:07 AM

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jul 20, 2009 at 06:13 AM

    Hi,

    check out the link

    [https://forums.sdn.sap.com/click.jspa?searchID=29189348&messageID=7785228]

    Best of Luck !!!

    Regards

    Ravi

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 20, 2009 at 06:56 AM

    hi,

    try the following given code..

    INCLUDE ole2incl.                       "include used for providing classes used for using create object for creating application and worksheets
    DATA: application TYPE ole2_object,
           workbook TYPE ole2_object,
           sheet TYPE ole2_object,
           cells TYPE ole2_object.
    CONSTANTS: row_max TYPE i VALUE 256.
    DATA index TYPE i.
    
    *DATA: BEGIN OF itab1 OCCURS 0, first_name(10), END OF itab1.
    *DATA: BEGIN OF itab2 OCCURS 0, last_name(10), END OF itab2.
    DATA: BEGIN OF itab3 OCCURS 0, formula(50), END OF itab3.
    *
    
    TABLES: vbap,mara.
    
    
    TYPES: BEGIN OF itab,
           lifnr TYPE lfa1-lifnr,
           land1 TYPE lfa1-land1,
    *       name1 TYPE lfa1-name1,
    *       ort01 TYPE lfa1-ort01,
           END OF itab.
    
    
    
    DATA: BEGIN OF itab2 OCCURS 0,
    matnr TYPE mara-matnr,
    ersda TYPE mara-ersda,
    ernam TYPE mara-ernam,
    END OF itab2.
     data : v_row type sy-tabix.
    
    DATA: itab1 TYPE STANDARD TABLE OF itab WITH HEADER LINE.
    
    DATA: IT_XLSTAB TYPE STANDARD TABLE OF ITAB ,
          WA_XLSTAB LIKE LINE OF IT_XLSTAB.
    
    START-OF-SELECTION.
    
      SELECT lifnr land1 fROM lfa1  INTO CORRESPONDING FIELDS OF TABLE itab1 UP TO 5 ROWS.
    
    
      SELECT matnr
      ersda
      ernam
      FROM mara
      INTO CORRESPONDING FIELDS OF
      TABLE itab2 UP TO 5 ROWS.
    
    
    
    ************************************************************************
    *START-OF-SELECTION
    START-OF-SELECTION.
    
      CREATE OBJECT application 'excel.application'.
      SET PROPERTY OF application 'visible' = 1.
      CALL METHOD OF application 'Workbooks' = workbook.
      CALL METHOD OF workbook 'Add'.
    
    * Create first Excel Sheet
      CALL METHOD OF application 'Worksheets' = sheet
                                   EXPORTING #1 = 1.
      CALL METHOD OF sheet 'Activate'.
      SET PROPERTY OF sheet 'Name' = 'Sheet1'.
      clear v_row.
      LOOP AT itab1.
         v_row = sy-tabix.
          perform fill_cell  using  v_row 1  itab1-lifnr.
          perform fill_cell  using  v_row 2 itab1-land1.
      ENDLOOP.
    
    * Create second Excel sheet
      CALL METHOD OF application 'Worksheets' = sheet
                                   EXPORTING #1 = 2.
      SET PROPERTY OF sheet 'Name' = 'Sheet2'.
      CALL METHOD OF sheet 'Activate'.
      clear v_row.
      LOOP AT itab2.
         v_row = sy-tabix.
    
          perform fill_cell using  v_row 1 itab2-matnr.
          perform fill_cell using  v_row 2 itab2-ersda.
          perform fill_cell using  v_row 3 itab2-ernam.
    
      ENDLOOP.
    
    
    * Save excel speadsheet to particular filename
      CALL METHOD OF sheet 'SaveAs'
                      EXPORTING #1 = 'c:\temp\excelgeet.xls'     "filename
                                #2 = 1.                          "fileFormat
    
    *  Closes excel window, data is lost if not saved
      SET PROPERTY OF application 'visible' = 0.
    
    *  call method of sheet 'CLOSE'
    *
    *  EXPORTING #1 = 'YES'.
    
    
    *&---------------------------------------------------------------------*
    *& both the below coding closes the apllication permanently from the task manager also.
    *&---------------------------------------------------------------------*
    
    SET PROPERTY OF application 'DisplayAlerts' = 0.
       free OBJECT application.
    
    
    **  call method of application 'QUIT'.
    **
    **  FREE OBJECT: APPLICATION,
    **               SHEET.
    
    *&---------------------------------------------------------------------*
    *&      Form  fill_cell
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_1      text
    *      -->P_V_COL  text
    *      -->P_ITAB1_LIFNR  text
    *----------------------------------------------------------------------*
    form fill_cell  using row  col val.
    
        CALL METHOD OF sheet 'Cells' = cells EXPORTING #1 = row  #2 = col.
        SET PROPERTY OF cells 'Value' = val.
    
    
    endform.                    " fill_cell

    hope this helps

    Regards

    RItesh

    Edited by: Ritesh Jha on Jul 20, 2009 8:57 AM

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.