Sending an excel spreadsheet attachment on an E-Mail

Afternoon,
Based upon program BCS_EXAMPLE_5 I have created a program that generates an e-mail and creates a spreadsheet attachment. The problem I have is how do get the contents of an internal table into the spreadsheet attachment?
My attempt at resolving the problem has been as follows:-
I have declared a variable document which points to the class cl_document_bcs. I have then instantiated the variable using a static method. I then call the method add_attachment (document->add_attachment) and pass the text content which contains two lines of text.
This creates a spreadsheet will the two lines of text in the first cell.
Could I use the binary content instead? If so how do I declare a variable that has the same type as a work area of binary content because this has a data type of RAW.
Any assistance would be very much appreciated. A copy of my code can be seen below:-
Thanks and regards
John.
REPORT bcs_example_5.
This example shows how to send
  - a simple text provided in an internal table of text lines
  - and an attached MS word document provided in internal table
  - to some internet email address.
All activities done via facade CL_BCS!
DATA: send_request       TYPE REF TO cl_bcs.
DATA: text               TYPE bcsy_text.
DATA: text_content       TYPE soli_tab.
DATA: wa_text_content    TYPE soli.
DATA: binary_content     TYPE solix_tab.
DATA: wa_binary_content  TYPE solix.
DATA: document           TYPE REF TO cl_document_bcs.
DATA: sender             TYPE REF TO cl_sapuser_bcs.
DATA: recipient          TYPE REF TO if_recipient_bcs.
DATA: bcs_exception      TYPE REF TO cx_bcs.
DATA: sent_to_all        TYPE os_boolean.
Data to be included in the spreadsheet
DATA:  text2(100) TYPE c VALUE 'ABC'.
DATA:  int TYPE i VALUE 258.
DATA:  buffer TYPE xstring.
DATA:  conv TYPE REF TO cl_abap_conv_out_ce.
START-OF-SELECTION.
  PERFORM main.
      FORM main                                                     *
FORM main.
  TRY.
    -------- create persistent send request ------------------------
      send_request = cl_bcs=>create_persistent( ).
    -------- create and set document with attachment ---------------
    create document from internal table with text
      APPEND 'Hello world!' TO text.
      document = cl_document_bcs=>create_document(
                      i_type    = 'RAW'
                      i_text    = text
                      i_length  = '12'
                      i_subject = 'test created by BCS_EXAMPLE_5' ).
    add attachment to document
    BCS expects document content here e.g. from document upload
    binary_content = ...
