Attachment in excel

Hi,
I want to send an excel file as an attachment with the mail.
I am usinf SAP standard Function module SO_NEW_DOCUMENT_ATT_SEND_API1.
I am geting an excel file, but it is not coming in a proper format.
I want it in Tab delimited format.
Thanks
Regards
Neelav

I'm sure Neelav came to some resolution long ago, but I had a different solution and thought I might share it.
Instead of e-mailing tab-delimited spreadsheets, I e-mail .csv files.  An advantage of this format is that double-clicking in MS Outlook causes Excel to open the attachment directly, without any import conversion prompts.
Problem 1 is converting the internal table to .csv format.  I'd loop at the internal table and use this function module to convert each row:
FUNCTION z_csv_from_structure.
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(LR_STRUCT)
*"  EXPORTING
*"     REFERENCE(LW_CSV)
  FIELD-SYMBOLS: <field>.
  DATA: lw_string(1023) TYPE c,
        lw_index LIKE sy-tabix.
* Init.
  CLEAR: lw_csv.
* For each field...
  DO.
    lw_index = sy-index.
*   Capture the first field.
    ASSIGN COMPONENT lw_index OF STRUCTURE lr_struct TO <field>.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
*   Convert to text.
    CLEAR: lw_string.
    WRITE <field> TO lw_string LEFT-JUSTIFIED.
    SHIFT lw_string LEFT DELETING LEADING space.
*   Escape any double quotes in the text.
    WHILE lw_string CS '"'.
      REPLACE '"' WITH '(~~&!!@!!&~~)' INTO lw_string.
    ENDWHILE.
    WHILE lw_string CS '(~~&!!@!!&~~)'.
      REPLACE '(~~&!!@!!&~~)' WITH '""' INTO lw_string.
    ENDWHILE.
*   Encapsulate in double quotes if needed.
    IF lw_string CS ',' OR lw_string CS '"'.
      CONCATENATE '"' lw_string '"' INTO lw_string.
    ENDIF.
*   Comma-separate the values.
    IF lw_index = 1.
      lw_csv = lw_string.
    ELSE.
      CONCATENATE lw_csv lw_string INTO lw_csv SEPARATED BY ','.
    ENDIF.
  ENDDO.                             " for each field.
ENDFUNCTION.
I send the e-mail using SAPOffice function module SO_NEW_DOCUMENT_ATT_SEND_API1.
A challenge of using this function module is that the attached spreadsheet must be passed in a table of 256-character rows.  That's rather narrow.  My work-around is to treat the spreadsheet as a character stream, embed my own end-of-line markers in the stream (hex '0D0A' in non-Unicode systems), and chop the stream into 256-character chunks.  In the e-mail API's attachment packing list, I specify document type 'CSV' and set binary transfer mode = 'X'.
(If binary transfer mode is off, SAP appends an EOL to each line of the table you pass it.  Bad.)
Here's my code for converting one table of .csv lines into another table of 256-character rows.  Note the .csv lines are already EOL-terminated.
  CLEAR: lr_attachment, lt_attachment, lw_buffer, lw_buflen, lw_index.
  IF NOT lt_spreadsheet[] IS INITIAL.
    DESCRIBE TABLE lt_spreadsheet LINES lw_tab_lines.
    WHILE lw_index < lw_tab_lines OR lw_buflen > 0.
      WHILE lw_buflen < lw_linlen AND lw_index < lw_tab_lines.
        ADD 1 TO lw_index.
        READ TABLE lt_spreadsheet INTO lr_spreadsheet INDEX lw_index.
        CONCATENATE lw_buffer lr_spreadsheet INTO lw_buffer.
        lw_buflen = strlen( lw_buffer ).
      ENDWHILE.
      CLEAR: lr_attachment.
      lr_attachment-line = lw_buffer.
      APPEND lr_attachment TO lt_attachment.
      SHIFT lw_buffer LEFT BY lw_linlen PLACES.
      lw_buflen = strlen( lw_buffer ).
    ENDWHILE.
For the rest, see the documentation of the e-mail function module.
Eric

