Send Excel as attachment in SAP

Hello All,
My requirement is to send a mail with the contents of an ALV once it is displayed on the screen. This is working fine. Now the users want that 3 fields Quantity,NETPR and NETWR fields should send data to excel with 0,3 and 2 decimal places. We are able to display the same in ALV but when the data is sent as excel attachment in some cells it is text and in some it is number causing it to display the same for some records. Is there a way to get the out similar to the one we get via Export to spreadsheet in ALV ?
Note the user needs the file to be XLS and we can not use ' in front of these fields to convert them to text for display purpose.
Any suggestions are welcome.
Thanks and Regards
Sachin

Please check
[http://wiki.sdn.sap.com/wiki/display/Snippets/FormattedExcelasEmailAttachment]
Nabheet

Similar Messages

  • 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.

  • Problem while sending excel as attachment

    Hi,
    I am trying to send excel as attachment through an email.
    I am using the fm: SO_DOCUMENT_SEND_API1
    In english, I am able to get the data properly. However, when I try to send the same in Chinese, I am getting junk characters in excel file.
    Could you please help me out to solve my issue.
    I am clueless, why only for chinese, I am getting the issue.
    Thanks,
    Sandeep

    Hi Rushi,
    In this FM, I am unable to find the parameter for code page. Could you please help me how exactly I can use this code page?
    Thanks,
    Sandeep

  • 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

  • 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

  • How to zip a text file and send as email attachment in SAP version 4.6c?

    Hi Guru,
    How to zip a text file in SAP version 4.6c which doesn't have class CL_ABAP_ZIP?
    Please help.
    Thanks & Regards,
    Ari

    Hi,
    Try this link
    [http://sap.ittoolbox.com/groups/technical-functional/sap-dev/sapr3dev-zip-file-from-sap-1707099?cv=expanded]
    Cheers,
    Surinder

  • 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.

  • Send file as attachment via mail

    Dear All,
    I want to send a report (ALV) as attachment to some mail. I am using SO_NEW_DOCUMENT_SEND_API1. Can you please suggest how can I send mail as attachment. I am able to send ALV report as HTML format. I want to send it as attachment.
    Thanks and regards,
    Atanu

    Hi,
    plz check the below code.
    it sends Excel sheet attachment with the mail using FM 'SO_DOCUMENT_SEND_API1'
    code>>>>>>>>>>>>>>>>>>>>.
    form send_email_with_attachment .
    DATA: l_t_objbin LIKE solisti1 OCCURS 100 WITH HEADER LINE.
      DATA: i_body TYPE soli_tab WITH HEADER LINE.
      DATA: l_t_objtxt  LIKE solisti1   OCCURS 100 WITH HEADER LINE.
      DATA: l_t_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.
      DATA: l_t_objhead LIKE solisti1   OCCURS 1 WITH HEADER LINE.
      DATA: l_t_reclist LIKE somlreci1  OCCURS 5 WITH HEADER LINE.
      DATA: w_tabln TYPE i .              "for number of table lines
      DATA: w_line        TYPE so_text255.       " Line of text
      DATA: l_doc_chng  LIKE sodocchgi1.
      DATA: l_tab_lines LIKE sy-tabix.
      DATA: l_att_lines TYPE i.
      DATA: lv_lines  TYPE i.
      DATA : BEGIN OF wa_mrpnm,
               werks TYPE ZCSVT024D-werks,
               dispo TYPE ZCSVT024D-dispo,
               name_first TYPE ZCSVT024D-name_first,
               name_last  TYPE ZCSVT024D-name_last,
             END OF wa_mrpnm,
             l_i_mrpnm LIKE STANDARD TABLE OF wa_mrpnm.
      DATA : l_name TYPE string.
    *Used for delimiting the columns in Excel Sheet.
      CLASS cl_abap_char_utilities DEFINITION LOAD.
      CONSTANTS:
      cr_mark(2) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
      constants c_l_newline type ABAP_CHAR1 value %_NEWLINE. "#EC NOTEXT
      CLEAR : l_t_objpack,
      l_t_objhead,
      l_t_objbin,
      l_t_objtxt,
      l_t_reclist.
      REFRESH: l_t_objpack,
      l_t_objhead,
      l_t_objbin,
      l_t_objtxt,
      l_t_reclist.
    Creating the content of the e-mail message text
      IF sy-sysid(1) = 'P'.
        IF p_order = 'X'.
         l_doc_chng-obj_name   = 'Subcontracting Setup Report'(m02).
          CONCATENATE 'Details of Orders Extract'(028) 'for Plant'(029)
                       p_werks
                       INTO l_doc_chng-obj_descr SEPARATED BY space.
          l_doc_chng-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( l_t_objtxt ).
        ELSE.
         l_doc_chng-obj_name   = 'TEST ONLY!! SC Setup Report'(m03).
          CONCATENATE 'Details of Forecast Extract'(030) 'for Plant'(029)
                       p_werks
                       INTO l_doc_chng-obj_descr SEPARATED BY space.
          l_doc_chng-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( l_t_objtxt ).
        ENDIF.
      ELSE.
        IF p_order = 'X'.
         l_doc_chng-obj_name   = 'Subcontracting Setup Report'(m02).
          CONCATENATE 'Details of Orders Extract'(028) 'for Plant'(029)
                       p_werks 'TEST TEST TEST'
                       INTO l_doc_chng-obj_descr SEPARATED BY space.
          l_doc_chng-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( l_t_objtxt ).
        ELSE.
         l_doc_chng-obj_name   = 'TEST ONLY!! SC Setup Report'(m03).
          CONCATENATE 'Details of Forecast Extract'(030) 'for Plant'(029)
                       p_werks 'TEST TEST TEST'
                       INTO l_doc_chng-obj_descr SEPARATED BY space.
          l_doc_chng-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( l_t_objtxt ).
        ENDIF.
      ENDIF.
      l_t_objtxt = 'Hi,'(036).
      APPEND l_t_objtxt.
      CLEAR l_t_objtxt.
      APPEND l_t_objtxt.
      CONCATENATE 'Please open the attachment to review details of the Report'(031)
                  'for plant'(029) p_werks INTO l_t_objtxt
                   SEPARATED BY space.
      APPEND l_t_objtxt.
      CLEAR l_t_objtxt.
      APPEND l_t_objtxt.
      DESCRIBE TABLE t_ddow LINES sy-tfill .
      IF sy-tfill GT 0 .
        MOVE 'These Materials have been marked as DDOW materials.'(032)
                TO l_t_objtxt.
        APPEND l_t_objtxt.
        CLEAR l_t_objtxt.
        APPEND l_t_objtxt.
        APPEND l_t_objtxt.
        APPEND l_t_objtxt.
        CONCATENATE 'Note! - This is an automatically generated email by the'(034)
                         'SAP system. Pls do not reply to the sender.'(035)
                   INTO  l_t_objtxt
                   SEPARATED BY space.
        APPEND l_t_objtxt.
        DESCRIBE TABLE l_t_objtxt LINES l_tab_lines.
        READ TABLE l_t_objtxt INDEX l_tab_lines.
       l_doc_chng-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( l_t_objtxt )
      Creating the entry for the email text in the packing list
        CLEAR l_t_objpack-transf_bin.
        l_t_objpack-head_start = 1.
        l_t_objpack-head_num = 1.
        l_t_objpack-body_start = 1.
        l_t_objpack-body_num = l_tab_lines.
        l_t_objpack-doc_type = 'RAW'.
        lv_lines = l_tab_lines.
        APPEND l_t_objpack.
    Columns Heading for Excel Attachment.
        CONCATENATE  'MRP Controller'(044)
                     'MRP Name'(047)
                     'Material'(037)
                     'Plant'(026)
                     'PP Cal'(038)
                     'Ship Date'(009)
                     'PO Number'(014)
                     'PO Line'(033)
                     'PP Text'(041)
             INTO i_body
            SEPARATED BY cr_mark.
        concatenate ' ' i_body into i_body separated by c_l_newline.
        APPEND i_body TO l_t_objtxt.
        CLEAR i_body.
      Get MRP Names
        SELECT werks dispo name_first name_last
          FROM ZCSVT024D
          INTO TABLE l_i_mrpnm
          FOR ALL ENTRIES IN t_ddow
          WHERE werks = t_ddow-werks
            AND dispo = t_ddow-dispo.
        IF sy-subrc = 0.
          SORT l_i_mrpnm by werks dispo.
        ENDIF.
    Data to be shown in Excel Sheet.
        LOOP AT t_ddow INTO w_ddow.
          CLEAR : l_name.
          READ TABLE l_i_mrpnm INTO wa_mrpnm WITH KEY werks = w_ddow-werks
                                                      dispo = w_ddow-dispo
                                                      BINARY SEARCH.
          IF sy-subrc = 0.
            CONCATENATE wa_mrpnm-name_first wa_mrpnm-name_last
              INTO l_name SEPARATED BY space.
          ENDIF.
          CONCATENATE  w_ddow-dispo
                       l_name
                       w_ddow-matnr
                       w_ddow-werks
                       w_ddow-mrppp
                       w_ddow-datum
                       w_ddow-ebeln
                       w_ddow-ebelp
                       w_ddow-pptxt
                INTO i_body
            SEPARATED BY cr_mark.
          concatenate ' ' i_body into i_body separated by c_l_newline.
          APPEND i_body TO l_t_objtxt.
          CLEAR : w_ddow.
        ENDLOOP.
        DESCRIBE TABLE l_t_objtxt LINES l_tab_lines.
        DESCRIBE TABLE l_t_objtxt LINES l_att_lines.
        l_tab_lines = l_tab_lines - lv_lines.
      Creating the entry for attachment in the packing list
      objpack-transf_bin = 'X'.
        lv_lines = lv_lines + 1.
        l_t_objpack-head_start = 2.
        l_t_objpack-head_num = 1.
        l_t_objpack-body_start = lv_lines.
        l_t_objpack-body_num = l_tab_lines.
        l_t_objpack-doc_type = 'XLS'.
        l_t_objpack-obj_name = 'DDOW_Materials'(045).
        l_t_objpack-obj_descr = 'DDOW Marked Materials'(046).
        l_t_objpack-doc_size = l_tab_lines * 255.
        APPEND l_t_objpack.
        lv_lines = l_att_lines.
         **RECEIVERS...
        LOOP AT t_ddow INTO w_ddow.
          REFRESH l_t_reclist .
          CLEAR l_t_reclist.
    * get the MRP controller from table
          READ TABLE t_mrpc INTO w_mrpc WITH KEY werks = p_werks
                                                 dispo = w_ddow-dispo
                                                 BINARY SEARCH .
          IF sy-subrc EQ 0 .
            MOVE: 'X'               TO l_t_reclist-express   ,
                  'U'               TO l_t_reclist-rec_type  ,
                  w_mrpc-smtp_addr  TO l_t_reclist-receiver  .
                  APPEND l_t_reclist.
            EXIT.
          ENDIF.
        ENDLOOP.
      Sending the document
        IF NOT l_t_reclist[] IS INITIAL.
          CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
            EXPORTING
              document_data              = l_doc_chng
              commit_work                = 'X'
            TABLES
              packing_list               = l_t_objpack
              object_header              = l_t_objhead
              contents_bin               = l_t_objbin
              contents_txt               = l_t_objtxt
              receivers                  = l_t_reclist
            EXCEPTIONS
              too_many_receivers         = 1
              document_not_sent          = 2
              operation_no_authorization = 4
              OTHERS                     = 99.
        ENDIF.
        IF sy-subrc <> 0.
    * Do nothing
        ELSE.
          COMMIT WORK AND WAIT.
          MESSAGE s899(8a) WITH 'Email Message sent successfully'."#EC
        ENDIF.
      ENDIF.
    <<<<<<<<<<<<<<<<<<<<<<<
    regards,
    vikas.
    plz reward if helpful..

  • Sending external mail with excel attachment from SAP

    Hi All,
    I am trying to send a external mail from SAP. Mail is getting posted correctly with attachment having type excel. If attach file has more than 1 records then in mail it is coming in a single lines. it is not getting wrap.
    e.g. my attach internal table has records like LINE1
                                                                      LINE2
                                                                      LINE3
    output in attach excel file is : LINE1         LINE2          LINE3
    in attach file it should come line by line.
    source code of my function module is as follows :
    FUNCTION ZXI_SEND_MAIL_WITH_ATTACHMENT.
    ""Local Interface:
    *"  IMPORTING
    *"     REFERENCE(SUBJECT) TYPE  SO_OBJ_DES OPTIONAL
    *"     REFERENCE(ATTACH_NAME1) TYPE  SOOD-OBJDES
    *"     REFERENCE(EXT1) TYPE  SOODK-OBJTP
    *"     REFERENCE(MAIL_ID) TYPE  ADR6-SMTP_ADDR
    *"  TABLES
    *"      IT_CONTENT TYPE  SOLI_TAB OPTIONAL
    *"      IT_ATTACH TYPE  SOLI_TAB OPTIONAL
      DATA: send_request       TYPE REF TO cl_bcs.
      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: exception_info     TYPE REF TO if_os_exception_info,
      bcs_exception      TYPE REF TO cx_document_bcs.
      DATA i_attachment_size TYPE sood-objlen.
    Creates persistent send request
      send_request = cl_bcs=>create_persistent( ).
      TRY.
    *****Create txt mail document**************************
          document = cl_document_bcs=>create_document(
                                        i_type    = 'RAW'
                                        i_text = it_content[]
                                        i_subject = subject ).
    **************Creates Attachment 1***********************
          CALL METHOD document->add_attachment
            EXPORTING
              i_attachment_type    = ext1
              i_attachment_subject = attach_name1
              i_att_content_text   = it_attach[].
    Add document to send request
          CALL METHOD send_request->set_document( document ).
    Get sender object
          sender = cl_sapuser_bcs=>create( sy-uname ).
    Add sender
          CALL METHOD send_request->set_sender
            EXPORTING
              i_sender = sender.
          recipient = cl_cam_address_bcs=>create_internet_address(
                               i_address_string = mail_id ).
          CALL METHOD send_request->add_recipient
            EXPORTING
              i_recipient  = recipient
              i_express    = 'U'
              i_copy       = ' '
              i_blind_copy = ' '
              i_no_forward = ' '.
    **********Trigger e-mails immediately****************************
          send_request->set_send_immediately( 'X' ).
          CALL METHOD send_request->send( ).
          COMMIT WORK.
        CATCH cx_document_bcs INTO bcs_exception.
      ENDTRY.
    ENDFUNCTION.
    please suggest me a solution and thanks in advance.
    Thanks&Regards,
    Sachin

    See the sample code  for sending attachment as Mail
    Mailing with Attachment by ABAP Coding  
    Refer this link:
    Mail with attachment.
    FORM send_list_to_basis .
      DATA: w_path      LIKE rlgrap OCCURS 0 WITH HEADER LINE,
            lt_index    TYPE sy-tabix,
            doc_type(3) TYPE c,
            descr       LIKE it_objpack_basis-obj_descr,
            temp_data   LIKE w_path,
            temp1       TYPE string,
            tab_lines   TYPE i,
            langu(15)   TYPE c,
            expirydate  TYPE so_obj_edt,
            L_FILE1(100).
      CONCATENATE 'C:\' sy-repid '_' sy-datum '.XLS' INTO L_FILE1.
      W_PATH-FILENAME = L_FILE1.
      APPEND w_path.
      CLEAR w_path.
      wa_doc_chng-obj_descr  = 'User List not logged on for 180 days'.
      wa_doc_chng-obj_langu  = 'E'.
      wa_doc_chng-obj_expdat = sy-datum.
      CLEAR w_subject.
      CONCATENATE 'Please find attached document with list of users'
                  'not logged on for 180 days for client' sy-mandt
                  INTO w_subject SEPARATED BY space.
      it_objtxt_basis-line = w_subject.
      APPEND it_objtxt_basis.
      CLEAR it_objtxt_basis.
      it_objtxt_basis-line = text-004.
      APPEND it_objtxt_basis.
      CLEAR it_objtxt_basis.
      CLEAR w_tab_line.
      DESCRIBE TABLE it_objtxt_basis LINES w_tab_line.
      READ TABLE it_objtxt_basis INDEX w_tab_line  INTO l_cline.
      wa_doc_chng-doc_size =
       ( w_tab_line - 1 ) * 255 + STRLEN( l_cline ).
      CLEAR it_objpack_basis-transf_bin.
      it_objpack_basis-head_start = 1.
      it_objpack_basis-head_num   = 0.
      it_objpack_basis-body_start = 1.
      it_objpack_basis-body_num   = w_tab_line.
      it_objpack_basis-doc_type   = 'RAW'.
      APPEND it_objpack_basis.
      CLEAR it_objpack_basis.
      LOOP AT w_path.
        temp1 = w_path.
        descr = w_path.
        CALL FUNCTION 'STRING_REVERSE'
          EXPORTING
            string  = descr
            lang    = 'E'
          IMPORTING
            rstring = descr.
        CALL FUNCTION 'STRING_SPLIT'
          EXPORTING
            delimiter = '\'
            string    = descr
          IMPORTING
            head      = descr
            tail      = temp_data.
        CALL FUNCTION 'STRING_REVERSE'
          EXPORTING
            string  = descr
            lang    = 'E'
          IMPORTING
            rstring = descr.
        CALL FUNCTION 'STRING_SPLIT'
          EXPORTING
            delimiter = '.'
            string    = descr
          IMPORTING
            head      = temp_data
            tail      = doc_type.
        CALL FUNCTION 'GUI_UPLOAD'
          EXPORTING
            filename      = temp1
            filetype      = 'BIN'
            header_length = 0
            read_by_line  = 'X'
            replacement   = '#'
          TABLES
            data_tab      = it_upload.
        DESCRIBE TABLE it_upload LINES tab_lines.
        DESCRIBE TABLE it_objbin_basis LINES lt_index.
        lt_index = lt_index + 1.
        LOOP AT it_upload.
          wa_objbin_basis-line = it_upload-line.
          APPEND wa_objbin_basis TO it_objbin_basis.
          CLEAR wa_objbin_basis.
        ENDLOOP.
        it_objpack_basis-transf_bin = 'X'.
        it_objpack_basis-head_start = 0.
        it_objpack_basis-head_num   = 0.
        it_objpack_basis-body_start = lt_index.
        it_objpack_basis-body_num   = tab_lines.
        it_objpack_basis-doc_type   = doc_type.
        it_objpack_basis-obj_descr  = descr.
        it_objpack_basis-doc_size   = tab_lines * 255.
        APPEND it_objpack_basis.
        CLEAR it_objpack_basis.
      ENDLOOP.
      it_reclist_basis-receiver = '[email protected]'.
      it_reclist_basis-rec_type = 'U'.
      APPEND it_reclist_basis.
      CLEAR it_reclist_basis.
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = wa_doc_chng
          put_in_outbox              = 'X'
          commit_work                = 'X'
        TABLES
          packing_list               = it_objpack_basis
          contents_txt               = it_objtxt_basis
          contents_bin               = it_objbin_basis
          receivers                  = it_reclist_basis
        EXCEPTIONS
          too_many_receivers         = 1
          document_not_sent          = 2
          operation_no_authorization = 4
          OTHERS                     = 99.
      IF sy-subrc EQ 0.
        SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.
      ENDIF.
    ENDFORM.                    " send_list_to_basis
    Reward points if useful
    Regards
    Anji

  • Simple code to send ALV display as XLS attachment  to SAP inbox

    Hi All,
    Simple code to send ALV display as XLS attachment  to SAP inbox.
    Also i need to send only 200 records per attachement. So in this case i need send multiple attachment per mail
    Thanks,
    Lokesh

    The following code is used to send the internal table which u pass fo  the ALV display to be send as excel sheet attachment
    Internal table is it_attach[]
    ld_email               = po_email.
      ld_mtitle              = 'Email From Z377_EMAIL_XLS'.
      ld_format              = 'XLS'.
      ld_attdescription      = 'filename'.
      ld_attfilename         = 'Allot'.
      ld_sender_address      = ' '.
      ld_sender_address_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[] = it_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 li_content 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               = li_content
      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.

  • Send EXCEL attachment with garbage russia text

    Hello All - Good day!
    I have the same problem where non-english text like russian, and will appear garbage in the excel attachment after it was email.
    When I test it in english description/text it looks ok.
    I have tried the following FM, and got no luck.
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    Program is in Unicode.
    PLEASE help.

    Hello,
    Check the following SAP note in this regards:
      1151258 Error when sending Excel attachments
    Also, please check SAP note regarding SO_DOCUMENT_SEND_API1 interface:
       190669 Sending lists via SAPconnect
    Regards,
    David

  • Sending excel attachment to the distribution list

    Hi ,
    I am sending an Excel file attachment in XLS format to the distrubution list using FM :SO_NEW_DOCUMENT_ATT_SEND_API1
    I have passed the parameters as follows:
      reclist-REC_TYPE   = 'C'.
      reclist-COM_TYPE   = 'INT'.
      reclist-NOTIF_DEL  = 'X'.
      reclist-NOTIF_NDEL = 'X'.
      reclist-RECEIVER = p_DLIST.
      APPEND reclist.
    but i am receiving error message :
    Exception from the class CX_SEND_REQ_BCS was caught
    when I am passing the receiver as email address, its working fine.
    Please let me know what is the issue?
    Tjhanks and regards,
    Madhuri

    Hi,
    Try
    RECLIST-REC_TYPE = 'U'. "internet users
    RECLIST-RECEIVER = '<name>@address.com'. " try one like youe first address
    RECLIST-REC_TYPE = 'U'.
    APPEND RECLIST.
    RECLIST-RECEIVER = p_DLIST.  " put the list
    RECLIST-REC_TYPE = 'P'.
    APPEND RECLIST.
    Also check this wiki [http://wiki.sdn.sap.com/wiki/display/Snippets/Howtosendmailtoadistributionlistoragroup+ID]
    Ben

  • Error when sending excel as email attachment

    Hi All,
    I am sending excel document as email attachment through F.M. SO_DOCUMENT_SEND_API1. I am getting the attachment but when i open it, it is giving error "The file is not in recognizable format....."
    Please let me know how can i solve this problem.
    Regards,
    Saba

    Hi Saba,
    Check this link I think will surely help.
    [http://www.sap-img.com/abap/sending-email-with-attachment.htm]
    Regards,
    Amit.

  • Send excel attachment using FM SO_NEW_DOCUMENT_ATT_SEND_API1

    Hi ABAPers,
    I managed to send excel attachment using FM SO_NEW_DOCUMENT_ATT_SEND_API1.
    Let say I send it to my own email account.
    But, when try to open the excel document, from lotus notes, there is warning message produced by the microsoft excel saying:
    "The file is not in a recognizable format.
    and so on....."
    Anyway, when I click button 'OK', excel sheet will be opened and no information lost.
    How can we code the abap program so that the message will not come each time I open the attachment from my lotus notes?
    Or this is just the tab delimited issue?
    Thank you.
    Regards,
    Edward.

    Hi Shan,
    Thank you for replying.
    I have the same as follows:
      DESCRIBE TABLE lt_contents_hex LINES lv_lines.
      lt_packing_list-transf_bin = 'X'.
      lt_packing_list-head_start = 1.
      lt_packing_list-head_num   = 1.
      lt_packing_list-body_start = 1.
      lt_packing_list-body_num   = lv_lines.
      lt_packing_list-doc_type   = 'XLS'.
      lt_packing_list-obj_name   = 'ATTACHMENT'.
      lt_packing_list-obj_descr  = 'Attachment'.
      lt_packing_list-doc_size   = lv_lines * 255.
      APPEND lt_packing_list.
    I'm using lt_contents_hex instead of lt_contents_bin.
    Still the problem is there.
    Is there any other way to calculate the doc size correctly?
    Regards,
    Edward.

  • Error while sending Excel attachment thro FM 'SO_NEW_DOCUMENT_ATT_SEND_API1

    Experts:
    I am working on sending Excel as an email attachment thro the function module 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    I am able to send mail successfully but I face the following two issues while opening the attachment.
    1. While opening it says 'un recognized format' , on pressing 'OK' it opens the excel file.
    2. The column heading (first row) which should be in Korean character is displayed in junk char. I tried to
        specify the unicode (Code Page = '8500')  but does not know how to do it.
        I am reading the column header text from standard text.
    Please let me know what mistake I have commited in my code and where I should specify the unicode transformation. I refered many samples but could not make it.
    Please let me know the error.
    The code is as follows.
    FORM sendemail_barcodedata.
      TYPE-POOLS: truxs.
      DATA: objpack LIKE sopcklsti1 OCCURS 2  WITH HEADER LINE.
      DATA: objhead LIKE solisti1   OCCURS 1  WITH HEADER LINE.
      DATA: objbin  LIKE solisti1   OCCURS 10 WITH HEADER LINE.
      DATA: objbin1 LIKE solisti1   OCCURS 10 WITH HEADER LINE.
      DATA: objtxt  LIKE solisti1   OCCURS 10 WITH HEADER LINE.
      DATA: reclist LIKE somlreci1  OCCURS 5  WITH HEADER LINE.
      DATA: doc_chng LIKE sodocchgi1.
      DATA: tab_lines LIKE sy-tabix.
      DATA: l_sent_to_all  TYPE sonv-flag.
    * Creating the document to be sent
    * File Name
      doc_chng-obj_name  = 'BCODEINFO'.
    * Mail Subject
      doc_chng-obj_descr = 'Delivery Barcode Information'.
    * Mail Content
      objtxt = 'Hi:'.
      APPEND objtxt.
      objtxt = 'Find attached,  Delivery Barcode Information'.
      APPEND objtxt.
      CONCATENATE 'Attachment : <<' w_fname1 '>>' INTO objtxt.
      APPEND objtxt.
      DESCRIBE TABLE objtxt LINES tab_lines.
      READ TABLE objtxt INDEX tab_lines.
      doc_chng-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).
      doc_chng-obj_langu = sy-langu.
      doc_chng-sensitivty = 'F'.
    * Creating the entry for the compressed document
      CLEAR objpack-transf_bin.
      objpack-head_start = 1.
      objpack-head_num   = 0.
      objpack-body_start = 1.
      objpack-body_num   = tab_lines.
      objpack-doc_type   = 'RAW'.
      APPEND objpack.
    * Creating the document attachment
    * Get column names for Barcode Data
      CLEAR objbin.
      CONCATENATE text-h23
                  text-h24
                  text-h25
                  text-h26
                  text-h27
                  INTO  objbin  SEPARATED BY con_tab .
      CONCATENATE objbin con_cret INTO objbin.
      APPEND objbin.
      CLEAR objbin.
      LOOP AT it_excel2 INTO wa_excel2.
        CONCATENATE wa_excel2-zz_date
                    wa_excel2-zz_delivery
                    wa_excel2-zz_barcode
                    wa_excel2-blank1
                    wa_excel2-blank2
                    INTO objbin  SEPARATED BY con_tab.
        CONCATENATE objbin con_cret INTO objbin.
        APPEND objbin.
        CLEAR objbin.
      ENDLOOP.
      DESCRIBE TABLE objbin LINES tab_lines.
      objhead = w_fname1.
      APPEND objhead.
    * Creating the entry for the compressed attachment
      objpack-transf_bin = 'X'.
      objpack-head_start = 1.
      objpack-head_num   = 1.
      objpack-body_start = 1.
      objpack-body_num   = tab_lines.
      objpack-doc_type   = 'XLS'.
      objpack-obj_name   = 'Barcode Information'.
      objpack-obj_descr  = 'Barcode Information'.
      objpack-doc_size   = tab_lines * 255.
      APPEND objpack.
    * Entering names in the distribution list
      reclist-receiver = p_email.
      reclist-rec_type = 'U'.
      APPEND reclist.
    * Sending the document
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = doc_chng
          put_in_outbox              = ' '
          commit_work                = 'X'
        IMPORTING
         sent_to_all                 = l_sent_to_all
        TABLES
          packing_list               = objpack
          object_header              = objhead
          contents_bin               = objbin
          contents_txt               = objtxt
          receivers                  = 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.
      CASE sy-subrc.
        WHEN 0.
          MESSAGE i000(z65f_msgclass) WITH text-211.
        WHEN 1.
          WRITE: / 'no authorization to send to the specified number of'.
        WHEN 2.
          WRITE: / 'document could not be sent to any of the recipients!'.
        WHEN 4.
          WRITE: / 'no authorization to send !'.
        WHEN OTHERS.
          WRITE: / 'error occurred during sending !'.
      ENDCASE.
    ENDFORM.                 
    Thanks in advance.
    Regards
    Vijai

    Hi:
    Can any one provide me a solution for this?
    regards
    vijai

Maybe you are looking for

  • Add hidden fields in ALV

    Hi all,    I wanna add a new field in ALV field catalog, so that when user choose function Change Layout to decide which fields are showed, they can choose the new field. In orginal source, the ALV uses field catalog from structure<b> LIPOV.</b> And

  • How to use Harvester Only Using HarvesterSettings.xml on aia server

    Hi, I have a problem. I can not fix it. The following HarvesterSettings.xml I had to use. <?xml version="1.0" encoding="UTF-8"?> <tns:harvesterSettings xmlns:tns="http://www.oracle.com/oer/integration/harvester" xmlns:xsi="http://www.w3.org/2001/XMLS

  • SBS2008 WSUS Update Issues

    I'm trying to find out what the hell is going on with our WSUS. My desktop and laptop are the trial children for the issue and both were attached to the server the same way, both have the same errors when attempting to update (800B0001 or on install

  • Look for thesis (diploma) in NetWeaver

    Ladies and Gentlemen, I am new here, on this interesting homepage I would like to write my request, I study computerscience in the last study term, I am on look for extensive exciting task within the range a SAP NetWeaver as practical course place, a

  • How to hide text field item based on true or false cases in oracle apex

    Hi, I have a set of text Field items in oracle apex: Order Number Revision Number When we open the report, revision should be hidden. Only when the user enters unique order number (non-duplicate order numbers), revision number should be visible. If h