*TRY.
     conv = cl_abap_conv_out_ce=>create(
          encoding                      = 'UTF-8'
          endian                        = 'L'
   REPLACEMENT                   = '#'
   IGNORE_CERR                   = ABAP_FALSE
CATCH CX_PARAMETER_INVALID_RANGE .
CATCH CX_SY_CODEPAGE_CONVERTER_INIT .
**ENDTRY.
     CALL METHOD conv->write( data = text n = 4 ).
     CALL METHOD conv->write( data = int ).
     buffer = conv->get_buffer( ).
      wa_text_content = '1234567890ABCDE'.
      APPEND wa_text_content TO text_content.
      wa_text_content = '1234567890ABCDE'.
      APPEND wa_text_content TO text_content.
      wa_binary_content = buffer.
     APPEND wa_binary_content TO binary_content.
     wa_binary_content = '11111111'.
     APPEND wa_binary_content TO binary_content.
      CALL METHOD document->add_attachment
        EXPORTING
          i_attachment_type    = 'XLS'
          i_attachment_subject = 'c:\temp\book2'
          i_att_content_text   = text_content.
         i_att_content_hex    = binary_content
    add document to send request
      CALL METHOD send_request->set_document( document ).
    --------- set sender -------------------------------------------
    note: this is necessary only if you want to set the sender
          different from actual user (SY-UNAME). Otherwise sender is
          set automatically with actual user.
      sender = cl_sapuser_bcs=>create( sy-uname ).
      CALL METHOD send_request->set_sender
        EXPORTING
          i_sender = sender.
    --------- add recipient (e-mail address) -----------------------
    create recipient - please replace e-mail address !!!
      recipient = cl_cam_address_bcs=>create_internet_address(
                                        '[email protected]' ).
    add recipient with its respective attributes to send request
      CALL METHOD send_request->add_recipient
        EXPORTING
          i_recipient = recipient
          i_express   = 'X'.
    ---------- send document ---------------------------------------
set send immediately flag
      CALL METHOD send_request->set_send_immediately( 'X' ).
      CALL METHOD send_request->send(
        EXPORTING
          i_with_error_screen = 'X'
        RECEIVING
          result              = sent_to_all ).
      IF sent_to_all = 'X'.
        WRITE text-003.
      ENDIF.
      COMMIT WORK.
*                     exception handling
* replace this very rudimentary exception handling
* with your own one !!!
    CATCH cx_bcs INTO bcs_exception.
      WRITE: 'Fehler aufgetreten.'(001).
      WRITE: 'Fehlertyp:'(002), bcs_exception->error_type.
      EXIT.
  ENDTRY.
ENDFORM.                    "main

Hi,
See the Blog..
/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface
Here is the example program to send the EXCEL as a attachment in a email
http://www.erpgenie.com/sap/abap/code/abap58.htm
Regards
Sudheer

Similar Messages

  • Can't open an excel spreadsheet attached to an s-mail - hotmail

    can't open an excel attachment to an e-mail v -- hotmail
    == This happened ==
    Just once or twice
    == only moved to firefox two days ago

    Ok,
    First Rick.
    When I get to the box where the choice of skins are, right
    above it, the choices are:
    Section 508 Compliant Output
    W3C Compliant Topics
    I double checked RoboHelps Help...and it says Robohelp for
    Word 6, Build 99.
    Colum...
    Here's what I did (I 'thought', I'd start off simple, lol)...
    1. Start Robo.
    2. Select New Project.
    3. The left panel contains all of the folders (I think its
    called Explorer).
    The right panel is the default Helpfile word document that
    contains the 'welcome' message.
    4. I added my spreadsheet to the Baggage folder.
    5. Back at the word document, I just added a simple word
    'excel'.
    6. Then I highlighted 'excel', Insert->Hyperlink...and
    pointed it to my excel spreadsheet.
    7. Saved it.
    8. Generated it.
    Everything opens up fine in IE. Excel is highlighted blue and
    underlined. But its not clickable.
    Doug

  • When I tried to send an Excel spreadsheet to my iPad, I got the message "cells outside the boundaries do Numbers".  What does that mean?

    WHen I sent an Excel spreadsheet, I got the message "cells outside the boundaries of Numbers".  What does this mean and how can I get Numbers to work with my spreadsheet?

    The thread on the right side of the page explains what is happening.
    jaxjason wrote:  the cell ranges of numbers are the same os pre-2007 excel. 65,536 rows x 256 columns for each sheet. make sure that you dont have any data outside that range. (you might want to delete all rows beneath your data and to the right to ensure nothing is floating out there, even a cell with a single space). Also check to see if your equations reference entire columns. I had an issue just going from excel 2002 to 2007 with a vlookup that referenced A:D, it saw it returning 1million rows when it only knew how to handle 65k. rewrote it to reference 65536 explicitly and it worked fine. Dont think that will be it, but if Excel messed up with it, Numbers could too. Jason

  • Not able to send pdf file as attachment in my apple mail.

    Hi, I was easily able to attach pdf files to my apple mail.  infact I could just open a pdf file and then send it as attachment in the email earlier. but after downloading and upgrading to os X Mountain lion, I am neither being able to attach and send pdf files in my apple mail, nor can I send PDF file as an attachment.
    Is there any issue with OS X Mountain Lion.
    Issue 1.  I compose Email , then click attach > Browse > select pdf file > click attach > it shows in my Email body either as an icon or as first page of the pdf document > I send it. >>> But when the receipient opens the Email, that pdf attachment is missing. In fact When I put a cc to my self and I open the Email, the attachment is mssing in the incoming E amil.
    Issue 2. I open the PDF document > Click on File > send as attachment in E-Mail > on right, a menu appears where I select the File and click attach> I get a message
    The SendMail doesnot know how to talk to your default mail client. Please select a different mail application to use. Attaching a screen shot.
    I never had these issues earlier with my Lion OS . but since the time I have upgraded to mountain Lion OS, I am having these issues.
    Are these the Mountain Lion issues, how to fix these please.

    I believe, the software team forgot to put a button for send or share as an attachment to preview.

  • Sending Excel as attachment in Email (Unicode)

    Hi,
    I'm using SO_NEW_DOCUMENT_ATT_SEND_API1 FM to send excel attachments as emails to external addresses.
    However, this the SAP upgrade to ECC6.0 from R/3 4.6B
    then I cannot open BIG5 char excel, who does know how to sending Unicode excel as attachment in email.
    the Excel can show Chinese , BIG5 code ,Japanese ,Korea .
    OR which new funciton module in ECC6.0 like SO_NEW_DOCUMENT_ATT_SEND_API1 FM .
    Regards,
    Hank

    Hey,
    try this one.
        lv_string = str_data1.
          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.
            send_request = cl_bcs=>create_persistent( ).
    Now  create document object from internal table with text
    document = cl_document_bcs=>create_document(
              i_type    = 'RAW'
              i_text    = main_text
              i_subject = l_var ).     
           document->add_attachment(
              i_attachment_type    = 'xls'                               i_attachment_subject = ' Details'                      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( abc at abc.com).
           recipient = cl_cam_address_bcs=>create_internet_address( 'abc at abc.com' ).
        add recipient object to send request
            send_request->add_recipient( recipient ).
            sent_to_all = send_request->send( i_with_error_screen = 'X' ).
            COMMIT WORK.
    This will definitely work .if any doubts aask me.
    Neeraj

  • TS1702 Using Numbers app, can't copy excel spreadsheet into Numbers via an attached email document on gmail.  Apple instructions state that an "open in" tab should be available. Can't locate this command. Only "open in Safari" appears.  Using app on iPad.

    USing Numbers app but can't copy excel spreadsheet attached to a gmail email into Numbers. Apple instruction state that you click on opened document and choose option to open in Numbers. Don't have this option, only an option to open in Safari. I need very complete instructions, I'm pretty new to IPad apps. Thanks!

    THanks, but no go.
    when I open spreadsheet attachment, only option is in lower right hand corner-- a box with arrow. When I touch this icon it gives me a choice to open in Safari or Cancel. No white dots.
    PLs be really basic with your response to me. I thought I am pretty computer literate but this has be baffled.
    THanks. I'm sure there is something "simple" that I'm missing.

  • Downloaded office 365 and associated apps onto ipad mini.  How come some excel spreadsheets will not open?

    Some excel spreadsheets attached to my emails will not open on ipad.  I have the excel app with 365 subscription.

    Can you open them in the mail app itself? If you can't open them in the mail app, my assumption would be that they were not properly saved, named or they are just corrupt file. Files with the .xls or .xlsx extension that are properly formatted Excel files, should open in the mail app without the need for any other app. If you want to save and edit the files, then you need a compatible app in which to save them.

  • For one of our users the option to send a document as attachment has dissapeared in office programs such as word, excel etc

    Hi,
    For one of our users the option to send an email as attachment has disappeared in office programs such as word, excel etc
    As you can see from the above these are the normal options you expect to see but for the user affected they get the option to send as a Text document, a pdf or an XPS the option to send as a attachment has gone.
    I have logged into her PC with my account and it was fine, i have had a look and no one else has reported this throughout the company and looking for answers online has proven fruitless.
    Any Ideas on why this option would have changed to only allow the user to send it as text.

    Hi,
    The "Send as Attachment" option only works when Outlook and word are installed from the same suite. That is required.
    Thanks,
    Ethan Hua CHN
    TechNet Community Support

  • Getting "Cannot Insert Object" message while attaching .pdf file to excel spreadsheet.

    While I am trying to attach an adobe (.pdf) file in excel spreadsheet I am getting message as “Cannot Insert Object”.
    I am following the below mentioned steps and getting message as “Cannot Insert Object”.
    Open the adobe (.pdf) file from IE browser.
    While saving the adobe file on local machine it gives warning as “This document does not allow you to save any changes you have made to it unless you are using Adobe Acrobat 9, Pro 9 or Pro Extended 9.  You will only be saving a copy of the original document.  Do you want to continue?” On pressing "OK" it successfully saves the file on my local machine.
    While I Tried to attach the saved adobe file in a spreadsheet of excel it gives message as “Cannot Insert Object”.
    Does any one have any thoughts at all as to how to solve this?

    Deepika,
    The alert dialog your screen shot depicts will only display if there is some kind of form annotation present in a PDF that is not "Reader Enabled".
    Look closer at your 'final' PDF.
    A PDF, not "Reader Enabled", that contains any form annotations will, when opened by Adobe Reader,
    result in the alert dialog that you mention. A "hard wired" default.
    Note that the forms document message bar can be "off" by a selection in Adobe Reader / Acrobat Preferences.
    Select the 'Forms' category. Select "Always hide forms document message bar".
    Be well...

  • Convert SAP spoolOR list to excel and send as an email attachment

    Hello All Masterminds ,
      Iu2019ve developed a utility, in which users has to maintain one u201CZu201D view where they can give any report name, type of attachment (PDF, XLS, TXT) and sender email addresses.u201DNote: thing to remember here is Iu2019m creating XLS,TXT,PDF format dynamicallyu201D 
    It is working fine for PDF. Iu2019m submitting the program and creating spool and converting it to PDF and sending to their emails as an attachment.  It looks fantastic. When Iu2019m doing the same thing for XLS it is showing messy output, I tried many functions and search lots of unanswered, unfinished SDN posts. I almost tried every single clue given in these posts but no luck. Email part is working fine using classes (  l_document = cl_document_bcs=>create_document , l_document->add_attachment , l_send_request->set_document( l_document ).,cl_sapuser_bcs=>create( l_uname ).,l_send_request->add_recipient,  l_send_request->set_send_immediately( '' ).  ) .
    My real deal is to create a beautiful XLS out put. I also tried FMs LIST_FROM_MEMORY and LIST_TO_ASCI but no-luck. I thought instead of spool if I use u201CSubmit  EXPORTING LIST TO MEMORY u201C option may be It works but BIG NO 
       Iu2019m sure some genius out there has done something like his , I ain`t genius that is why I am stuck   Please guys throw me some bones .  As I said, I am able to do most of the things. I need some magic code /answer which turns my messy, ugly unformatted excel sheet attachment to beautiful u201Cpiece of art u201CExcel output.
      Here are the FMs I tried so far with different combinations.
    CALL FUNCTION 'LIST_FROM_MEMORY'
    CALL FUNCTION 'LIST_TO_ASCI'
    CALL FUNCTION 'GUI_DOWNLOAD'
    CALL FUNCTION 'RSPO_DOWNLOAD_SPOOLJOB'
    CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
    CALL FUNCTION 'CONVERT_OTF'
    CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
    And logic like to get rid of things getting in Asci tables
    cl_abap_char_utilities=>newline.
    cl_abap_char_utilities=>horizontal_tab
    cl_abap_char_utilities=>VERTICAL_TAB
    cl_abap_char_utilities=>cr_lf
    FIELD-SYMBOLS: <lfs_table>,    " Internal table structure
                     <lfs_con>.      " Field Content
      DATA: l_text TYPE char1024.     " Text content for mail attachment
      DATA: l_con(50) TYPE c.        " Field Content in character format
    Columns to be tab delimeted
      LOOP AT FINAL ASSIGNING <lfs_table>.
        DO.
          ASSIGN COMPONENT sy-index OF STRUCTURE <lfs_table>
                 TO <lfs_con>.
          IF sy-subrc NE 0.
            CONCATENATE c_cr l_text INTO l_text.
            APPEND l_text TO i_attach.
            EXIT.
          ELSE.
            CLEAR: l_con.
            MOVE <lfs_con> TO l_con.
            CONDENSE l_con.
            IF sy-index = 1.
              CLEAR: l_text.
              MOVE l_con TO l_text.
            ELSE.
              CONCATENATE l_text l_con INTO l_text
                 SEPARATED BY c_tab.
            ENDIF.
          ENDIF.
        ENDDO.
      ENDLOOP.
    Posts : https://forums.sdn.sap.com/click.jspa?searchID=14756211&messageID=4401940
    https://forums.sdn.sap.com/click.jspa?searchID=14756211&messageID=4796657
    https://forums.sdn.sap.com/search.jspa?threadID=&q=convertspoolintoexcelformatforsendingmail&objID=c42&dateRange=all&numResults=30&rankBy=10001
    Will appreciate your help and time.
    Thanks,
    Saquib Khan

    Hi,
    i send excel-att like this.
    REPORT Z_EMAIL_CL_BCS MESSAGE-ID ZZ.
    More examples here BCS_EXAMPLE_* with se38
    DATA: SEND_REQUEST       TYPE REF TO CL_BCS.
    DATA: SUBJECT            TYPE SO_OBJ_DES.
    DATA: ATT_TYPE           TYPE SOODK-OBJTP.
    DATA: IT_TEXT            TYPE BCSY_TEXT.
    DATA: WA_TEXT            LIKE SOLI.
    DATA: IT_BIN             TYPE SOLIX_TAB.
    DATA: WA_BIN             TYPE SOLIX.
    DATA: DOCUMENT           TYPE REF TO CL_DOCUMENT_BCS.
    DATA: SENDER             TYPE REF TO CL_SAPUSER_BCS.
    DATA: RECIPIENT          TYPE REF TO IF_RECIPIENT_BCS.
    DATA: BCS_EXCEPTION      TYPE REF TO CX_BCS.
    DATA: SENT_TO_ALL        TYPE OS_BOOLEAN.
    Bytes der Datei
    DATA: IT_LENGHT          TYPE SO_OBJ_LEN.
    DATA: N10(10)            TYPE N.
    CONSTANTS: CON_NEWL TYPE ABAP_CHAR1 VALUE CL_ABAP_CHAR_UTILITIES=>NEWLINE,
               CON_TAB  TYPE ABAP_CHAR1 VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    CONSTANTS: CON_NEWL TYPE X VALUE '0D', "OK for non Unicode
                CON_TAB  TYPE X VALUE '09'. "OK for non Unicode
    START-OF-SELECTION.
      PERFORM MAIN.
    END-OF-SELECTION.
    FORM MAIN.
      TRY.
        -------- create persistent send request ------------------------
          SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).
          PERFORM HEAD_CONT.
          PERFORM XLS_ATT.
        add document to send request
          CALL METHOD SEND_REQUEST->SET_DOCUMENT( DOCUMENT ).
        --------- set sender -------------------------------------------
          SENDER = CL_SAPUSER_BCS=>CREATE( SY-UNAME ).
          CALL METHOD SEND_REQUEST->SET_SENDER
            EXPORTING
              I_SENDER = SENDER.
        --------- set recipent -----------------------------------------
          RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS(
                                            'the email adress' ).
        add recipient with its respective attributes to send request
          CALL METHOD SEND_REQUEST->ADD_RECIPIENT
            EXPORTING
              I_RECIPIENT = RECIPIENT
              I_EXPRESS   = 'X'.
         RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS(
                                           'the email adress 2' ).
        add recipient with its respective attributes to send request
         CALL METHOD SEND_REQUEST->ADD_RECIPIENT
           EXPORTING
             I_RECIPIENT = RECIPIENT
             I_EXPRESS   = 'X'.
        ---------- send document ---------------------------------------
          CALL METHOD SEND_REQUEST->SEND(
            EXPORTING
              I_WITH_ERROR_SCREEN = 'X'
            RECEIVING
              RESULT              = SENT_TO_ALL ).
          COMMIT WORK.
        CATCH CX_BCS INTO BCS_EXCEPTION.
          WRITE: 'Fehler aufgetreten.'(001).
          WRITE: 'Fehlertyp:'(002), BCS_EXCEPTION->ERROR_TYPE.
          EXIT.
      ENDTRY.
    ENDFORM.                    "main
    FORM HEAD_CONT.
      CLEAR: IT_TEXT[], WA_TEXT, SUBJECT.
      ATT_TYPE = 'RAW'.
      CONCATENATE 'Betreffzeile am' SY-DATUM 'um' SY-UZEIT
      INTO SUBJECT SEPARATED BY SPACE.
      WA_TEXT = 'Hello!'.
      APPEND WA_TEXT TO IT_TEXT.
    WA_TEXT = 'dieses ist eine Testmail'.
    APPEND WA_TEXT TO IT_TEXT.
    WA_TEXT = 'Gruß'.
    APPEND WA_TEXT TO IT_TEXT.
      DESCRIBE TABLE IT_TEXT LINES N10.
      N10 = ( N10 - 1 ) * 255 + STRLEN( WA_TEXT ).
      IT_LENGHT = N10.
      DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
                I_TYPE    = ATT_TYPE
                I_TEXT    = IT_TEXT
                I_LENGTH  = IT_LENGHT
                I_SUBJECT = SUBJECT ).
    ENDFORM.                    "HEAD_CONT
    FORM XLS_ATT.
      DATA: BEGIN OF ITAB OCCURS 0,
            MATNR     LIKE MARA-MATNR,
            MTART     LIKE MARA-MTART,
            MATKL     LIKE MARA-MATKL,
            BRGEW     LIKE MARA-BRGEW,
          END   OF ITAB.
      DATA: BRGEW(18).
      CLEAR: IT_BIN[], WA_BIN, SUBJECT.
      SELECT MATNR MTART MATKL BRGEW INTO TABLE ITAB FROM MARA UP TO 10 ROWS.
      CONCATENATE 'Material'      CON_TAB
            'Materialart'   CON_TAB
            'Warengruppe'   CON_TAB
            'Bruttogewicht' CON_NEWL
              INTO WA_BIN.
      APPEND WA_BIN TO IT_BIN.
      LOOP AT ITAB.
        WRITE ITAB-BRGEW TO BRGEW.
        CONCATENATE ITAB-MATNR CON_TAB
                    ITAB-MTART CON_TAB
                    ITAB-MATKL CON_TAB
                         BRGEW CON_NEWL
                    INTO WA_BIN.
        APPEND WA_BIN TO IT_BIN.
      ENDLOOP.
      ATT_TYPE = 'XLS'.
      SUBJECT = 'My XLS attachment'.
      DESCRIBE TABLE IT_BIN LINES N10.
      N10 = ( N10 - 1 ) * 255 + STRLEN( WA_BIN ).
      IT_LENGHT = N10.
      CALL METHOD DOCUMENT->ADD_ATTACHMENT
        EXPORTING
          I_ATTACHMENT_TYPE    = ATT_TYPE
          I_ATT_CONTENT_HEX    = IT_BIN
          I_ATTACHMENT_SIZE    = IT_LENGHT
          I_ATTACHMENT_SUBJECT = SUBJECT.
    ENDFORM.                    "XLS_ATT
    Perhaps it helps.
    regards, Dieter

  • To Send HTML Format and excel file attachment  in same mail

    Dear All,
            Have requerment ,to send a mail options HTML table format and same data in excel file attachement.have capable to do the html format using methods BCS .but how to send excel format attachment in same  mail.
    Please guide me how to do it.
    Regards ,
    Santhu
    Edited by: santosh jajur on Apr 9, 2010 1:54 PM

    Santhosh,
    please check the code:
    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 'ur mail id'.                    "#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.
      try.
          send_request = cl_bcs=>create_persistent( ).
        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.
      endtry.
    endform.                    "send
    form create_content.
      data lv_string type string.
      data ls_t100 type t100.
    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.
      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
    Thanks.

  • Sending an Excel Attachment in E-mail, where linesize 255 characters

    Hi,
    I have a requirement where I need to send an Excel attachment of around 150 columns and the line-size is around 2000 characters.
    I was planning to use SO_DOCUMENT_SEND_API1.
    But, it appears that because of the restriction of 255 characters as SOLISTI1 structure has the field size of 255 characters.
    Please note, I cannot use any of the OLE or foreground Excel functions, as the job runs in the background.
    Please let me know if you have any solutions or work around.
    Hoiping to hear from all of the experts out there.
    Regards,
    Ani

    try to use the following classes :       
    send_request  TYPE REF TO cl_bcs,
            document      TYPE REF TO cl_document_bcs,
            conlengths    TYPE        so_obj_len,
            html          TYPE STANDARD TABLE OF w3html,
            sender_id     TYPE REF TO if_sender_bcs,
            recipient     TYPE REF TO if_recipient_bcs,
            sent_to_all   TYPE        os_boolean,
            bcs_exception TYPE REF TO cx_bcs,
            bcs_message   TYPE        string.

  • Send Excel as attachment in Email

    Hi,
    I have an excel file attached as the original to a DIR.
    I want to send this excel file as an attachment in the external email.
    I am retrieving the data contents of original file in binary format using CVAPI_DOC_CHECKOUTVIEW
    Then I am converting binary to text using SCMS_BINARY_TO_TEXT
    and then sending the email with the data file as attachment using SO_DOCUMENT_SEND_API1.
    However, this attachment does not open when its type is .xls
    It does open with .txt, but the file is distorted and in non-understanable format.
    Regards,
    Reema

    hi,
    Check this Out...
    REPORT  ZEMAIL_ATTACH                   .
    TABLES: ekko.
    PARAMETERS: p_email   TYPE somlreci1-receiver
                                      DEFAULT '[email protected]'.
    TYPES: BEGIN OF t_ekpo,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
      aedat TYPE ekpo-aedat,
      matnr TYPE ekpo-matnr,
    END OF t_ekpo.
    DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,
          wa_ekpo TYPE t_ekpo.
    TYPES: BEGIN OF t_charekpo,
      ebeln(10) TYPE c,
      ebelp(5)  TYPE c,
      aedat(8)  TYPE c,
      matnr(18) TYPE c,
    END OF t_charekpo.
    DATA: wa_charekpo TYPE t_charekpo.
    DATA:   it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                    WITH HEADER LINE.
    DATA:   it_attach TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
                    WITH HEADER LINE.
    DATA:   t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
            t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
            t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
            t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
            t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
            w_cnt TYPE i,
            w_sent_all(1) TYPE c,
            w_doc_data LIKE sodocchgi1,
            gd_error    TYPE sy-subrc,
            gd_reciever TYPE sy-subrc.
    *START_OF_SELECTION
    START-OF-SELECTION.
      Retrieve sample data from table ekpo
      PERFORM data_retrieval.
      Populate table with detaisl to be entered into .xls file
      PERFORM build_xls_data_table.
    *END-OF-SELECTION
    END-OF-SELECTION.
    Populate message body text
      perform populate_email_message_body.
    Send file by email as .xls speadsheet
      PERFORM send_file_as_email_attachment
                                   tables it_message
                                          it_attach
                                    using p_email
                                          'Example .xls documnet attachment'
                                          'XLS'
                                          'filename'
                                 changing gd_error
                                          gd_reciever.
      Instructs mail send program for SAPCONNECT to send email(rsconn01)
      PERFORM initiate_mail_execute_program.
    *&      Form  DATA_RETRIEVAL
          Retrieve data form EKPO table and populate itab it_ekko
    FORM data_retrieval.
      SELECT ebeln ebelp aedat matnr
       UP TO 10 ROWS
        FROM ekpo
        INTO TABLE it_ekpo.
    ENDFORM.                    " DATA_RETRIEVAL
    *&      Form  BUILD_XLS_DATA_TABLE
          Build data table for .xls document
    FORM build_xls_data_table.
      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 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
             INTO it_attach SEPARATED BY con_tab.
      CONCATENATE con_cret it_attach  INTO it_attach.
      APPEND  it_attach.
      LOOP AT it_ekpo INTO wa_charekpo.
        CONCATENATE wa_charekpo-ebeln wa_charekpo-ebelp
                    wa_charekpo-aedat wa_charekpo-matnr
               INTO it_attach SEPARATED BY con_tab.
        CONCATENATE con_cret it_attach  INTO it_attach.
        APPEND  it_attach.
      ENDLOOP.
    ENDFORM.                    " BUILD_XLS_DATA_TABLE
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
          Send email
    FORM send_file_as_email_attachment tables pit_message
                                              pit_attach
                                        using p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription
                                              p_sender_address
                                              p_sender_addres_type
                                     changing p_error
                                              p_reciever.
      DATA: ld_error    TYPE sy-subrc,
            ld_reciever TYPE sy-subrc,
            ld_mtitle LIKE sodocchgi1-obj_descr,
            ld_email LIKE  somlreci1-receiver,
            ld_format TYPE  so_obj_tp ,
            ld_attdescription TYPE  so_obj_nam ,
            ld_attfilename TYPE  so_obj_des ,
            ld_sender_address LIKE  soextreci1-receiver,
            ld_sender_address_type LIKE  soextreci1-adr_typ,
            ld_receiver LIKE  sy-subrc.
      ld_email   = p_email.
      ld_mtitle = p_mtitle.
      ld_format              = p_format.
      ld_attdescription      = p_attdescription.
      ld_attfilename         = p_filename.
      ld_sender_address      = p_sender_address.
      ld_sender_address_type = p_sender_addres_type.
    Fill the document data.
      w_doc_data-doc_size = 1.
    Populate the subject/generic message attributes
      w_doc_data-obj_langu = sy-langu.
      w_doc_data-obj_name  = 'SAPRPT'.
      w_doc_data-obj_descr = ld_mtitle .
      w_doc_data-sensitivty = 'F'.
    Fill the document data and get size of attachment
      CLEAR w_doc_data.
      READ TABLE it_attach INDEX w_cnt.
      w_doc_data-doc_size =
         ( w_cnt - 1 ) * 255 + STRLEN( it_attach ).
      w_doc_data-obj_langu  = sy-langu.
      w_doc_data-obj_name   = 'SAPRPT'.
      w_doc_data-obj_descr  = ld_mtitle.
      w_doc_data-sensitivty = 'F'.
      CLEAR t_attachment.
      REFRESH t_attachment.
      t_attachment[] = pit_attach[].
    Describe the body of the message
      CLEAR t_packing_list.
      REFRESH t_packing_list.
      t_packing_list-transf_bin = space.
      t_packing_list-head_start = 1.
      t_packing_list-head_num = 0.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE it_message LINES t_packing_list-body_num.
      t_packing_list-doc_type = 'RAW'.
      APPEND t_packing_list.
    Create attachment notification
      t_packing_list-transf_bin = 'X'.
      t_packing_list-head_start = 1.
      t_packing_list-head_num   = 1.
      t_packing_list-body_start = 1.
      DESCRIBE TABLE t_attachment LINES t_packing_list-body_num.
      t_packing_list-doc_type   =  ld_format.
      t_packing_list-obj_descr  =  ld_attdescription.
      t_packing_list-obj_name   =  ld_attfilename.
      t_packing_list-doc_size   =  t_packing_list-body_num * 255.
      APPEND t_packing_list.
    Add the recipients email address
      CLEAR t_receivers.
      REFRESH t_receivers.
      t_receivers-receiver = ld_email.
      t_receivers-rec_type = 'U'.
      t_receivers-com_type = 'INT'.
      t_receivers-notif_del = 'X'.
      t_receivers-notif_ndel = 'X'.
      APPEND t_receivers.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
           EXPORTING
                document_data              = w_doc_data
                put_in_outbox              = 'X'
                sender_address             = ld_sender_address
                sender_address_type        = ld_sender_address_type
                commit_work                = 'X'
           IMPORTING
                sent_to_all                = w_sent_all
           TABLES
                packing_list               = t_packing_list
                contents_bin               = t_attachment
                contents_txt               = it_message
                receivers                  = t_receivers
           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.
    Populate zerror return code
      ld_error = sy-subrc.
    Populate zreceiver return code
      LOOP AT t_receivers.
        ld_receiver = t_receivers-retrn_code.
      ENDLOOP.
    ENDFORM.
    *&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
          Instructs mail send program for SAPCONNECT to send email.
    FORM initiate_mail_execute_program.
      WAIT UP TO 2 SECONDS.
      SUBMIT rsconn01 WITH mode = 'INT'
                    WITH output = 'X'
                    AND RETURN.
    ENDFORM.                    " INITIATE_MAIL_EXECUTE_PROGRAM
    *&      Form  POPULATE_EMAIL_MESSAGE_BODY
           Populate message body text
    form populate_email_message_body.
      REFRESH it_message.
      it_message = 'Please find attached a list test ekpo records'.
      APPEND it_message.
    endform.                    " POPULATE_EMAIL_MESSAGE_BODY
    Regards,
    Santosh

  • Send Excel as attachment with colors in coloums

    Hi,
    I need to send Excel as attachment and some particular columns should be coloured.
    I am sending Excel attachment using FM SO_DOCUMENT_SEND_API1 when report executed in foreground.
    Please help how to make columns coloured.
    Thanks,
    Phani

    hi,
    This report demonstrates how to send some ABAP data to an EXCEL sheet using OLE automation by this it makes EXCEL columns colorful.
    TYPE-POOLS OLE2 .
    * 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-DATUM+6(2) '_' SY-DATUM+4(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.

  • I cannot open files attached to an excel spreadsheet. I am using office for mac 2011. when double clicking object I only get the picture modifier windows.

    I cannot open files attached to an excel spreadsheet. I am using office for mac 2011. when double clicking object I only get the picture modifier windows.

    Preventing Microsoft Office to open recent documents at startup in Mac OS, Please see:
    http://www.frenchguys.com/wordpress/preventing-microsoft-office-open-documents-startup-mac-os-lion/
    It seems that the solution works for most people.
    In a terminal, enter the following:
     defaults write com.microsoft.Excel NSQuitAlwaysKeepsWindows -bool false

Maybe you are looking for

  • Cost Run should not be getting executed on Material with Price Control V

    Raw & Packing materials are with price control V in MM as company wants to keep them on moving average cost. Somehow finance users executed cost run on one such material and cost run was executed and the difference was posted in price difference. As

  • CO_TXT_OUTBINDING_NOT_FOUND

    I need your help on Idoc-to-file scenario using Business Service with Party.  My Problem is that the Receiver Interface and Receiver Namespace in SXMB_MONI appear same as that of senders and the message goes into the error condition "CO_TXT_OUTBINDIN

  • Org Level Roles / Authorization Object Roles

    Hi board, I have heard of the concept to use roles with "Organizational Values" only and no other authorization values contained. Similar the idea to exclude special authorization objects from common roles and combine them in dedicated special ones t

  • I can't access my emails, but my wife can.

    Hi there, We've had a MacBook Pro for 2 years (primarily my wife's, but I share it). My wife and I both have an inbox account. For the last 2 days, I've not been able to receive any NEW emails. I get them on my iphone, but not on her laptop. She, on

  • Real time integration of controlling with financial accounting

    Hi friends, Can any one please explain the concept and as well as provide the configuration guide. Thanks & Regards T N R