Similar Messages

  • I have a scenario. Import IDOC into PI and PI transform IDOC to Excel. Using mail adapter attach that Excel using pi and send to customer. Can you please help me on the same?

    HI Experts,
    I have a scenario. Import IDOC into PI and PI transform IDOC to Excel. Using mail adapter attach that Excel using pi and send to vendor. Can you please help me on the same?
    Thanks
    SaiSreevastav

    Hi Sai,
    you can use XSLT or java mapping or adapter module to convert IDOC xml to XLS. Please refer the below blog
    Convert incoming XML to Excel or Excel XML – Part 1 - XSLT Way
    Convert incoming XML to Excel Sheet Part 2 – Adapter Module way
    Convert incoming XML to Excel Sheet
    then after converting to Excel, you can use the payloadswap bean in mail adapter
    XI: Sender mail adapter - PayloadSwapBean - Step by step
    regards,
    Harish

  • How to attach a excel or word file when replying to a mail ?

    Hi,
    I am having problem while using safari app.
    When i am to reply to a mail and while replying i am to attach an excel or word file, how should i do it ?

    Doesn't matter what mail it is.  You cannot actually do this on an iPhone.  It is a bit frustrating. The only thing you can attach to a mail message (from within the message itself) is a photo or video.
    You can email all sorts of things from within lots of apps, but you cannot add something to a message.

  • Extension of excel file in email attachment is .excel instead of .xls

    I have concurrent program and I'm trying to use the 'delivery option' to send the output as attachment in email. I defined a rtf template and can open the output from 'Output' button correctly. it can also send mail with attach, but the file name of the attachment is .excel which Excel cannot recognize. My question is , is there any setup to specify the file extension of excel output. I'm sure bursting can work correctly, I just want to try the delivery option. Thanks in advance.

    Please see these links.
    excel output in report builder reports
    http://forums.oracle.com/forums/search.jspa?threadID=&q=excel+AND+XML&objID=f475&dateRange=all&userID=&numResults=15&rankBy=10001
    Thanks,
    Hussein

  • Attaching generated excel file in cfmail

    Hi,
    I've attached the code in which I've generated an excel file
    from my data, which the user can then open/save on their PC. I now
    want to attach this excel file to an email (using cfmail) and send
    it (the task will then become scheduled).
    How do I save rather than output the excel file?
    Katie

    Hi,
    Have a look at the following tags:
    1)
    <cfsavecontent> to generate a variable from your
    tab-delimited content
    <cffile action = "write"> to generate a temp file with
    your content
    <cfmail> and attach that file to your email
    or
    2)
    <cfsavecontent>
    <cfmail>,<cfmailpart> to attach the variable
    directly to the email without creating a temp file first (have not
    tried that myself)
    cheers,
    fober

  • Embed Attachment (Word / Excel / JPG / BMP ) in a Smartform or Adobe PDF ?!

    Hi everybody
    Can we embed an attachment (Word / Excel / JPG / BMP ) in an Adobe PDF Document thro ABAP ?!
    Or
    Can the attachment be embedded in a Smartform and then convert the OTF to PDF ?!
    Appreciate a quick reply !!
    Thanxxx
    Jibu

    That's what I forgot to add to my previous reply. As far as I know, this is not (yet) possible for Smartforms. And what do you mean by Adobe PDF?
    The methods I know for doing this are only available for AIF:
    [Set_attachments|http://help.sap.com/saphelp_nw70/helpdata/EN/46/1bff4c3d034f08e10000000a114a6b/frameset.htm]

  • Internal Table attached as Excel file to an eMail - BCS_EXAMPLE_7 for UC

    Hi forums,
    SAP provided an example report to send out internal tables attached as an Excel file to a recipients eMail address. I attached the coding of the BCS_EXAMPLE_7 programm to this thread.
    report bcs_example_7.
    This report provides an example for sending an Excel
    attachment in Unicode Systems
    constants:
      gc_tab  type c value cl_bcs_convert=>gc_tab,
      gc_crlf type c value cl_bcs_convert=>gc_crlf.
    parameters:
      mailto type ad_smtpadr
       default 'john.doe(a)crazy-company.com'.                    "#EC *
    data send_request   type ref to cl_bcs.
    data document       type ref to cl_document_bcs.
    data recipient      type ref to if_recipient_bcs.
    data bcs_exception  type ref to cx_bcs.
    data main_text      type bcsy_text.
    data binary_content type solix_tab.
    data size           type so_obj_len.
    data sent_to_all    type os_boolean.
    start-of-selection.
      perform create_content.
      perform send.
    *&      Form  send
    form send.
      try.
        -------- create persistent send request ------------------------
          send_request = cl_bcs=>create_persistent( ).
        -------- create and set document with attachment ---------------
        create document object from internal table with text
          append 'Hello world!' to main_text.                   "#EC NOTEXT
          document = cl_document_bcs=>create_document(
            i_type    = 'RAW'
            i_text    = main_text
            i_subject = 'Test Created By BCS_EXAMPLE_7' ).      "#EC NOTEXT
        add the spread sheet as attachment to document object
          document->add_attachment(
            i_attachment_type    = 'xls'                        "#EC NOTEXT
            i_attachment_subject = 'ExampleSpreadSheet'         "#EC NOTEXT
            i_attachment_size    = size
            i_att_content_hex    = binary_content ).
        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( mailto ).
        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 mailto.
          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.
    endform.                    "send
    *&      Form  create_content
    Create Example Content
    1) Write example text into a string
    2) convert this string to solix_tab
    form create_content.
      data lv_string type string.
      data ls_t100 type t100.
    as example content we use some system messages out of t100
    get them for all installed languages from db
    and write one line for each language into the spread sheet
    columns are separated by TAB and each line ends with CRLF
      concatenate 'This Is Just Example Text!'                  "#EC NOTEXT
                  gc_crlf gc_crlf
                  into lv_string.
    header line
      concatenate lv_string
                  'MSGID'    gc_tab
                  'MSGNO'    gc_tab
                  'Language' gc_tab                             "#EC NOTEXT
                  'Text'     gc_crlf                            "#EC NOTEXT
                  into lv_string.
    data lines
      select * from t100 into ls_t100
        where arbgb = 'SO' and msgnr = '182'.
        concatenate lv_string
                    ls_t100-arbgb gc_tab
                    ls_t100-msgnr gc_tab
                    ls_t100-sprsl gc_tab
                    ls_t100-text  gc_crlf
                    into lv_string.
      endselect.
      select * from t100 into ls_t100
        where arbgb = 'SO' and msgnr = '316'.
        concatenate lv_string
                    ls_t100-arbgb gc_tab
                    ls_t100-msgnr gc_tab
                    ls_t100-sprsl gc_tab
                    ls_t100-text  gc_crlf
                    into lv_string.
      endselect.
    convert the text string into UTF-16LE binary data including
    byte-order-mark. Mircosoft Excel prefers these settings
    all this is done by new class cl_bcs_convert (see note 1151257)
      try.
          cl_bcs_convert=>string_to_solix(
            exporting
              iv_string   = lv_string
              iv_codepage = '4103'  "suitable for MS Excel, leave empty
              iv_add_bom  = 'X'     "for other doc types
            importing
              et_solix  = binary_content
              ev_size   = size ).
        catch cx_bcs.
          message e445(so).
      endtry.
    endform.                    "create_content
    NOTES:
    UTF-16LE including the BOM (Byte order mark)
    is preferred by Microsoft Excel. If you want to create
    other binary content you may choose another codepage (e.g.
    '4110' (UTF-8) which is standard for e-mails).
    Find SAP codepage names in the drop down list
    for the codepage setting of node SMTP in transaction SCOT.
    Or: leave iv_codepage and iv_add_bom empty. Then the target
    codepage is set according to SAPconnect settings
    Important:
    SAP neither guarantees that the attachment created
    by this report can be opened by all Excel Versions nor
    that it can be opened by any 3rd party software at all
    Best regards to you
    Thorsten Hüser
    SAP CRM Senior consultant
    arvato / Bertelsmann

    Hi forums,
    SAP provided an example report to send out internal tables attached as an Excel file to a recipients eMail address. I attached the coding of the BCS_EXAMPLE_7 programm to this thread.
    report bcs_example_7.
    This report provides an example for sending an Excel
    attachment in Unicode Systems
    constants:
      gc_tab  type c value cl_bcs_convert=>gc_tab,
      gc_crlf type c value cl_bcs_convert=>gc_crlf.
    parameters:
      mailto type ad_smtpadr
       default 'john.doe(a)crazy-company.com'.                    "#EC *
    data send_request   type ref to cl_bcs.
    data document       type ref to cl_document_bcs.
    data recipient      type ref to if_recipient_bcs.
    data bcs_exception  type ref to cx_bcs.
    data main_text      type bcsy_text.
    data binary_content type solix_tab.
    data size           type so_obj_len.
    data sent_to_all    type os_boolean.
    start-of-selection.
      perform create_content.
      perform send.
    *&      Form  send
    form send.
      try.
        -------- create persistent send request ------------------------
          send_request = cl_bcs=>create_persistent( ).
        -------- create and set document with attachment ---------------
        create document object from internal table with text
          append 'Hello world!' to main_text.                   "#EC NOTEXT
          document = cl_document_bcs=>create_document(
            i_type    = 'RAW'
            i_text    = main_text
            i_subject = 'Test Created By BCS_EXAMPLE_7' ).      "#EC NOTEXT
        add the spread sheet as attachment to document object
          document->add_attachment(
            i_attachment_type    = 'xls'                        "#EC NOTEXT
            i_attachment_subject = 'ExampleSpreadSheet'         "#EC NOTEXT
            i_attachment_size    = size
            i_att_content_hex    = binary_content ).
        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( mailto ).
        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 mailto.
          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.
    endform.                    "send
    *&      Form  create_content
    Create Example Content
    1) Write example text into a string
    2) convert this string to solix_tab
    form create_content.
      data lv_string type string.
      data ls_t100 type t100.
    as example content we use some system messages out of t100
    get them for all installed languages from db
    and write one line for each language into the spread sheet
    columns are separated by TAB and each line ends with CRLF
      concatenate 'This Is Just Example Text!'                  "#EC NOTEXT
                  gc_crlf gc_crlf
                  into lv_string.
    header line
      concatenate lv_string
                  'MSGID'    gc_tab
                  'MSGNO'    gc_tab
                  'Language' gc_tab                             "#EC NOTEXT
                  'Text'     gc_crlf                            "#EC NOTEXT
                  into lv_string.
    data lines
      select * from t100 into ls_t100
        where arbgb = 'SO' and msgnr = '182'.
        concatenate lv_string
                    ls_t100-arbgb gc_tab
                    ls_t100-msgnr gc_tab
                    ls_t100-sprsl gc_tab
                    ls_t100-text  gc_crlf
                    into lv_string.
      endselect.
      select * from t100 into ls_t100
        where arbgb = 'SO' and msgnr = '316'.
        concatenate lv_string
                    ls_t100-arbgb gc_tab
                    ls_t100-msgnr gc_tab
                    ls_t100-sprsl gc_tab
                    ls_t100-text  gc_crlf
                    into lv_string.
      endselect.
    convert the text string into UTF-16LE binary data including
    byte-order-mark. Mircosoft Excel prefers these settings
    all this is done by new class cl_bcs_convert (see note 1151257)
      try.
          cl_bcs_convert=>string_to_solix(
            exporting
              iv_string   = lv_string
              iv_codepage = '4103'  "suitable for MS Excel, leave empty
              iv_add_bom  = 'X'     "for other doc types
            importing
              et_solix  = binary_content
              ev_size   = size ).
        catch cx_bcs.
          message e445(so).
      endtry.
    endform.                    "create_content
    NOTES:
    UTF-16LE including the BOM (Byte order mark)
    is preferred by Microsoft Excel. If you want to create
    other binary content you may choose another codepage (e.g.
    '4110' (UTF-8) which is standard for e-mails).
    Find SAP codepage names in the drop down list
    for the codepage setting of node SMTP in transaction SCOT.
    Or: leave iv_codepage and iv_add_bom empty. Then the target
    codepage is set according to SAPconnect settings
    Important:
    SAP neither guarantees that the attachment created
    by this report can be opened by all Excel Versions nor
    that it can be opened by any 3rd party software at all
    Best regards to you
    Thorsten Hüser
    SAP CRM Senior consultant
    arvato / Bertelsmann

  • Attachment as Excel in a mail -through  HTML

    Hi Guys,
    I have a requirement on sending an Excel as attachment to a mail.
    Basically,the existing program runs for a single record and builds a HTML and sends the information as Mail body in the email.
    Now,they want to run a report which will be multiple/records per customer and they need the same information in the EXCEL sheet for a mail?
    I'm sure we can build a HTML for all the records and attach is as a .txt format.
    But,any idea how complex it is to push it as an EXCEL, with the column names and sizes also to be taken into consideration?
    Please advise n help ..
    Thanks in advance

    Welcome to the forum, please see the FAQ
    {thread:id=2174552}
    Particularly
    {message:id=9360007}
    http://technology.amis.nl/2011/02/19/create-an-excel-file-with-plsql/

  • Attach an Excel File with Email for External Email Address

    Hi,
    I want to send an excel file to an external email address as an attachement.
    I am using the function module SO_NEW_DOCUMENT_ATT_SEND_API1 for sending the email.
    But as far as I know we can only create and send the excel file in this FM. e.g. we can put the text manually and name the file as excel and add it as packing list and send the document.
    Now, my client has a template in excel/word which he wants to send as an attachment always when he sends the mail. I have below Queries:
    1. Where and how do i store the template which is in Excel or word? He doesnt want to upload the template each time he runs the report. Can I save the file on AL11? how do i insert the file in this?
    2. I have tried standard texts, but his template contains a logo. So, I am not sure if that would work. Can I send the template in Binary and just aapend the file extension? xls or doc? would that do?

    Hi,
    See if you can matintain the required templates in document management and use them in your reports.
    Try the link below for reference.
    [Document Management|http://wiki.sdn.sap.com/wiki/display/PLM/Templates-Document+Management]]
    Regards,
    Booma

  • E-mail results as an attachement in excel format

    Hello,
    I have printer MPDF using device type PDF1 and Host Spooll Access Method 'M' for sending e-mails from our SAP 7.0.  We are getting e-mails with file attachments in PDF format from a number of our background jobs set to print to printer MPDF.
    Is there anything similar which can be done to get e-mails in XLS format from a background job? 
    Is there a device type which can do this?
    Is there any way to accomplish this task without ABAP programming?
    Please advise.
    Thanks
    Galina

    It's not feasible without additional development. You would have to either change the program itself or create a "wrapper" program, which would get the output and then send an email with XLS attachment by using a function module, for example. Function modules and all the details may be found on SDN, it has been discussed many times.
    HTML can be imported into Excel - lazy users...

  • How to attach an Excel document with the Workflow notification?

    Hi,
    I need to pass an Excel document through workflow process in several notification nodes. Do you have any demonstration example which shows how to implement it? I found some threads like this, but nobody send me the example. I think I need the example's with Oracle Text and workflow 2.6.3 and an example inside Oracle Collaboration Suite(OCS) Files. Please send these examples to [email protected]
    Thanks a million
    Tulip

    Hi,
    I had the same issue and I found that Oracle Workflow does not attach files. The solution is to create a table with blob, clob, ordsys, etc data types and reference to the file from a notification and a message.
    I did an interface with java to read the document, and then put the link in the oracle workflow message. The link opened the file.
    So, for any workflow development is recomended to use your own Entity-Relation Model, including the process number and the files attached to that process.
    Regards,
    Santiago Meneses
    [email protected]
    Quito-Ecuador

  • Attaching PC Excel File to e-mail

    Hi,
    Is it possible to attach an existing Excel file in the Presentation server to the E-mail?
    If it is poosible Please tell how

    Hi Gayathri,
    Refer to the following link:
    http://sapdev.co.uk/reporting/email/attach_xls.htm
    Hope this helps.
    Reward if helpful.
    Regards,
    Sipra

  • Send Report output as attachment in excel

    Hi All,
    I am scheduling background Job for Auto mail of standard SAP report. I am able to send the details in html format, please guide me how to send report details in excel format.
    I have already check SCN but unable to find exact solution for same.
    Regards
    Rashid

    Rashid,
    When u Go  SM37 Follow This Step Then U Get The Data In Excel Format.
    Follow step
    Select Spool Option
    Then U got the screen
    Select the type option then u got screen.
    In This Screen U Find the option save in Local File  then get the option.
    When U Select the Spreadsheet Option You can Able to save your data in excel format.
    Hope its help full for you

  • Send ALV report as attachment in EXCEL format

    Hi SAP Guru,
    I had a report output as ALV format.
    Currently, when the background job ended, it would be send out to the recipent thru SAPconnect as PDF format using internet mailing address.
    I tried to search for a configuraiton for EXCEL output but there don;t seems to be any option availble.
    I can only choose from PDF/TEXT/HTM/PS in the output document type selection in SOST.
    How can I configure to allow the system to send out the ALV report to my recipent in EXCEL format instead of PDF or HTML?
    Thanks

    Hi,
    By Using OOPS Concept you can send ALV Output as Excel Format by using Class Interface: CL_BCS.
    Do some search on CL_BCS.
    There are some demo Program, sreach for BCS* on SE38.
    Thanks & Regards
    M Nair

  • Got E-mail Attachment (.xls Excel file), then import data to Database

    Dear All,
    I have a project need to do above mention function.
    how to do that automatically ?
    Database is Oracle 10g running on RH AS 4.0 Linux.
    Best regards
    boris

    Dear All,
    Tks for yr reply first,
    My meanings is process it automatically & no need thru client to do that.
    i think the solution as below : -
    1) partner send e-mail to mailbox with attahcment.
    2) software can get a mail then extract attachment & allocation to somewhere folder in db server
    3) execute command for import data from file to database.
    did u know any solution or third party software can do that ?
    best regards
    boris

Maybe you are looking for