Spool to excel file

Hi 
I need to download spool content to excel file in sap script. 
It would be appreciated if any one knows fn module or any other way to solve this.
Thanks
Ragavan.S

CALL FUNCTION 'RSPO_RETURN_ABAP_SPOOLJOB'
    EXPORTING
      rqident              = tsp01-rqident                     "Spool Request Number
      first_line           = 1
    TABLES
      buffer               = it_spool_xls                            "Internal table that will have the Spool Request No data
    EXCEPTIONS
      no_such_job          = 1
      not_abap_list        = 2
      job_contains_no_data = 3
      selection_empty      = 4
      no_permission        = 5
      can_not_access       = 6
      read_error           = 7
      OTHERS               = 8.
CALL FUNCTION 'SO_RAW_TO_RTF'
    TABLES
      objcont_old = it_spool_xls               "Internal table having spool data
      objcont_new = it_xls_spool.           "Int table having Excel format data converted from Spool data
*To convert the excel format data into string
  LOOP AT it_xls_spool.
    CONCATENATE xls_string it_xls_spool INTO xls_string.           "xls_string will have the data as one string
  ENDLOOP. 
*To convert the string into xstring format for mail sending
  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
    EXPORTING
      text           = xls_string                         "String of String data type
  MIMETYPE       = ' '
  ENCODING       =
   IMPORTING
     buffer         = xls_str                             "String of XString data type
   EXCEPTIONS
     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.
*To send mail the xstring having excel format data
  TRY.
    Create persistent send request
      send_request = cl_bcs=>create_persistent( ).
    Create and set document
      pdf_content = cl_document_bcs=>xstring_to_solix( xls_str ).          "String having Excel format
                                                                                "Data above populated
      document = cl_document_bcs=>create_document(
            i_type    = 'XLS'
            i_hex     = pdf_content
            i_length  = pdf_size
            i_subject = 'Asset Origin Details Report' ).    "#EC NOTEXT
    Add document object to send request
      send_request->set_document( document ).
    Add recipient (e-mail address)
    Create recipient object
      recipient = cl_cam_address_bcs=>create_internet_address( p_email ).
    Add recipient object to send request
      send_request->add_recipient( recipient ).
    Send document
      sent_to_all = send_request->send( i_with_error_screen = 'X' ).
      COMMIT WORK.
      IF sent_to_all IS INITIAL.
        MESSAGE i500(sbcoms) WITH p_email.
      ELSE.
        MESSAGE s022(so).
      ENDIF.
  Exception handling
  replace this rudimentary exception handling with your own one
    CATCH cx_bcs INTO bcs_exception.
      MESSAGE i865 (so) WITH bcs_exception->error_type.
  ENDTRY.
Edited by: I.Muthukumar on Jan 28, 2010 8:42 AM

