Excel attachment in email

Hi Friends,
I'm using FM SO_NEW_DOCUMENT_ATT_SEND_API1, to send my internal table contents as excel attachment via e-mail. I'm receiving the xls attachment via e-mail.  I'm using cl_abap_char_utilities=>newline to pass internal table contents line by line. This is working fine.
But from second line onwards, the lines are right aligned. For eg. contents_bin-line is 255 character length. If the internal table line is just 100 characters, it is leaving the 1st 155 character space and starting from 101st caharacter space. I need the line to start from 1st character space.
How shall i do this?..
Please help me on this.
Regards,
Subbu.

Hi ,
Use class  cl_abap_char_utilities=>cr_lf  as shown below .
CONSTANTS: c_cret TYPE c VALUE cl_abap_char_utilities=>cr_lf . " for carriage return
You can use  class CL_BCS  also for sending attachment thr mail.(Optional)
Regards
Chetan

Similar Messages

  • EXCEL attachment as EMAIL to USER - When USER executes REPORT in BACKGROUND

    Hi Friends,
    I have 10 records in Internal Table. In BACK GROUND execution, I have to send this 10 records as EXCEL attachment through EMAIL to the USER who executed in background.
    How to do this? Thanks in advance.
    Regards,
    Viji.

    hi,
    the following excerpt converts to excel:
    REPORT ZEX_DATATOEXCEL .
    Parameters: P_file like RLGRAP-FILENAME.
    data : begin of int_head occurs 0,
    Filed1(20) type c,                     " Header Data
    end of int_head.
    data : begin of int_data occurs 0,
    Field1(20) type c,                     " Data
    Field2(20) type c,
    Field3(20) type c,
    Field4(20) type c,
    end of int_data.
    int_head-Filed1 = 'Sales Ord'.
    APPEND int_head.
    CLEAR  int_head.
    int_head-Filed1 = 'Sold-to-Party'.
    APPEND int_head.
    CLEAR  int_head.
    int_head-Filed1 = 'Purchase Ord'.
    APPEND int_head.
    CLEAR  int_head.
    int_head-Filed1 = 'Ship-to-Party'.
    APPEND int_head.
    CLEAR  int_head.
    int_data-field1 = '1JOHN'.
    int_data-field2 = '2TOM'.
    int_data-field3 = '3BRAD'.
    int_data-field4 = '4PETER'.
    Append int_data.
    Clear int_data.
    CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
    EXPORTING
    file_name = p_file " path offile where u need to download
    * CREATE_PIVOT = 0
    * DATA_SHEET_NAME = ' '
    * PIVOT_SHEET_NAME = ' '
    * PASSWORD = ' '
    * PASSWORD_OPTION = 0
    TABLES
    * PIVOT_FIELD_TAB =
    data_tab = int_data "internal table with data
    fieldnames = int_head "internal table with header
    EXCEPTIONS
    file_not_exist = 1
    filename_expected = 2
    communication_error = 3
    ole_object_method_error = 4
    ole_object_property_error = 5
    invalid_filename = 6
    invalid_pivot_fields = 7
    download_problem = 8
    OTHERS = 9
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    got it from
    http://abaplovers.blogspot.com/2008/05/abap-internal-table-to-excel-sheet.html.
    then you can export to spool and mail it.
    ags.

  • IOS4.0.2 won't open excel attachment from email

    I can open the PDF file, but not the excel file. When I click on the .xls attachment from my email, it brought me to the home screen. Does anyone know what I need to setup in order to be able to view the excel file?

    Motion can't find a framework it needs in order to launch. That could be because the framework is missing or because permissions are set incorrectly.
    To fix this problem, try repairing permissions. If that doesn't work, reinstall Final Cut Studio or copy the file /System/Library/PrivateFrameworks/Helium.framework/Frameworks/HeliumRender.fram ework/Versions/A/HeliumRender from another computer with the SAME version of Final Cut Studio. Then repair permissions again.

  • How do I save excel attachment from email

    Hello... My received email attachment is an excel file but read as PDF format when opened from my iPad. Do i need Iwork apps to save it as excel file or is there any other way I can do it.

    You use apps to do this. Look at Documents to Go, or Office2HD. Used with the superb free Cloud service Dropbox either of these will work for you.
    In the email, you can just 'Open with ...' (one of the apps) and then save either locally or to Dropbox which will sync the file to all your laptops and desktops too.

  • Excel Attachment via Email into PI

    I have a shipping partner that says they can only email me a large Excel file for the requested delivery information (for R3 update).  I want to have the entire process automated. 
    I have seen a couple threads concerning using Conversion Agent or a writing a java module in order to parse an Excel document.  But from what I have seen in blog 1967, doing it with Java for a large Excel file seems like it would be a large pain.
    Any suggestions or recommendations (Java module versus Conversion Agent or other)?
    Thanks,
    Keith

    Hi Keith !
    It depends on the complexity of the excel file itself, and also on the availability of the conversion agent tool and the knowledge in java development. Using Conversion Agent you will need almost none development (depending on the sheet).
    Also another idea could be, that if the sender uses Excel, the also can export the file as CSV or XML, allowing  you to read it from a standard adapter into XI.
    Regards,
    Matias
    ps: please award points if helpful.

  • SSRS report through data subscription - Connect to 2 different SQL server DB for excel attachment in EMail Deliery

    I need to connect to 2 different SQL server without creating linked server for generating report. Is it possible in SSRS 2008 report service?

    Yes possible
    You would just required created two data sources which points to both your SQL Servers. And inside report you can create datasets based on each of these data sources to retrieve and display the data from them. In cases where you would require merging the
    data from both the systems you can use functions like Lookup, LookupSet etc. Reports created in SSRS can be rendered in a variety of formats like Excel, PDF, CSV etc
    see
    http://www.allaboutmssql.com/2013/08/ssrs-example-for-lookup-lookupset-and.html
    http://www.sqlcircuit.com/2012/03/ssrs-2008-r2-lookup-how-to-use-multiple.html
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Email Excel attachment with a BOLD row

    hi!
    My requirement is that data in an internal table should be sent as an attachment in an email. There are a few records in the internal table which needs to be in bold(i have the logic to figure out whichones). I am using the below FM  .
    CALL FUNCTION 'SO_OBJECT_SEND'
       EXPORTING
         object_hd_change                 = wa_object_hd
         object_type                       = 'RAW'
       TABLES
         objcont                          = i_text
         receivers                        = i_recv
         packing_list                     = i_packing_list
         att_cont                         = i_att
    Does any body have any idea how to bold a few records in the excel attachment?
    I appreciate your suggestions.
    Thanks,
    manasa
    Message was edited by:
            manasa

    Hi Manasa,
    The Code below is for sending Excel attachment in email. Not sure for BOLD...
    You can copy and paste the following codes and execute..
    Hope this will help you..
    TYPE-POOLS: truxs.
    DATA t5 LIKE t005t OCCURS 0 WITH HEADER LINE.
    START-OF-SELECTION.
    SELECT * INTO TABLE t5
    FROM t005t
    WHERE spras = sy-langu.
    DATA wa_data TYPE truxs_t_text_data.
    CALL FUNCTION 'SAP_CONVERT_TO_TXT_FORMAT'
    EXPORTING
    i_line_header = 'X'
    TABLES
    i_tab_sap_data = t5
    CHANGING
    i_tab_converted_data = wa_data
    EXCEPTIONS
    conversion_failed = 1
    OTHERS = 2.
    DATA stmp(4096) TYPE c.
    DATA itmp TYPE i.
    LOOP AT wa_data INTO stmp.
    itmp = STRLEN( stmp ).
    stmp+itmp = cl_abap_char_utilities=>cr_lf.
    MODIFY wa_data FROM stmp.
    ENDLOOP.
    PERFORM send_email.
    *& Form send_email
    FORM send_email .
    DATA docs LIKE docs OCCURS 0 WITH HEADER LINE.
    DATA excelsize TYPE i.
    DATA excel LIKE solisti1 OCCURS 0 WITH HEADER LINE.
    DATA doc LIKE sodocchgi1.
    DATA excelln TYPE i.
    DATA int_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
    DATA int_objhead LIKE solisti1 OCCURS 2 WITH HEADER LINE.
    DATA int_objtext LIKE solisti1 OCCURS 0 WITH HEADER LINE.
    DATA int_reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.
    DATA bodyln LIKE sy-tabix.
    DATA output_data TYPE ssfcrescl.
    excel[] = wa_data[].
    excel table sizes
    DESCRIBE TABLE excel LINES excelln.
    Body Email
    int_objtext-line = 'Test Body'.
    APPEND int_objtext.
    DESCRIBE TABLE int_objtext LINES bodyln.
    READ TABLE int_objtext INDEX bodyln.
    CLEAR doc.
    doc-doc_size = ( bodyln - 1 ) * 255 + STRLEN( int_objtext ).
    doc-obj_name = ' '.
    doc-sensitivty = 'P'.
    doc-proc_syst = sy-sysid.
    doc-proc_clint = sy-mandt.
    CLEAR: int_objpack, int_objpack[].
    int_objpack-transf_bin = ' '.
    int_objpack-head_start = 1.
    int_objpack-head_num = 0.
    int_objpack-body_start = 1.
    int_objpack-body_num = bodyln.
    int_objpack-doc_type = 'RAW'.
    int_objpack-obj_descr = 'Test'.
    APPEND int_objpack.
    CLEAR: int_objhead, int_objhead[].
    int_objhead = 'Attachment'.
    APPEND int_objhead.
    int_objpack-transf_bin = 'X'.
    int_objpack-head_start = 1.
    int_objpack-head_num = 0.
    int_objpack-body_start = 1.
    int_objpack-body_num = excelln.
    int_objpack-doc_size = excelsize.
    int_objpack-doc_type = 'XLS'.
    int_objpack-obj_name = 'excel'.
    int_objpack-obj_descr = 'test.xls'. "File name
    APPEND int_objpack.
    Set Receiver
    int_reclist-receiver = 'SAPUSER'.
    int_reclist-rec_type = 'B'.
    int_reclist-notif_del = 'X'.
    int_reclist-notif_read = 'X'.
    int_reclist-notif_ndel = 'X'.
    int_reclist-express = 'X'.
    APPEND int_reclist.
    doc-obj_descr = 'Report in Excel'.
    Sending Email
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
    document_data = doc
    put_in_outbox = 'X'
    commit_work = 'X'
    TABLES
    packing_list = int_objpack
    object_header = int_objhead
    contents_bin = excel
    contents_txt = int_objtext "Body
    receivers = int_reclist
    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. " send_email
    Note:
    - If you are using FM SAP_CONVERT_TO_TXT_FORMAT you will not be able to execute this program in the background.
    - dont forget to change 'SAPUSER' to your SAP user ID
    - you can check the email by using tcode 'SBWP'.
    Reward points if this Helps.
    Manish

  • Email with excel attached

    Hello,
    I have to send an email in a workflow step with a excel attach from an internal table, Does anyone have any sugestion ?
    Thanks,
    Diego

    Hi,
    Check this [thread1|send excel attachment as email; [thread2|Re: Excel attachment in SO_DOCUMENT_SEND_API1; & [thread3|Help needed for the Excel attachment to mail;.
    Regards,
    Surjith

  • Need to color and increase the font size of the text in Excel Attachment

    Hi ,
    I have a requirement where i need to send an Excel attachment as email.
    and In the Excel I need to increase the font size and add colour to the header text in order to distinguish it form the item details.
    Is there a way that we can do it.using ALE programming .....if yes how can we do it...??
    regards
    Abaper

    Hello
    * Row color change
    FORM set_rows_fill USING number TYPE i
                                  colorindex.
      CALL METHOD OF excel 'Rows' = rows EXPORTING #1 = number.
      CALL METHOD OF rows 'SELECT'.
      CALL METHOD OF excel 'SELECTION' = selection.
      CALL METHOD OF selection 'Interior' = interior.
      SET PROPERTY OF interior 'ColorIndex' = colorindex.
      SET PROPERTY OF interior 'Pattern' = 1.
    ENDFORM.                    " SET_COLUMN_FILL
    * Font change
    FORM WRITE_ROW USING USING LEFT TOP BOTTOM RIGHT.
      DATA: bcells TYPE ole2_object,
            ecells TYPE ole2_object.
      CALL METHOD OF excel 'CELLS' = bcells EXPORTING #1 = top #2 = left.
      CALL METHOD OF excel 'CELLS' = ecells EXPORTING #1 = bottom #2 = right.
      CALL METHOD OF excel 'RANGE' = range EXPORTING #1 = bcells  #2 = ecells.
      CALL METHOD OF range 'SELECT'.
      CALL METHOD OF range 'Font' = font.
      SET PROPERTY OF font 'Name' = 'Arial Cyr'.
      SET PROPERTY OF font 'Size' = 12.
    ENDFORM.

  • Sending Grid output as Excel Sheet in Email

    Hi ,
    I am sending excel attachment through email .
    This excel attachment is generated from an ALV Grid Output .
    The excel file has all columns fixed to its initial length due to which the entire column content isnt visible unless its extended at the time of checking its content  .
    Can anyone suggest a remedy to this or send any code which can be used to read the Grid Output and Convert into excel sheet ?
    Thanks and Regards
    Soumyadip Pal

    Hi Soumyadip Pal,
    Check this code.
    *& Report  ZEMAIL_ATTACH                                               *
    *& Example of sending external email via SAPCONNECT                    *
    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
    Hope this resolves your query.
    Reward all the helpful answers.
    Regards

  • Excel Attachment Issue

    Hi ,
    I use the FM : SO_NEW_DOCUMENT_ATT_SEND_API1 for triggering an email with the excel attachment. Email triggering with an attachment  happens without any issues. But in the attachment , I am facing the following issue.
    One of the fields in the excel is numeric. Excel displays that field in the exponential format. Say for example, if the content is 38883001593305 ,excel  displays it as 3.8883E+13.  I need to display the numeric as it is without any conversion. Please kindly suggest how to achieve this.
    Thanks.

    Hi friend,
    follow the below code
    { lv_message = 'Mail For Cancelled Invoices.'.
      append lv_message to it_message.
      concatenate 'OPERATING UNIT NAME'
                  'INVOICE BATCH NAME'
                  'SUPPLIER NAME'
                  'SUPPLIER GSL'
                  'SUPPLIER PAY SITE CODE'
                  'SUPPLIER PAY SITE ADDRESS'
                  'SUPPLIER PAY SITE CITY'
                  'SUPPLIER PAY SITE STATE'
                  'SUPPLIER PAY SITE COUNTRY'
                  'INVOICE NUMBER'
                  'VOUCHER NUMBER'
                  'PO NUMBER'
                  'PO LINE NUMBER'
                  'PO BUYER NAME'
                  'INVOICE DATE'
                  'CANCELLED DATE'
                  'INVOICE ENTERED DATE'
                  'INVOICE AMOUNT'
                  'INVOICE CREATED BY'
                  into it_attachment separated by
                  cl_abap_char_utilities=>horizontal_tab.
      concatenate cl_abap_char_utilities=>cr_lf it_attachment into it_attachment.
      append it_attachment.
      loop at t_output into wa_output.
        concatenate wa_output-bukrs
                    wa_output-belnr
                    wa_output-name1
                    wa_output-gsl
                    wa_output-lifnr
                    wa_output-stras
                    wa_output-ort01
                    wa_output-regio
                    wa_output-land1
                    wa_output-xblnr
                    wa_output-belnr
                    wa_output-ebeln
                    wa_output-ebelp
                    wa_output-name2
                    wa_output-budat
                    wa_output-cpudt
                    wa_output-bldat
                    wa_output-dmbtr
                    wa_output-usnam
                     into it_attachment separated by
                 cl_abap_char_utilities=>horizontal_tab.
        concatenate cl_abap_char_utilities=>cr_lf it_attachment into it_attachment.
        append it_attachment.
      endloop.
    Selecting the mail id's
      select intid
             email
        from ztbidl
        into table t_ztbidl
       where intid = 'RICEF125' and
             obj_name = 'EPIQ'.
      loop at t_ztbidl into wa_ztbidl.
        it_receivers-receiver = wa_ztbidl-email.
        it_receivers-rec_type = 'U'.
        it_receivers-com_type = 'INT'.
        it_receivers-notif_del = 'X'.
        it_receivers-notif_ndel = 'X'.
        it_receivers-express = 'X'.
        append it_receivers.
      endloop.
    *File Type
      ld_format = 'XLS'.
    **File Name
    ld_attfilename = 'File1'.
      concatenate 'PIC_' sy-datum into ld_attfilename.
    Fill the document data.
      gd_doc_data-doc_size = 1.
    Populate the subject/generic message attributes
      gd_doc_data-obj_langu = sy-langu.
      gd_doc_data-obj_name = 'SAPRPT'.
      gd_doc_data-obj_descr = psubject .
      gd_doc_data-sensitivty = 'F'.
    Fill the document data and get size of attachment
      clear gd_doc_data.
    Populate the subject/generic message attributes
      gd_doc_data-obj_langu = sy-langu.
      read table it_attachment index w_cnt.
      gd_doc_data-doc_size = ( w_cnt - 1 ) * 255 + strlen( it_attachment ).
      gd_doc_data-obj_name  = 'SAPRPT'.
      gd_doc_data-obj_descr = psubject.
      gd_doc_data-sensitivty = 'F'.
    Describe the body of the message
      clear it_packing_list.
      refresh it_packing_list.
      it_packing_list-transf_bin = space.
      it_packing_list-head_start = 1.
      it_packing_list-head_num   = 0.
      it_packing_list-body_start = 1.
      describe table it_message lines it_packing_list-body_num.
      it_packing_list-doc_type   = 'RAW'.
      append it_packing_list.
    **Describe the attachment info
      it_packing_list-transf_bin = 'X'.
      it_packing_list-head_start = 1.
      it_packing_list-head_num   = 1.
      it_packing_list-body_start = 1.
      describe table it_attachment lines  it_packing_list-body_num.
      it_packing_list-doc_type   = ld_format.
      it_packing_list-obj_name   = ld_attfilename.
      it_packing_list-obj_descr  = ld_attfilename.
      it_packing_list-doc_size   = it_packing_list-body_num * 255.
      append it_packing_list.
      call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        exporting
          document_data              = gd_doc_data
          put_in_outbox              = 'X'
          commit_work                = 'X'
        tables
          packing_list               = it_packing_list
          contents_bin               = it_attachment
          contents_txt               = it_message
          receivers                  = it_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.

  • Sending  Excel Attachment

    Hi ,
    I am sending excel attachment through email .
    This excel attachment is generated from an ALV Grid Output .
    The excel file has all columns fixed to its initial length due to which the entire column content isnt visible unless its extended at the time of checking its content  .
    Can anyone suggest a remedy to this or send any code which can be used to read the Grid Output and Convert into excel sheet ?
    Thanks and Regards
    Soumyadip Pal

    Hi Soumyadip Pal,
    Check this code.
    REPORT z_email_abap_report.
    E-mail an Abap report                                               *
    DATA : w_name TYPE sos04-l_adr_name.
    SELECT-OPTIONS :
    Recipient address
      s_name FOR w_name DEFAULT sy-uname NO INTERVALS.
    START-OF-SELECTION.
    E-mail Abap report
      PERFORM f_send_mail.
    Form f_send_mail
    FORM f_send_mail.
    Data Declaration
      DATA:
        l_datum(10),
        ls_docdata    TYPE sodocchgi1,
        lt_objpack    TYPE TABLE OF sopcklsti1 WITH HEADER LINE,
        lt_objhead    TYPE TABLE OF solisti1   WITH HEADER LINE,
        lt_objtxt     TYPE TABLE OF solisti1   WITH HEADER LINE,
        lt_objbin     TYPE TABLE OF solisti1   WITH HEADER LINE,
        lt_reclist    TYPE TABLE OF somlreci1  WITH HEADER LINE,
        lt_listobject TYPE TABLE OF abaplist   WITH HEADER LINE,
        l_tab_lines TYPE i,
        l_att_type  LIKE soodk-objtp.
      WRITE sy-datum TO l_datum.
    List of Users According to Logon Date and Password Change
    NOTE: Create ALI/OTF Document in Spool
      SUBMIT rsusr200 WITH valid = 'X'
                      WITH notvalid = space
                      WITH unlocked = 'X'
                      WITH locked = space
                 EXPORTING LIST TO MEMORY AND RETURN.
    Read list from memory into table
      CALL FUNCTION 'LIST_FROM_MEMORY'
        TABLES
          listobject = lt_listobject
        EXCEPTIONS
          not_found  = 1
          OTHERS     = 2.
      IF sy-subrc <> 0.
      Error in function module &1
        MESSAGE ID '61' TYPE 'E' NUMBER '731'
           WITH 'LIST_FROM_MEMORY'.
      ENDIF.
    Because listobject is of size RAW(1000)
    and objbin is of size CHAR(255) we make this table copy
      CALL FUNCTION 'TABLE_COMPRESS'
        TABLES
          in             = lt_listobject
          out            = lt_objbin
        EXCEPTIONS
          compress_error = 1
          OTHERS         = 2.
      IF sy-subrc <> 0.
      Error in function module &1
        MESSAGE ID '61' TYPE 'E' NUMBER '731'
           WITH 'TABLE_COMPRESS'.
      ENDIF.
    NOTE: Creation of attachment is finished yet.
    For your report, the attachment should be placed into table
    objtxt for plain text or
    objbin for binary content.
    Now create the message and send the document.
    Create Message Body
    Title and Description
      ls_docdata-obj_name = 'USERS_LIST'.
      CONCATENATE 'List of Users' sy-sysid '-' l_datum          "#EC *
            INTO ls_docdata-obj_descr SEPARATED BY space.
    Main Text
      lt_objtxt = 'List of Users According to Logon Date' &
                  ' and Password Change'.                       "#EC *
      APPEND lt_objtxt.
    Write Packing List (Main)
      DESCRIBE TABLE lt_objtxt LINES l_tab_lines.
      READ TABLE lt_objtxt INDEX l_tab_lines.
      ls_docdata-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt ).
      CLEAR lt_objpack-transf_bin.
      lt_objpack-head_start = 1.
      lt_objpack-head_num = 0.
      lt_objpack-body_start = 1.
      lt_objpack-body_num = l_tab_lines.
      lt_objpack-doc_type = 'RAW'.
      APPEND lt_objpack.
    Create Message Attachment
    Write Packing List (Attachment)
      l_att_type = 'ALI'.
      DESCRIBE TABLE lt_objbin LINES l_tab_lines.
      READ TABLE lt_objbin INDEX l_tab_lines.
      lt_objpack-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( lt_objbin ).
      lt_objpack-transf_bin = 'X'.
      lt_objpack-head_start = 1.
      lt_objpack-head_num = 0.
      lt_objpack-body_start = 1.
      lt_objpack-body_num = l_tab_lines.
      lt_objpack-doc_type = l_att_type.
      lt_objpack-obj_name = 'ATTACHMENT'.
      lt_objpack-obj_descr = 'List_of_Users'.                   "#EC *
      APPEND lt_objpack.
    Create receiver list
      LOOP AT s_name.
        lt_reclist-receiver = s_name-low.
        lt_reclist-rec_type = 'B'.
        APPEND lt_reclist.
      ENDLOOP.
    Send Message
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = ls_docdata
          put_in_outbox              = ''
        TABLES
          packing_list               = lt_objpack
          object_header              = lt_objhead
          contents_bin               = lt_objbin
          contents_txt               = lt_objtxt
          receivers                  = lt_reclist
        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.
      IF sy-subrc = 0.
      Document sent
        MESSAGE ID 'SO' TYPE 'S' NUMBER '022'.
      ELSE.
      Document <&> could not be sent
        MESSAGE ID 'SO' TYPE 'S' NUMBER '023'
           WITH ls_docdata-obj_name.
      ENDIF.
    ENDFORM.                               " F_SEND_MAIL
    END OF PROGRAM Z_EMAIL_ABAP_REPORT ******************
    Hope this resolves your query.
    Reward all the helpful answers.
    Regards

  • Error while opening Excel file sent through attachment in email in sap

    Hi All,
    I have implemented sending email with excel attachment in SAP.
    Email is sent successfully with attachment but when i tried to open it i get first error dialog like " file is not in recognizable format" but after that if i click ok then file gets opened correctly.
    Can you please sort this out.
    Thanks in advance.
    regards
    Ashutosh

    Go to the following link you will get solutions:
    ABAP BASIC

  • Excel doc as email attachment

    Hi Experts
    Hope you guys are doing fine.
    I have a requirement where i need to send the internal table data as an excel email attachment.I used the FM 'SO_NEW_DOCUMENT_ATT_SEND_API1',but in the email attachment,the data is getting distorted and not coming in a properly manner.Here with,i am pasting the code i used.
    (l_pto_tab is the internal table)
    FORM report_as_email .
      TYPES : BEGIN OF ty_pto_tab,
               pernr(10),
               nachn(40),
               vorna(40),
               hdate(15),
               supno(10),
               supln(40),
               supfn(40),
             END    OF  ty_pto_tab.
      DATA:   wa_pack_list  TYPE sopcklsti1,
              it_pack_list  TYPE TABLE OF sopcklsti1.
      DATA:  it_email_lines  like SOLISTI1 occurs 0 with header line,
             it_obj_text  like SOLISTI1 occurs 0 with header line.
      DATA:  wa_object_header  TYPE solisti1,
             it_object_header  TYPE TABLE OF solisti1.
      DATA: wa_mail_receiver  TYPE somlreci1,
            it_mail_receiver  TYPE TABLE OF somlreci1.
      DATA: wa_mail_data      TYPE sodocchgi1,
            l_pto_tab type ty_pto_tab occurs 0 with header line.
      DATA: w_att_lines(6) TYPE n.
      DATA: w_att_lines1(6) TYPE n.
      DATA: text1 TYPE c LENGTH 155.
      DATA: text2 TYPE c LENGTH 155.
      DATA: text3 TYPE c LENGTH 155.
      DATA: wa_error_cols  TYPE ty_email_lines.
      DATA: count TYPE i.
      DATA: gv_date1 TYPE c LENGTH 10.
      REFRESH: it_pack_list,
               it_object_header,
               it_mail_receiver.
    Set first line to be displayed in the document
      wa_object_header-line = 'PTO_Reminder_List.TXT'.
      APPEND wa_object_header TO it_object_header.
    *-- Document data
      CLEAR: wa_mail_data.
      wa_mail_data-obj_name = 'Object name'.
      wa_mail_data-sensitivty = 'O'.
      wa_mail_data-obj_descr = 'PTO Reminder Report'.
    Set Mail body
    it_obj_text = 'PTO Reminder'.
    append it_obj_text.
    clear it_obj_text.
    *-- Set Attachment values
      l_pto_tab-pernr = 'EE Number'.
      l_pto_tab-nachn = 'EE LNAME'.
      l_pto_tab-vorna = 'EE FNAME'.
      l_pto_tab-hdate = 'Hire Date'.
      l_pto_tab-supno = 'Sup No'.
      l_pto_tab-supln = 'Sup LNAME'.
      l_pto_tab-supfn = 'Sup FNAME'.
      INSERT l_pto_tab INTO it_email_lines INDEX 1.
      CLEAR l_pto_tab.
    count = 1.
    loop at it_pto_tab.
      l_pto_tab-pernr = it_pto_tab-pernr.
      l_pto_tab-nachn = it_pto_tab-nachn.
      l_pto_tab-vorna = it_pto_tab-vorna.
      l_pto_tab-hdate = it_pto_tab-hdate.
      l_pto_tab-supno = it_pto_tab-supno.
      l_pto_tab-supln = it_pto_tab-supln.
      l_pto_tab-supfn = it_pto_tab-supfn.
      append l_pto_tab.
      clear l_pto_tab.
      endloop.
    l_pto_tab is the internal table
      LOOP AT l_pto_tab.
          count = count + 1.
          INSERT l_pto_tab INTO it_email_lines INDEX count.
        ENDLOOP.
      REFRESH  l_pto_tab.
      wa_pack_list-head_start = 1.
      wa_pack_list-head_num   = 0.
      wa_pack_list-body_start = 1.
      wa_pack_list-body_num   = 1.
      wa_pack_list-doc_type   = 'RAW'.
      wa_pack_list-doc_size   = 255.
      APPEND wa_pack_list TO it_pack_list.
      CLEAR: wa_pack_list.
    DESCRIBE TABLE it_email_lines LINES w_att_lines.
    READ TABLE it_email_lines INDEX w_att_lines.
    wa_mail_data-doc_size = ( w_att_lines - 1 ) * 255 +
                     STRLEN( it_email_lines-line ).
    Attachment
      wa_pack_list-transf_bin = 'X'.
      wa_pack_list-head_start = 1.
      wa_pack_list-head_num   = 1.
      wa_pack_list-body_start = 1.
      wa_pack_list-body_num   = w_att_lines.
    Excel attachment
      wa_pack_list-doc_type   = 'XLS'.
      wa_pack_list-obj_name   = 'ATTACHMENT'.
      wa_pack_list-obj_descr  = 'PTO_REMINDER_LIST'.
      wa_pack_list-doc_size   = wa_mail_data-doc_size.
      APPEND wa_pack_list TO it_pack_list.
      CLEAR: wa_pack_list.
    *-- Set E-Mail Receiver address
      wa_mail_receiver-receiver = '[email protected]'.
      wa_mail_receiver-rec_type = 'U'.
      wa_mail_receiver-express  = 'X'.
      APPEND wa_mail_receiver TO it_mail_receiver.
      *-- Send E-Mail
      call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        exporting
          document_data              = wa_mail_data
          put_in_outbox              = 'X'
          commit_work                = 'X'
        tables
          packing_list               = it_pack_list
          object_header              = it_object_header
          contents_bin               = it_email_lines
          contents_txt               = it_obj_text
          receivers                  = it_mail_receiver
        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.
      IF NOT sy-subrc IS INITIAL.
        WRITE: / 'E-mail failed.'.
      ENDIF.
    ENDFORM.                    " report_as_email
    Can anyone look into this code and let me know what changes i need to make to correct this error.Or if anyone has any sample code,can you pls share it with me.
    Your help wud be greatly appreciated.
    Thnx

    alan,
      Check the below code.
    report y_cr17_mail .
    data method1 like sy-ucomm.
    data g_user like soudnamei1.
    data g_user_data like soudatai1.
    data g_owner like soud-usrnam.
    data g_receipients like soos1 occurs 0 with header line.
    data g_document like sood4 .
    data g_header like sood2.
    data g_folmam like sofm2.
    data g_objcnt like soli occurs 0 with header line.
    data g_objhead like soli occurs 0 with header line.
    data g_objpara  like selc occurs 0 with header line.
    data g_objparb  like soop1 occurs 0 with header line.
    data g_attachments like sood5 occurs 0 with header line.
    data g_references like soxrl occurs 0 with header line.
    data g_authority like sofa-usracc.
    data g_ref_document like sood4.
    data g_new_parent like soodk.
    data: begin of g_files occurs 10 ,
      text(4096) type c,
       end of g_files.
    data : fold_number(12) type c,
           fold_yr(2) type c,
           fold_type(3) type c.
    parameters ws_file(4096) type c default 'c:\debugger.txt'.
    Can me any file fromyour pc ....either xls or word or ppt etc ...
    g_user-sapname = sy-uname.
    call function 'SO_USER_READ_API1'
    exporting
       user                            = g_user
       PREPARE_FOR_FOLDER_ACCESS       = ' '
    importing
       user_data                       = g_user_data
    EXCEPTIONS
       USER_NOT_EXIST                  = 1
       PARAMETER_ERROR                 = 2
       X_ERROR                         = 3
       OTHERS                          = 4
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    fold_type = g_user_data-outboxfol+0(3).
    fold_yr = g_user_data-outboxfol+3(2).
    fold_number =  g_user_data-outboxfol+5(12).
    clear g_files.
    refresh : g_objcnt,
      g_objhead,
      g_objpara,
      g_objparb,
      g_receipients,
      g_attachments,
      g_references,
      g_files.
    method1 = 'SAVE'.
    g_document-foltp  = fold_type.
    g_document-folyr   = fold_yr.
    g_document-folno   = fold_number.
    g_document-objtp   = g_user_data-object_typ.
    *g_document-OBJYR   = '27'.
    *g_document-OBJNO   = '000000002365'.
    *g_document-OBJNAM = 'MESSAGE'.
    g_document-objdes   = 'Manohar testing by program'.
    g_document-folrg   = 'O'.
    *g_document-okcode   = 'CHNG'.
    g_document-objlen = '0'.
    g_document-file_ext = 'TXT'.
    g_header-objdes =  'Manohar testing by program'.
    g_header-file_ext = 'TXT'.
    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
      exporting
        method             = method1
       office_user        = sy-uname
       ref_document       = g_ref_document
       new_parent         =  g_new_parent
    importing
       authority          =  g_authority
    tables
       objcont            = g_objcnt
       objhead            = g_objhead
       objpara            = g_objpara
       objparb            = g_objparb
       recipients         = g_receipients
       attachments        = g_attachments
       references         = g_references
       files              = g_files
      changing
        document           = g_document
       header_data        = g_header
      FOLMEM_DATA        =
      RECEIVE_DATA       =
    File from the pc to send...
    method1 = 'ATTCREATEFROMPC'.
    g_files-text = ws_file.
    append g_files.
    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
      exporting
        method             = method1
       office_user        = g_owner
       ref_document       = g_ref_document
       new_parent         =  g_new_parent
    importing
       authority          =  g_authority
    tables
       objcont            = g_objcnt
       objhead            = g_objhead
       objpara            = g_objpara
       objparb            = g_objparb
       recipients         = g_receipients
       attachments        = g_attachments
       references         = g_references
       files              = g_files
      changing
        document           = g_document
       header_data        = g_header
    method1 = 'SEND'.
    g_receipients-recnam = 'MK085'.
    g_receipients-recesc = 'B'.
    g_receipients-sndex = 'X'.
    append  g_receipients.
    call function 'SO_DOCUMENT_REPOSITORY_MANAGER'
      exporting
        method             = method1
       office_user        = g_owner
       ref_document       = g_ref_document
       new_parent         =  g_new_parent
    importing
       authority          =  g_authority
    tables
       objcont            = g_objcnt
       objhead            = g_objhead
       objpara            = g_objpara
       objparb            = g_objparb
       recipients         = g_receipients
       attachments        = g_attachments
       references         = g_references
       files              = g_files
      changing
        document           = g_document
       header_data        = g_header.
    Don't forget to reward if useful.......

  • Issue in Sending email with EXCEL attachment

    Hi,
    Im using the FM SO_NEW_DOCUMENT_ATT_SEND_API1 for sending emails to a list of recipients with an excel attachment. In the attachment data, as the field length is 255 for the structure SOLISTI1, for the records having more than 255 characters, data is being truncated. I did a search in this forum and done some changes , still it is not working properly.
    I have used SCMS_TEXT_TO_XSTRING, SCMS_XSTRING_TO_BINARY FMs for converting the data to hexa format. This case, records having more than 255 are displayed properly in the attachment, but there are blank lines inserted between two records.
    Please suggest me to resolve this isssue.
    Thanks in advance.
    Jayashree

    Hi Jayashree,
    you might want to check out the example link by Saso in his post Send external email from within ABAP program to xls.
    For the rest I can only guess that there might be some issues with the format you use for Excel. In case of empty lines and using a text format for Excel the issue is in most cases that there are too many carriage return line feeds in the text fiel (cl_abap_char_utilities=>cr_lf).
    Hope that helps.
    Best Regards
    Michael

Maybe you are looking for

  • The Add-on installation is currently in phase DDIC_ACTIVATION

    Dear All, I am applying the addon "ST-A/PI" on SAP ERP 6.0. The status "The Add-on installation is currently in phase DDIC_ACTIVATION" has been there for a few hours now whereas the sap note says it should end in 12 mins approx. Could you please help

  • Purchase order item - avoid delete

    Hi Expert, I have to make a control to avoid the deletion of an item of purchase order. In other word, when the user press the delete button in the item of purchase order, I have to check variable A. If A = 'X' --> avoid delete item, and pop for info

  • Tooltip with xml data set

    I have posted this over on the Spry forum but wonder if someone else has had a similar issue and found a solution as I am trying to find the answer to this quickly if possible; I want to use a tooltip with an xml data set. I have an xml data set of e

  • I need to change my apple id. how do i do that?

    I need to change my apple id. How do i do that?

  • How to get the line information when double click the ALV line?

    LOOP AT it_outr.     AT END OF vornr.       REFRESH it_out.       CLEAR it_out.       LOOP AT it_outt WHERE nplnr = it_outr-nplnr                         AND vornr = it_outr-vornr.         MOVE-CORRESPONDING it_outt TO it_out.         APPEND it_out.