Similar Messages

  • How to download data from spool to excel file

    Hi,
    I have requirement like....i need to download data from spool to excel file.
    Please let me know the process how to download...
    <removed by moderator>
    <removed by moderator>
    Thanks,
    Khasimsa
    Moderator message: please (re)search yourself before asking, do not assign priorities, do not offer re-ward
    locked by: Thomas Zloch on Sep 8, 2010 1:18 PM

    Hi try this way..
    *FM called that returns the Spool Request Number data into and internal table
      CALL FUNCTION 'RSPO_RETURN_ABAP_SPOOLJOB'
        EXPORTING
          rqident              = p_spool                     "Spool Request Number
          first_line           = 1
        TABLES
          buffer               = it_spool_xls                            "Internal table that will have the Spool Request No data
        EXCEPTIONS
          no_such_job          = 1
          not_abap_list        = 2
          job_contains_no_data = 3
          selection_empty      = 4
          no_permission        = 5
          can_not_access       = 6
          read_error           = 7
          OTHERS               = 8.
    *To convert the spool data into excel format
      CALL FUNCTION 'SO_RAW_TO_RTF'
        TABLES
          objcont_old = it_spool_xls               "Internal table having spool data
          objcont_new = it_xls_spool.           "Int table having Excel format data converted from Spool data
    "call GUI down Load by passing  it_xls_spool
    Prabhudas

  • FM to down load the spool to excel file  along with the deliminator

    hi all,
    this is regarding a downloading of spool to a excel file along with a deliminator.
    Can any one suggest a function module which downloads spool to excel file with a deliminator in a proper way.

    Hi ram,
    You can try using the BAPI_XBP_JOB_SPOOLLIST_READ_20 - to get the list from spool and then do the required formatting. You can use can use the function module mentioned in the other reply to download it into excel file.
    Cheers

  • Spool to Excel or Text Conversion

    Dear All,
    Is it possible to convert a spool into Excel file or Text Format?

    Hi
    Check the below links. They wil help you in converting spool to text format.
    [http://www.sap-basis-abap.com/sapac016.htm]
    [http://help.sap.com/saphelp_nw70/helpdata/en/30/cc154219fce12ce10000000a1550b0/content.htm]
    Thanks,
    Jyothi

  • Spool to Excel or Text Conversion thru ABAP

    Dear All,
    Is it possible to convert a spool into Excel file or Text Format thru ABAP?

    Hi!
    The function modules CONVERT_ABAPSPOOLJOB_2_PDF, CONVERT_OTFSPOOLJOB_2_PDF are converting spool to PDF.
    HTH
    Peter

  • How to get Formatted Excel file when downloading spool request of a r paint

    I have scheduled a Report painter program  in background  & spool is generated .
    When I download the output in the Excel file its not in the proper format . We need to format the file file by adding  deleting blank Line in the report .
    Can it be possible when we Download the Report painter. Its come The generated Excel file should come in formatted way.
    Thanks

    kiro123 wrote:
    I have scheduled a Report painter program  in background  & spool is generated .
    >
    > When I download the output in the Excel file its not in the proper format . We need to format the file file by adding  deleting blank Line in the report .
    >
    > Can it be possible when we Download the Report painter. Its come The generated Excel file should come in formatted way.
    >
    >
    > Thanks
    Yes the report painter report especially in the hierarchial format will not make much sense when you download to excel. Until now I also have not seen any solution to this.

  • Generate Excel file Automatically of Spool Ouptut from Spool request

    In 4.6C version how do i code to download Excel file of spool output from its spool request number?

    hi
    please if u know this ans pls send me...........
    but think like this .......
    it will create seperate image for u
    Regards Prasad
    Edited by: EV prasad on Nov 26, 2008 4:55 AM

  • In Adobe Pro XI when converting an excel file to a pdf, the pdf is not retaining the page size settings.  Has anyone found a fix for this?

    In Adobe Pro XI when converting an excel file to a pdf, the pdf is not retaining the page size settings.  Has anyone found a fix for this?

    It shouldn't print each page as a separate job and
    each tab has a different name, so, even if it did, it
    ought to give the printouts the name of the tabs.
    It doesn't print each page as a separate job unless the orientation is different - that's the bug. And the name of the job is taken from the name of the window, not the name of the tabs. That's how every application works, which, I think, is why Excel allows the specific selection or the active sheets to be printed.
    Still, that does sound like a plausible explanation.
    However, even if presented with multiple prints with
    the same name, the spooler should print each one!
    The spooler does print each one - you can watch the spooler process the multiple jobs. I think, though, that they are being overwritten since all the jobs have the name of the window as the job title. And since this happens after the Save Dialog is presented, there's really nothing the application can do. To Excel, it's one job, the multiple orientations don't matter; it's just that Apple doesn't handle it correctly.
    As a workaround, you can print the selections one at a time and give them unique names and then rejoin them in one PDF file.

  • How to get query result in comma dilimited text or excel file?

    Does anybody know how to get query results in comma delimited
    text file or excel file, I tried spool abc.txt, but the result
    showed some ------ lines
    Thanks

    Try doing this in your sql scripts
    set heading off
    set pagesize 0
    set linesize 4000
    set feedback off
    set verify off
    set trimespace on
    set colsep ","
    spool output.txt
    select * from dual (or whatever you are querying
    spool off
    There may be a couple other set statement that you could add but
    this should get you started in the right direction

  • Send email with spool in excel attachment

    Hi,
    I have this function:
    CALL FUNCTION 'Z_SEND_EMAIL_SPOOL_PDF'
           EXPORTING
                application = 'EMAIL'
                emailtitle  = texttitle
                recextnam   = email
                src_spoolid = tsp01-rqident
           TABLES
                texttab     = body.
    And code:
    FUNCTION z_send_email_spool_pdf .
    *"*"Interfase local
    *"  IMPORTING
    *"     REFERENCE(APPLICATION) LIKE  SOOD1-OBJNAM DEFAULT 'EMAIL'
    *"     REFERENCE(EMAILTITLE) LIKE  SOOD1-OBJDES
    *"     VALUE(RECEXTNAM) LIKE  SOOS1-RECEXTNAM
    *"     REFERENCE(SRC_SPOOLID) LIKE  TSP01-RQIDENT
    *"  TABLES
    *"      TEXTTAB STRUCTURE  SOLI
    *- local data declaration
      DATA: ohd    LIKE sood1,
            oid    LIKE soodk,
            to_all LIKE sonv-flag,
            okey   LIKE swotobjid-objkey.
      DATA: g_document     LIKE sood4,
            g_header_data  LIKE sood2,
            g_authority LIKE sofa-usracc,
            lt_attachments LIKE STANDARD TABLE OF sood5 WITH HEADER LINE,
            l_folder_id    LIKE sofdk,
            l_objcont     LIKE soli OCCURS 0 WITH HEADER LINE,
            i_bin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
            l_objhead     LIKE soli OCCURS 0 WITH HEADER LINE,
            folder_id      LIKE soodk,
            object_id      LIKE soodk,
            link_folder_id LIKE soodk,
            hd_dat  LIKE sood1.
      DATA: desired_type  LIKE sood-objtp,
            real_type LIKE sood-objtp,
            attach_type LIKE sood-objtp,
            otf LIKE sood-objtp VALUE 'OTF', " SAPscript Ausgabeformat
            ali LIKE sood-objtp VALUE 'ALI', " ABAP lists
            pdf LIKE sood-objtp VALUE 'PDF', "PDF format
            pbyte TYPE i,
            t_pdf LIKE tline OCCURS 0 WITH HEADER LINE,
            objtype LIKE rststype-type,
            type    LIKE rststype-type.
      CONSTANTS: ou_fol LIKE sofh-folrg              VALUE 'O',
                 c_objtp    LIKE g_document-objtp    VALUE 'RAW',
                 c_file_ext LIKE g_document-file_ext VALUE 'PDF'.
      DATA: BEGIN OF receivers OCCURS 0.
              INCLUDE STRUCTURE soos1.
      DATA: END OF receivers.
    * Fist part: Verify if the spool really exists
      SELECT SINGLE * FROM tsp01 WHERE rqident = src_spoolid.
      CHECK sy-subrc = 0.
    *- fill odh
      CLEAR ohd.
      ohd-objla    = sy-langu.
      ohd-objnam   = application.
      ohd-objdes   = emailtitle.
      ohd-objpri   = 3.
      ohd-objsns   = 'F'.
      ohd-ownnam   = sy-uname.
    *- send Email
      CONDENSE recextnam NO-GAPS.
      CHECK recextnam <> space AND recextnam CS '@'.
      CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
           EXPORTING
                authority     = 'SP01'
                client        = tsp01-rqclient
                name          = tsp01-rqo1name
                part          = 1
           IMPORTING
                type          = type
                objtype       = objtype
           EXCEPTIONS
                fb_error      = 1
                fb_rsts_other = 2
                no_object     = 3
                no_permission = 4
                OTHERS        = 5.
      attach_type = c_objtp.
      desired_type = pdf.
      IF objtype(3) = 'OTF'.
        CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
             EXPORTING
                  src_spoolid   = src_spoolid
             IMPORTING
                  pdf_bytecount = pbyte
             TABLES
                  pdf           = t_pdf.
      ELSE.
        CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
             EXPORTING
                  src_spoolid   = src_spoolid
             IMPORTING
                  pdf_bytecount = pbyte
             TABLES
                  pdf           = t_pdf.
      ENDIF.
      PERFORM convertir_tabla_pdf_2 TABLES t_pdf l_objcont.
      CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
           EXPORTING
                owner     = sy-uname
                region    = ou_fol
           IMPORTING
                folder_id = l_folder_id
           EXCEPTIONS
                OTHERS    = 5.
    * fill out informations about the header of the email
      CLEAR: g_document.
      g_document-foltp     = l_folder_id-foltp.
      g_document-folyr     = l_folder_id-folyr.
      g_document-folno     = l_folder_id-folno.
      g_document-objtp     = c_objtp.
      g_document-objdes    = emailtitle.
      g_document-file_ext  = c_file_ext.
      g_header_data-objdes    = emailtitle.
      CALL FUNCTION 'SO_DOCUMENT_REPOSITORY_MANAGER'
           EXPORTING
                method      = 'SAVE'
                office_user = sy-uname
           IMPORTING
                authority   = g_authority
           TABLES
                objcont     = texttab
                attachments = lt_attachments
           CHANGING
                document    = g_document
                header_data = g_header_data
           EXCEPTIONS
                OTHERS      = 1.
      object_id-objtp = c_objtp.
      object_id-objyr = g_document-objyr.
      object_id-objno = g_document-objno.
      folder_id-objtp = l_folder_id-foltp.
      folder_id-objyr = l_folder_id-folyr.
      folder_id-objno = l_folder_id-folno.
      link_folder_id-objtp = l_folder_id-foltp.
      link_folder_id-objyr = l_folder_id-folyr.
      link_folder_id-objno = l_folder_id-folno.
      hd_dat-file_ext = pdf.
      hd_dat-objdes = emailtitle.
      CALL FUNCTION 'SO_ATTACHMENT_INSERT'
           EXPORTING
                object_id                  = object_id
                attach_type                = attach_type
                object_hd_change           = hd_dat
                owner                      = sy-uname
           TABLES
                objcont                    = l_objcont
                objhead                    = l_objhead
           EXCEPTIONS
                active_user_not_exist      = 35
                communication_failure      = 71
                object_type_not_exist      = 17
                operation_no_authorization = 21
                owner_not_exist            = 22
                parameter_error            = 23
                substitute_not_active      = 31
                substitute_not_defined     = 32
                system_failure             = 72
                x_error                    = 1000.
    *       FORM SO_OBJECT_SEND_REC                                       *
    FORM  so_object_send_rec
          TABLES  objcont      STRUCTURE soli
                  receivers    STRUCTURE soos1
          USING   object_hd    STRUCTURE sood1
                  folder_id
                  object_id
                  link_folder_id.
      DATA:   oid     LIKE soodk,
              to_all  LIKE sonv-flag,
              okey    LIKE swotobjid-objkey.
      CALL FUNCTION 'SO_OBJECT_SEND'
           EXPORTING
                extern_address             = 'X'
    *            object_hd_change           = object_hd
    *            object_type                = 'RAW'
                outbox_flag                = 'X'
                sender                     = sy-uname
                owner                      = sy-uname
                folder_id                  = folder_id
                object_id                  = object_id
                store_flag                 = 'X'
                link_folder_id             = link_folder_id
           IMPORTING
                object_id_new              = oid
                sent_to_all                = to_all
                office_object_key          = okey
           TABLES
                objcont                    = objcont
                receivers                  = receivers
           EXCEPTIONS
                active_user_not_exist      = 1
                communication_failure      = 2
                component_not_available    = 3
                folder_not_exist           = 4
                folder_no_authorization    = 5
                forwarder_not_exist        = 6
                note_not_exist             = 7
                object_not_exist           = 8
                object_not_sent            = 9
                object_no_authorization    = 10
                object_type_not_exist      = 11
                operation_no_authorization = 12
                owner_not_exist            = 13
                parameter_error            = 14
                substitute_not_active      = 15
                substitute_not_defined     = 16
                system_failure             = 17
                too_much_receivers         = 18
                user_not_exist             = 19
                x_error                    = 20
                OTHERS                     = 21.
      IF sy-subrc <> 0.
        RAISE others.
      ENDIF.
    ENDFORM.
    *       FORM INIT_REC                                                 *
    FORM init_rec TABLES receivers STRUCTURE soos1.
      CLEAR receivers.
      REFRESH receivers.
      MOVE sy-datum  TO receivers-rcdat .
      MOVE sy-uzeit  TO receivers-rctim.
      MOVE '1'       TO receivers-sndpri.
      MOVE 'X'       TO receivers-sndex.
      MOVE 'U-'      TO receivers-recnam.
      MOVE 'U'       TO receivers-recesc.
      MOVE 'INT'     TO receivers-sndart.
      MOVE '5'       TO receivers-sortclass.
      APPEND receivers.
    ENDFORM.
    With this function I can send a spool in pdf format by email. But, now I need send a spool in Excel (xls) format by email. I try to disconnect 'CONVERT_OTFSPOOLJOB_2_PDF' and 'CONVERT_ABAPSPOOLJOB_2_PDF' but doesnt work.
    Can you help me?
    A lot of thanks in advance.
    Best regards.

    Hi.
    I do not think it is feasible to create a worthwhile Excel file from a SAP spool file.
    I have reports that send output as Excel attachments to email, but the code (including function modules etc) is too much to post here.
    You can use OLE to create an Excel file, but this will not generally work when the report is run in the background.
    So my approach is to make the report write an Excel XML file (that's just text after all), and send that as an XLS email attachment.  When the email receiver double-clicks on the attachment, it fires up Excel and brings in the data.  Most users would not realise that it's not a native Excel file.
    One nice touch is to have two sheets in the Excel file, one with the main report and the other with the selection criteria.
    Of course there is a lot of work getting started with this.
    John

  • Run report in Backround and Save it automatic as Excel File

    I've created a report program that uses the alv grid. I run it in background, then i want to save it automatic as an excel file.
    can y help me
    Thanks

    Hi,
      When you run a report in background, irespective of the type of report, let it be Normal or ALV report, we have to use JOB FM's, such as JOB_OPEN, JOB_CLOSE. When you run a report in background, the data to be displayed is stored in the spool. So firt, you need to hold the spool data into an internal table, and then pass that internal table to GUI_DOWNLOAD, by hardcoding a path in the local system to download.
    Use this FM to hold the spool output in a internal table , RSPO_RETURN_SPOOLJOB.
    Hope this is helpful to you. If you need further information, revert back.
    Reward all the helpful answers.
    Regards
    Nagaraj T

  • Save ALV report output as excel file in background

    Hi all,
    As the no. of records is huge and the running time is long, I'd like to modify my program to be able to run in background mode with excel as output..
    Is there any method to generate the result list in ALV format and save it as an excel file while running the program in background mode?
    And any limitation?
    Thanks!

    Try to create ALV output to spool in background then try to use any of the below mentioned fm
    SAP_CONVERT_TO_XLS_FORMAT
    MS_EXCEL_OLE_STANDARD_DAT
    RSPO_DOWNLOAD_SPOOLJOB
    RH_START_EXCEL_WITH_DATA
    or
    create CSV using OPEN DATASET & TRANSFER

  • Sending ALV result as Excel file in email and in background mode

    Hello,
    My need was to developp a generic program  to send ALV result in a Excel file by email (as we have already a program to send any spool in PDF format).
    I found package SALV_EXPORT which contains very interesting things.
    I have done a program with following selection-screen parameters:
    - Name of a program to call
    - execution variant linked to this program
    - several output options (mail, save as local file, save on application server...)
      data: g_guid type guid_32.
      data : l_xxml_data  type xstring.
      g_guid = cl_salv_export_db_storage=>create_guid( ).
      export l_mode = 'M' to memory id 'ALV_EXTRACT_MODE'.
      export l_guid = g_guid to memory id 'ALV_EXTRACT_GUID'.
    * call the program with its variant
    submit (p_prog)
        using selection-set p_vari
        and return.
    * Get back the data
      l_xxml_data = cl_salv_export_db_storage=>import_xmlstring( guid  = g_guid ).
    Here, we have a XML data (ALVXML or XML for Excel, i don't know) which is the ALV result with the layout applied (either the alv layout specified on selection-screen of called program or default layout).
    This solution is so simple that i wonder that it's not documented (or i haven't found the documentation).
    If anybody knows any problem with this solution, has anyu remarks or want to add some enhancement, don't hesitate to post..
    Hope this help
    Christophe

    A review of comments in ALV driver code shows references to "Mendocino" which I believe is now called 'Duet". It's part of SAP and Microsoft Office integration suite:
    http://www.sap.com/solutions/duet/index.epx
    I have used this method of extracting ALV reports in the past but I don't think it's released for general use.
    Thanks,
    Abdul Rouhi
    Washington, DC

  • Download an excel file in background mode

    Hi All,
    I need to download a file from a ABAP  report to the local workstation in background mode. I tried GUI_DOWNLOAD but it is failing in the background.
    Is there any way to download the excel file in the background. I am thinking of generating the spool.
    Please let me know if anybody has worked on the same requirement. Any help would be highly appreciated.
    Thanks a lot.
    Regards,
    Priti

    You be able to use the function "WS_DONLOAD" ?
    parameters: p_fnam like  rlgrap-filename memory id fnam obligatory.
    data: begin of t_registro occurs 0,
            registro(1000),
          end of t_registro.
          describe table t_registro lines sy-tfill.
          if sy-tfill gt 0.
            l_tam = strlen( p_fnam ).
            call function 'WS_DOWNLOAD'
                 exporting
                      filename                = p_fnam
                 tables
                      data_tab                = t_registro
                 exceptions
                      file_open_error
                      file_write_error
                      invalid_filesize
                      invalid_type
                      no_batch
                      unknown_error
                      invalid_table_width
                      gui_refuse_filetransfer
                      customer_error.
            if sy-subrc <> 0.
              open dataset p_fnam for output in text mode.
              if sy-subrc = 0.
                loop at t_registro.
                  transfer t_registro to p_fnam.
                endloop.
                close dataset p_fnam.
                write:/ 'Se genero el archivo:', p_fnam(l_tam).
              else.
                write:/ 'No se pudo generar el archivo:', p_fnam(l_tam).
              endif.
              close dataset p_fnam.
            else.
              write:/ 'Se genero el archivo:', p_fnam(l_tam).
            endif.
       endif.
    I hope this works for you.
    See ya.
    Ar@

  • Problem when converting from spool to XLS file

    Hey.
    I need to get table data from the spool and send it by mail in an xls file.
    so this is what i have done:
    I have used the FM 'RSPO_RETURN_ABAP_SPOOLJOB' to get the data table from the spool.
    then i am sending the data table in an xls file via the FM 'SO_DOCUMENT_SEND_API1'.
    the problem is that the xls file that i am getting through the mail is defected.
    All the contents of the spool is located in the first row, first column.
    How can i fix it?
    Thanks, Barak.

    After geting the data in a internal table.from spool......refer this report.....
    data: p_email   type somlreci1-receiver
                                   value 'MAIL ID'.
    data: begin of it001 occurs 0,
          bukrs type t001-bukrs,
          butxt type t001-butxt,
          end of it001.
    data:   imessage type standard table of solisti1 with header line,
            iattach type standard table of solisti1 with header line,
            ipacking_list like sopcklsti1 occurs 0 with header line,
            ireceivers like somlreci1 occurs 0 with header line,
            iattachment like solisti1 occurs 0 with header line.
    start-of-selection.
      select bukrs butxt into table it001 from t001.
      Populate table with detaisl to be entered into .xls file
      perform build_xls_data .
    Populate message body text
      clear imessage.   refresh imessage.
      imessage = 'Please find attached excel file'.
      append imessage.
    Send file by email as .xls speadsheet
      perform send_email_with_xls tables imessage
                                          iattach
                                    using p_email
                                          'Example Excel Attachment'
                                          'XLS'
                                          'TestFileName'
                                          'CompanyCodes'.
         Form  BUILD_XLS_DATA
    form build_xls_data .
    constants: con_cret type x value '0D',  "OK for non Unicode
                con_tab type x value '09'.   "OK for non Unicode
    *If you have Unicode check active in program attributes thnen you will
    *need to declare constants as follows
    *class cl_abap_char_utilities definition load.
    constants:
        con_tab  type c value cl_abap_char_utilities=>horizontal_tab,
        con_cret type c value cl_abap_char_utilities=>cr_lf.
      concatenate 'BUKRS' 'BUTXT'
             into iattach separated by con_tab.
      concatenate con_cret iattach into iattach.
      append  iattach.
      loop at it001 .
        concatenate it001-bukrs it001-butxt
               into iattach separated by con_tab.
        concatenate con_cret iattach  into iattach.
        append  iattach.
      endloop .
    endform.
         Form  SEND_EMAIL_WITH_XLS
    form send_email_with_xls tables pit_message
                                              pit_attach
                                        using p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription.
      data: xdocdata like sodocchgi1,
            xcnt type i.
    Fill the document data.
      xdocdata-doc_size = 1.
    Populate the subject/generic message attributes
      xdocdata-obj_langu = sy-langu .
      xdocdata-obj_name  = 'SAPRPT' .
      xdocdata-obj_descr = p_mtitle .
    Fill the document data and get size of attachment
      clear xdocdata.
      read table iattach index xcnt.
      xdocdata-doc_size =
         ( xcnt - 1 ) * 255 + strlen( iattach ).
      xdocdata-obj_langu  = sy-langu.
      xdocdata-obj_name   = 'SAPRPT'.
      xdocdata-obj_descr  = p_mtitle.
      clear iattachment.  refresh iattachment.
      iattachment[] = pit_attach[].
    Describe the body of the message
      clear ipacking_list.  refresh ipacking_list.
      ipacking_list-transf_bin = space.
      ipacking_list-head_start = 1.
      ipacking_list-head_num = 0.
      ipacking_list-body_start = 1.
      describe table imessage lines ipacking_list-body_num.
      ipacking_list-doc_type = 'RAW'.
      append ipacking_list.
    Create attachment notification
      ipacking_list-transf_bin = 'X'.
      ipacking_list-head_start = 1.
      ipacking_list-head_num   = 1.
      ipacking_list-body_start = 1.
      describe table iattachment lines ipacking_list-body_num.
      ipacking_list-doc_type   =  p_format.
      ipacking_list-obj_descr  =  p_attdescription.
      ipacking_list-obj_name   =  p_filename.
      ipacking_list-doc_size   =  ipacking_list-body_num * 255.
      append ipacking_list.
    Add the recipients email address
      clear ireceivers.  refresh ireceivers.
      ireceivers-receiver = p_email.
      ireceivers-rec_type = 'U'.
      ireceivers-com_type = 'INT'.
      ireceivers-notif_del = 'X'.
      ireceivers-notif_ndel = 'X'.
      append ireceivers.
      call function 'SO_DOCUMENT_SEND_API1'
           exporting
                document_data              = xdocdata
                put_in_outbox              = 'X'
                commit_work                = 'X'
           tables
                packing_list               = ipacking_list
                contents_bin               = iattachment
                contents_txt               = imessage
                receivers                  = ireceivers
           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.
    endform.
    Reward IF.........
    Regards
    Anbu

Maybe you are looking for