Long text in mail as excel attachment

Hi Experts,
I am sending internal table as excel attachment in mail through Function Module -  SO_DOCUMENT_SEND_API1.
But there is one field with long text. Pls help me how to send long text in excel sheet as mail attachment.
Regards,
Reny Richard

Hi,
And do your self a favor and use CL_BCS instead of SO_DOCUMENT_SEND_API1 .
See Send email from ABAP with class CL_BCS - Code Gallery - SCN Wiki
See Re: Excel formating in email attachment without using XML.
Use "where use" for class CL_BCS .
Regards.

Similar Messages

  • Problem in excel format while sending mail with excel attachment.

    Hi Gurus ,
    I am sending a email with Excel attachment using FM SO_DOCUMENT_SEND_API1 or SO_NEW_DOCUMENT_ATT_SEND_API1.
    I am able to send a mail with excel attachment with a piece of code which I got from SDN itself.
    But the problem is when I am trying to open the attachment, <b>A pop up comes which says that it is not in recognizable format. Would you like to open it?
    and several other lines of caution.</b>
    When i choose to open it, i get the correct data in one excel sheet. Certain vertical lines of the excel sheet is missing. <b>But no data is missing. </b>
    I am attaching the code below. Can any one please tell me where is the problem in this code ?
    Thanx in advance
    types: begin of t_mara,
    matnr type mara-matnr,
    matkl type mara-matkl,
    mtart type mara-mtart,
    meins type mara-meins,
    end of t_mara.
    data: gt_mara type table of t_mara,
    wa_mara like line of gt_mara,
    it_packing_list type table of SOPCKLSTI1,
    wa_packing_list like line of it_packing_list,
    it_receivers type table of SOMLRECI1,
    wa_receivers like line of it_receivers,
    it_mailbody type table of SOLISTI1,
    wa_mailbody like line of it_mailbody,
    it_attachment type table of SOLISTI1,
    wa_attachment like line of it_attachment.
    data: la_doc type SODOCCHGI1.
    constants:
    con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB,
    con_cret type c value cl_abap_char_utilities=>CR_LF.
    * get material
    select matnr matkl mtart meins
    into table gt_mara
    from mara
    up to 25 rows.
    * Populate the subject/generic message attributes
    la_doc-obj_langu = sy-langu.
    la_doc-obj_descr = 'Material Details' . "Mail Header
    la_doc-sensitivty = 'F'.
    la_doc-doc_size = 1.
    * Add the recipients email address
    CLEAR wa_receivers.
    REFRESH it_receivers.
    wa_receivers-receiver = 'PCSDEVL'.
    wa_receivers-rec_type = 'U'.
    wa_receivers-com_type = 'INT'.
    wa_receivers-notif_del = 'X'.
    wa_receivers-notif_ndel = 'X'.
    APPEND wa_receivers to it_receivers.
    * Mail Body
    CLEAR wa_mailbody.
    REFRESH it_mailbody.
    wa_mailbody-line = 'Please find the attachment'.
    APPEND wa_mailbody to it_mailbody.
    * Mail attachmwnt
    CLEAR wa_attachment.
    REFRESH it_attachment.
    CONCATENATE 'MATNR' 'MATKL' 'MTART' 'MEINS'
    INTO wa_attachment SEPARATED BY con_tab.
    CONCATENATE con_cret wa_attachment INTO wa_attachment.
    APPEND wa_attachment to it_attachment.
    LOOP AT gt_mara INTO wa_mara.
    CONCATENATE wa_mara-matnr wa_mara-matkl
    wa_mara-mtart wa_mara-meins
    INTO wa_attachment SEPARATED BY con_tab.
    CONCATENATE con_cret wa_attachment INTO wa_attachment.
    APPEND wa_attachment to it_attachment.
    ENDLOOP.
    * Describe the body of the message
    CLEAR wa_packing_list.
    REFRESH it_packing_list.
    wa_packing_list-transf_bin = space.
    wa_packing_list-head_start = 1.
    wa_packing_list-head_num = 0.
    wa_packing_list-body_start = 1.
    wa_packing_list-body_num = 1.
    wa_packing_list-doc_type = 'RAW'.
    APPEND wa_packing_list to it_packing_list.
    * Create attachment notification
    wa_packing_list-transf_bin = 'X'.
    wa_packing_list-head_start = 1.
    wa_packing_list-head_num = 1.
    wa_packing_list-body_start = 1.
    DESCRIBE TABLE it_attachment LINES wa_packing_list-body_num.
    wa_packing_list-doc_type = 'XLS'. " To word attachment change this as 'DOC'
    wa_packing_list-obj_descr = ' '.
    concatenate wa_packing_list-doc_type 'file' into wa_packing_list-OBJ_DESCR
    separated by space.
    wa_packing_list-doc_size = wa_packing_list-body_num * 255.
    APPEND wa_packing_list to it_packing_list.
    CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
    document_data = la_doc
    PUT_IN_OUTBOX = 'X'
    * SENDER_ADDRESS = SY-UNAME
    * SENDER_ADDRESS_TYPE = 'B'
    COMMIT_WORK = 'X'
    * IMPORTING
    * SENT_TO_ALL =
    * NEW_OBJECT_ID =
    * SENDER_ID =
    tables
    packing_list = it_packing_list
    * OBJECT_HEADER =
    CONTENTS_BIN = it_attachment
    CONTENTS_TXT = it_mailbody
    * CONTENTS_HEX =
    * OBJECT_PARA =
    * OBJECT_PARB =
    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
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.

    REPORT  Zex5 LINE-SIZE 255 LINE-COUNT 255 .
    class CL_ABAP_CHAR_UTILITIES definition load. "-->
    TABLES : vbap.
    SELECT-OPTIONS: s_vbeln FOR vbap-vbeln.
    DATA : BEGIN OF itab OCCURS 1,
           vbeln LIKE vbap-vbeln,
           posnr LIKE vbap-posnr,
           matnr LIKE vbap-matnr,
           END OF itab.
    parameters : p_email like somlreci1-receiver
    DATA: tlines type i.
    DATA: itmessage   LIKE solisti1 OCCURS 1 WITH HEADER LINE. "Ok
    DATA: itattach    LIKE solisti1 OCCURS 2 WITH HEADER LINE. "Ok
    DATA: itpacklist  LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.
    DATA: itreclist   LIKE somlreci1 OCCURS 5 WITH HEADER LINE.
    data: itattachment like solisti1 OCCURS 2 WITH HEADER LINE.
    start-of-selection.
      SELECT vbeln posnr matnr
             FROM vbap
             INTO TABLE itab
             WHERE vbeln IN s_vbeln.
    **Make the internal table data to be compatible in excel format .
      PERFORM BUILD_XLS_FORMAT.
    **Populate message of body text.
      clear itmessage.
      refresh itmessage.
      itmessage = 'Please find attached Excel file'.
      append itmessage.
      PERFORM send_mail_as_xls_attachment tables itmessage
                                                 itattach
             using p_email 'Excel Attachment' 'TXT'    " 'XLS'
              using p_email 'TEXT Attachment' 'TXT'    " 'XLS'
                            'TestFileName'
                            'SalesOrders' .
    *&      Form  BUILD_XLS_FORMAT
          text
    -->  p1        text
    <--  p2        text
    form BUILD_XLS_FORMAT.
    previosuly we were using for unicode ..now replaced
    **Declare constants for the spacing .
    *Constants : con1 type x value '0D',
               con2 type x value '09'.
      Constants : con1 type c
            value CL_ABAP_CHAR_UTILITIES=>CR_LF,
            con2 type c
            value CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    **For the Header descriptions.
      Concatenate 'SalesORdNo'
                  'Item'
                  'Materialno' into itattach separated by con2.
      Concatenate con1 itattach into itattach.
      Append itattach.
    **Now align the items in the itab as above .
      Loop at Itab.
        concatenate itab-vbeln
                    itab-posnr
                    itab-matnr into itattach separated by con2.
        concatenate con1 itattach into itattach .
        Append itattach.
      endloop.
    endform.                    " BUILD_XLS_FORMAT
    *&      Form  send_mail_as_xls_attachment
          text
         -->P_ITMESSAGE  text
         -->P_ITATTACH  text
         -->P_P_EMAIL  text
         -->P_0116   text
         -->P_0117   text
         -->P_0118   text
         -->P_0119   text
    form send_mail_as_xls_attachment tables   p_itmessage
                                              p_itattach
                                     using    p_email
                                              p_mtitle
                                              p_format
                                              p_filename
                                              p_attdescription.
      Data : xdocdata like sodocchgi1,
             xcnt type i.
    *Fill the document data.
      xdocdata-doc_size = 1.
    *Populate the subject/generic message attributes.
      xdocdata-obj_name  = 'SAPRPT'.
      xdocdata-obj_langu = sy-langu.
      xdocdata-obj_descr = p_mtitle.
    *Fill the document data and fetch size of attachment.
      clear xdocdata.
      read table itattach index xcnt.
      xdocdata-doc_size = ( xcnt - 1 ) * 255 + strlen( itattach ).
    xdocdata-doc_size =  ( xcnt - 1 ) * 255.
      xdocdata-obj_name  = 'SAPRPT'.
      xdocdata-obj_langu = sy-langu.
      xdocdata-obj_descr = p_mtitle.
      clear itattachment. refresh itattachment.
         itattachment[] = p_itattach[].
    *Describe the body of the message.
      clear itpacklist. refresh itpacklist.
      itpacklist-transf_bin = 'X'.
      itpacklist-head_start = '1'.
      itpacklist-head_num = '0'.
      itpacklist-body_start = '1'.
      describe table itattachment lines itpacklist-body_num .
      itpacklist-doc_type = 'TXT'.
    itpacklist-doc_type = 'XLS'.
      append itpacklist.
    *Create attachment notification.
      itpacklist-transf_bin = 'X'.
      itpacklist-head_start = '1'.
      itpacklist-head_num = '1'.
      itpacklist-body_start = '1'.
      describe table itattachment lines itpacklist-body_num .
      itpacklist-doc_type = p_format.
      itpacklist-obj_name = p_filename.
      itpacklist-obj_descr = p_attdescription.
      itpacklist-doc_size = itpacklist-body_num * 255 .
      append itpacklist.
    *FIll the receivers list.
      Clear itreclist. refresh itreclist.
      itreclist-receiver = p_email.
      itreclist-rec_type = 'U'.
      itreclist-com_type = 'INT'.
      itreclist-notif_del = 'X'.
      itreclist-notif_ndel = 'X'.
    *itreclist-notif_read = 'X'.
      append itreclist.
    *CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
    EXPORTING
      document_data                    = xdocdata
      PUT_IN_OUTBOX                    = 'X'
      commit_work    = 'X'
      SENDER_ADDRESS                   = SY-UNAME
    tables
       packing_list                    = itpacklist
       CONTENTS_BIN                    = itattachment
       CONTENTS_TXT                    = itmessage
       receivers                       = itreclist
    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.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *ENDIF.
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data              = xdocdata
          PUT_IN_OUTBOX              = 'X'
        TABLES
          packing_list               = itpacklist
          CONTENTS_BIN               = itattachment
          CONTENTS_TXT               = itmessage
          receivers                  = itreclist
        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.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    endform.                    " send_mail_as_xls_attachment
    Just execute the above code and let me know.
    What is the sap version u r using .
    Vijay

  • Sending mail with excel attachment-improper format

    Dear experts,
    I am sending a mail to outlook with an excel attachment. The mail is sent with attachment and the data, but all in one cell.
    I am using SO_NEW_DOCUMENT_ATT_SEND_API1. What parameters do i need to manipulate to have data in different columns of excel? I am using "packing_list" table of FM. But dont know the exact parameters to be passed. Can anyone help with the same please?
    Best regards and thanks!
    Sumit Nene.

    Hello Sumit,
    I am using same function module to send mail with excel attachment.
    Below I am attaching my own code for your reference.
    Data which u want to add in excel file is maintain in IT_OBJBIN i.e. document information.
    CLEAR :IMESSAGE,IT_OBJBIN,IT_OBJPACK,IT_RECLIST.
    REFRESH: IMESSAGE[ ] , IT_OBJBIN[ ]  , IT_OBJPACK[ ] ,  IT_RECLIST[ ].
    " populate the text for body of the mail
    CLEAR WA_IMESSAGE.
    CONCATENATE    'Board : ' P_BOARD ':' 'Please find  the excel attached for the list of Material whose routing is created'   INTO WA_IMESSAGE-LINE.
      APPEND WA_IMESSAGE TO IMESSAGE.
    "document information
      W_DOC_CHNG-OBJ_NAME = 'Excel'.
      IF NOT P_BOARD IS INITIAL.
        CONCATENATE    'Board : ' P_BOARD ':' 'List Of Routing Materials' INTO  W_DOC_CHNG-OBJ_DESCR.
      ELSE.
        CONCATENATE     'List Of' ' Routing Materials' INTO  W_DOC_CHNG-OBJ_DESCR.
      ENDIF.
      W_DOC_CHNG-SENSITIVTY = 'F'.  " ->Functional object
      " displaying  material , plant in the excel
      CONCATENATE 'BOARD NO : ' P_BOARD INTO WA_OBJBIN.
      APPEND WA_OBJBIN TO IT_OBJBIN.
      CONCATENATE 'MATERIAL' 'PLANT' 'DESCRIPTION' INTO WA_OBJBIN SEPARATED BY C_TAB.
      CONCATENATE C_RET WA_OBJBIN INTO WA_OBJBIN.
      APPEND WA_OBJBIN TO IT_OBJBIN.
      CLEAR : WA_OBJBIN.
      LOOP AT IT_DOWNLOAD INTO WA_DOWNLOAD. "It_orders is the internal table to be transferred to excel
        CONCATENATE WA_DOWNLOAD-MATNR WA_DOWNLOAD-WERKS WA_DOWNLOAD-DESC INTO WA_OBJBIN SEPARATED BY C_TAB.
        CONCATENATE C_RET WA_OBJBIN INTO WA_OBJBIN.
        APPEND WA_OBJBIN TO IT_OBJBIN.
      ENDLOOP.
      DESCRIBE TABLE IT_OBJBIN LINES V_LINES_BIN.   " no of lines for excel data
      " pack the data as RAW
      CLEAR WA_IT_OBJPACK-TRANSF_BIN.                     "Obj. to be transported not in binary form
      WA_IT_OBJPACK-HEAD_START = 1.                   "Start line of object header in transport packet
      WA_IT_OBJPACK-HEAD_NUM = 0.                     "Number of lines of an object header in object packet
      WA_IT_OBJPACK-BODY_START = 1.                   "Start line of object contents in an object packet
      WA_IT_OBJPACK-BODY_NUM = MESSAGE_LINES.         "Number of lines of the mail body
      WA_IT_OBJPACK-DOC_TYPE = 'RAW'.
      APPEND WA_IT_OBJPACK TO IT_OBJPACK.
      " pack the data as excel
      WA_IT_OBJPACK-TRANSF_BIN = 'X'.
      WA_IT_OBJPACK-HEAD_START = 1.
      WA_IT_OBJPACK-HEAD_NUM = 1.
      WA_IT_OBJPACK-BODY_START = 1.
      WA_IT_OBJPACK-BODY_NUM = V_LINES_BIN.         "no of lines of it_orders to give no of unprocessed orders
      WA_IT_OBJPACK-DOC_TYPE = 'XLS'.   " ->  excel fomat
      WA_IT_OBJPACK-OBJ_NAME = 'EXCEL ATTACHMENT'.
      " attachment name
      IF NOT P_BOARD IS INITIAL.
        CONCATENATE P_BOARD '.XLS' INTO WA_IT_OBJPACK-OBJ_DESCR.
      ELSE.
        CONCATENATE 'LIST' '.XLS' INTO WA_IT_OBJPACK-OBJ_DESCR.
      ENDIF.
      WA_IT_OBJPACK-DOC_SIZE = V_LINES_BIN * 255.
      APPEND WA_IT_OBJPACK TO IT_OBJPACK.
      " creating email id
      DATA: STR1 TYPE STRING,
          STR2 TYPE STRING,
          STR3 TYPE STRING,
          ITAB TYPE TABLE OF STRING.
      DATA : WA_I LIKE LINE OF ITAB.
      SPLIT P_EMAIL AT ',' INTO: TABLE ITAB.
    e-mail receivers.
      CLEAR WA_IT_RECLIST.
      LOOP AT ITAB INTO WA_I.
        WA_IT_RECLIST-RECEIVER = WA_I.
      WA_IT_RECLIST-RECEIVER = V_MAILADDR.
        WA_IT_RECLIST-EXPRESS =  'X'.
        WA_IT_RECLIST-REC_TYPE = 'U'. "->  Internet address
        APPEND WA_IT_RECLIST TO IT_RECLIST.
        CLEAR WA_IT_RECLIST.
      ENDLOOP.
      " sending mail
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          DOCUMENT_DATA                    = W_DOC_CHNG
         PUT_IN_OUTBOX                    = 'X'
         COMMIT_WORK                      = 'X'
       IMPORTING
         SENT_TO_ALL                      =
         NEW_OBJECT_ID                    =
        TABLES
          PACKING_LIST                     = IT_OBJPACK
         OBJECT_HEADER                    =
         CONTENTS_BIN                      = IT_OBJBIN
         CONTENTS_TXT                      = IMESSAGE
         CONTENTS_HEX                     =
         OBJECT_PARA                      =
         OBJECT_PARB                      =
          RECEIVERS                        = IT_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
      COMMIT WORK.
      IF SY-SUBRC = 0.
        MESSAGE I001 WITH 'Routing is Created for Board' P_BOARD 'and Mail send on e-mail id :' P_EMAIL.
      ENDIF.

  • Error in Sending Mail with excel attachment

    Hi All,
    While sending a mail with excel attachment it is getting successfully send but when i am opening the excel it gives a popup saying "The file is not in recognizable format", and when i click OK the data is getting displayed.
    So anybody has any idea of how to remove the popup??
    I am using SO_NEW_DOCUMENT_ATT_SEND_API1 FM for sending the mail.
    Can anybody help me regarding this.
    Thanks
    Salish

    Hi,
    I was facing the issue when I did not populate the parameters packing_list, object_header,contents_bin, contents_txt of the FM
    SO_NEW_DOCUMENT_ATT_SEND_API1 properly.
    Also the possible cause could be the configuration in SCOT, not very sure about this. Check with the BASIS guy.
    Regards,
    Sagar

  • Issue in sending e mails with Excel attachment

    Hi,
    I am facing an issue with one function module - SO_DOCUMENT_SEND_API1. We were using this for sending mails to diff destination with excel sheet attachment contains sales data. This system has been migrated from 4.5B to ECC 5. Now this process is not working like the old one and the excel attachment is not properly formatted. All the data is being written into one cell of excel sheet and it seems only one line is present in output and is corrupted.
    Can you please let me know what might be the issue here, any alternate option available or something to be modified in new version with this function module?
    Thanks in advance,
    Ullas

    Hi Ullas,
    check this once.
    REPORT  ZLAXMI_ALVMAIL4                         .
    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,
    Laxmi.

  • Sending mail with excel attachment

    Hi
    I need to send my a mail thru pl/sql procedure wit h an excel attachment
    I used the elow code. when trying to open the excel getting error in it .
    can anyone help out
    create or replace PROCEDURE send_mail_not IS
    v_mailConn utl_smtp.connection;
    v_err VARCHAR2(1000);
    v_message VARCHAR2(3000);
    crlf VARCHAR2(2) := CHR(13) || CHR(10);
    v_attachment varchar2(200);
    p_from_mail_id varchar2(200);
    p_to_mail_id varchar2(200);
    p_subject varchar2(200);
    BEGIN
    p_from_mail_id:= '[email protected]';
    p_to_mail_id :='[email protected]';
    p_subject :='error msg';
    v_attachment :='erer';
    v_mailconn := utl_smtp.open_connection('localhost', 25);
    utl_smtp.helo(v_mailconn, 'localhost');
    utl_smtp.mail(v_mailconn, '[email protected]');
    utl_smtp.rcpt(v_mailconn, '[email protected]');
    v_message := 'dfdfjkdflkdmf';
    dbms_output.put_line('Inside email procedure');
    v_message := 'Date: ' || TO_CHAR(SYSDATE, 'dd Mon yy hh24:mi:ss') || crlf ||
    'From: ' || p_from_mail_id || crlf || 'To: ' || '<' ||
    p_to_mail_id || '>' || crlf || 'Subject: ' ||
    p_subject || crlf ||
    'MIME-Version: 1.0'|| utl_tcp.crlf || -- use Mime mail standard
    'Content-Type: multipart/mixed;' || utl_tcp.crlf ||
    ' boundary="-----SECBOUND"'|| utl_tcp.crlf ||
    '-------SECBOUND'|| utl_tcp.crlf ||
    'Content-Type: text/html;'|| utl_tcp.crlf ||
    'Content-Transfer_Encoding: 8bit'|| utl_tcp.crlf ||
    utl_tcp.crlf ||
    v_message || utl_tcp.crlf || -- message body
    utl_tcp.crlf ||
    utl_tcp.crlf ||
    '-------SECBOUND'|| utl_tcp.crlf ||
    'Content-Type: text/plain;' || utl_tcp.crlf ||
    ' name="errr.log"'|| utl_tcp.crlf || -- file name that will hold the attached text
    'Content-Transfer_Encoding: 8bit'|| utl_tcp.crlf ||
    'Content-Disposition: attachment;'|| utl_tcp.crlf ||
    ' filename="error.xls"'|| utl_tcp.crlf ||
    utl_tcp.crlf ||
    v_attachment || utl_tcp.crlf || -- attachment
    utl_tcp.crlf ||
    '-------SECBOUND--' -- end mime mail
    utl_smtp.data(v_mailconn, v_message);
    utl_smtp.quit(v_mailconn);
    dbms_output.put_line('v_message');
    EXCEPTION
    WHEN OTHERS THEN
    v_err := sqlerrm;
    insert into pas.temp_trg values ('mail2', v_err, '');
    END send_mail_not;

    Your code had some syntactic errors... can you please try the below.. not tested.
    please let me know...
    CREATE OR REPLACE PROCEDURE send_mail_not
    IS
       v_mailconn       UTL_SMTP.connection;
       v_err            VARCHAR2 (1000);
       v_message        VARCHAR2 (3000);
       crlf             VARCHAR2 (2) := CHR (13) || CHR (10);
       v_attachment     VARCHAR2 (200);
       p_from_mail_id   VARCHAR2 (200);
       p_to_mail_id     VARCHAR2 (200);
       p_subject        VARCHAR2 (200);
    BEGIN
       p_from_mail_id := '[email protected]';
       p_to_mail_id := '[email protected]';
       p_subject := 'error msg';
       v_attachment := 'erer';
       v_mailconn := UTL_SMTP.open_connection ('localhost', 25);
       UTL_SMTP.helo (v_mailconn, 'localhost');
       UTL_SMTP.mail (v_mailconn, '[email protected]');
       UTL_SMTP.rcpt (v_mailconn, '[email protected]');
       v_message := 'dfdfjkdflkdmf';
       DBMS_OUTPUT.put_line ('Inside email procedure');
       v_message :=
             'Date: '
          || TO_CHAR (SYSDATE, 'dd Mon yy hh24:mi:ss')
          || crlf
          || 'From: '
          || p_from_mail_id
          || crlf
          || 'Subject: '
          || p_subject
          || crlf
          || 'To: '
          || p_to_mail_id
          || crlf
          || 'Mime-version: 1.0'
          || UTL_TCP.crlf
          ||                                             -- use Mime mail standard
            'Content-type: multipart/mixed;'
          || UTL_TCP.crlf
          || 'boundary="-----SECBOUND"'
          || UTL_TCP.crlf
          || '-------SECBOUND'
          || UTL_TCP.crlf
          || 'Content-Type: text/html;'
          || UTL_TCP.crlf
          || 'Content-Transfer_Encoding: 8bit'
          || UTL_TCP.crlf
          || UTL_TCP.crlf
          || v_message
          || UTL_TCP.crlf
          ||                                                       -- message body
            UTL_TCP.crlf
          || UTL_TCP.crlf
          || '-------SECBOUND'
          || UTL_TCP.crlf
          || 'Content-Type: text/plain;'
          || UTL_TCP.crlf
          || ' name="errr.log"'
          || UTL_TCP.crlf
          ||                         -- file name that will hold the attached text
            'Content-Transfer_Encoding: 8bit'
          || UTL_TCP.crlf
          || 'Content-Disposition: attachment;'
          || UTL_TCP.crlf
          || ' filename="error.xls"'
          || UTL_TCP.crlf
          || UTL_TCP.crlf
          || v_attachment
          || UTL_TCP.crlf
          ||                                                         -- attachment
            UTL_TCP.crlf
          || '-------SECBOUND--'                                  -- end mime mail
       UTL_SMTP.write_data (v_mailconn, v_message);
       UTL_SMTP.close_data (v_mailconn);
       UTL_SMTP.quit (v_mailconn);
       DBMS_OUTPUT.put_line ('v_message');
    EXCEPTION
       WHEN OTHERS
       THEN
          v_err := SQLERRM;
          INSERT INTO pas.temp_trg
               VALUES ('mail2', v_err, '');
    END send_mail_not;

  • Problem when sending mails with excel attached

    Hi
      I'm tryin to send mails via SAPOffice with attached excel documents. I'm using FM SO_NEW_DOCUMENT_ATT_SEND_API1. I have a problem with the code. Here I post it:
    DATA:  ti_objbin    LIKE solisti1   OCCURS 150 WITH HEADER LINE,
    ti_objhex    LIKE solix      OCCURS 150 WITH HEADER LINE.
    DATA: BEGIN OF i_excel,
    sobid(8) TYPE c,
    tab1 TYPE X VALUE 09, "tab code
    name(80) TYPE c,
    tab2 TYPE X VALUE 09, "tab code
    city(40) TYPE c,
    tab3 TYPE X VALUE 09, "tab code
    kostl(10) TYPE c,
    tab4 TYPE X VALUE 09, "tab code
    ktext(20) TYPE c,
    tab5 TYPE X VALUE 09, "tab code
    fasig(10) TYPE c,
    tab6 TYPE X VALUE 09, "tab code
    ruta(255) TYPE c,
    fin  TYPE X VALUE 13, "carriage return
    END OF i_excel.
    i_excel-sobid        = wa_datos-sobid.
    i_excel-name         = wa_datos-name.
    i_excel-city         = wa_datos-city.
    i_excel-kostl        = wa_datos-kostl.
    i_excel-ktext        = wa_datos-ktext.
    i_excel-fasig        = wa_datos-fasig.
    i_excel-ruta         = wa_datos-ruta.
    WRITE i_excel TO ti_objbin-line.
    APPEND ti_objbin.
    CLEAR  ti_objbin.
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
    document_data              = docdata
    put_in_outbox              = 'X'
    TABLES
    packing_list               = ti_objpack
    object_header              = ti_objhead
    contents_bin               = ti_objbin
    contents_txt               = ti_objtxt
    *      contents_hex               = ti_objhex
    receivers                  = ti_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.
    I have used this code before, in 4.6C release and it works fine, but now I'm on ECC5.0 and when i check the code, the next error message is generated: ""I_EXCEL" cannot be converted to a character-type field." If i try using MOVE i_excel TO i_objbin-line instead of WRITE, the error message changes to: ""TI_OBJBIN-LINE" and "I_EXCEL" are not mutually convertible in a Unicode program. program.". I have tried using ti_objhex table instead of ti_objbin in order to use 'context_hex' parameter (instead of 'context_bin') on FM, but i get the same result.
    I've been searching any other FM to do this, and i've found more FM of SOI1 function group but i didn´t get the expected result. So i need to send the message with the excel attached, using this FM or any other, but I need some help.  Anyone can help me?
    Thanks and Regards

    hi this is a simple example to send the excel sheet as a mail
    TABLES: ekko.
    PARAMETERS: p_email   TYPE somlreci1-receiver .
    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.
      data: ld_store(50) type c.  "Leading zeros
      CONSTANTS: con_cret(5) TYPE c VALUE '0D',  "OK for non Unicode
                 con_tab(5) TYPE c 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.
    *Modification to retain leading zeros
      inserts code for excell REPLACE command into ld_store
      =REPLACE("00100",1,5,"00100")
        concatenate '=REPLACE("' wa_charekpo-ebelp '",1,5,"'
                                 wa_charekpo-ebelp '")' into ld_store .
      concatenate ld_store into .xls file instead of actual value(ebelp)
        CONCATENATE wa_charekpo-ebeln ld_store  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,
    venkat.

  • Process of incoming mails including Excel attachment

    Hello Forum,
    we are looking for a possibility to process incoming e-mails including an Excel attachment.
    We are already able to receive e-mails in SAP, but we are not able to process/read the attachment in Excel format.
    I already checked the blogs of Thomas Jung and Gregor Wolf, but both didn't help for the XLS-attachments.
    Any ideas? Please help...
    Thanks
    Matthias

    Okay, so the question is not really about mail (that's just the context).
    I deduce from "Excel = hex" that you have to process native Excel files. In that case, this will be an issue as SAP doesn't offer software to decode native files.
    From ABAP, the only possibility is to use OLE2 (ABAP statements CREATE OBJECT ... OF, CALL METHOD ... OF, etc.) but that can only work when code is executed in dialog workprocesses, that is not the case here as you are processing inbound mails.
    So, I think you can only:
    1) ask users to save Excel files as any text type (CSV, XML...)
    2) delay the processing of the native excel files, users will have to later launch online (dialog) transactions that will read these files using OLE2
    3) get a specialized software (free or not) to read native Excel files
    4) Install a server (Microsoft OS) with Excel installed (licence cost probably), which will be called by SAP to decode the file and return the result

  • Sending Mail As Excel Attachment

    Dear ALL,
    I have a requirement to send the output of ALV as excel attachment when the user clicks the button. I have written the complete code and the mail is also successfully send. But the issue is that all the ALV output is coming in 1 Column in excel attachement.
    I have already searched in SDN and tried all the related posts. But could not succeed.
    Here is my sample code which I have used for separating the contents:-
    Here W_BELNR etc contains the Heading Used for Column.
    CONCATENATE W_BELNR W_BUDAT W_BLDAT W_VBELN W_BLART W_BI_DESC W_UMSKZ W_WEVWV
                      W_DRAMT W_CRAMT W_CUMAMT W_ZUONR W_WRBTR W_WAERS W_AUGBL W_FLAG W_PRCTR
                      W_XBLNR W_SGTXT W_ZTERM W_ZTERMT W_VKAUS W_VKAUST W_BAANR
                   INTO W_LONGTEXT SEPARATED BY CON_TAB.
          IT_OBJBIN = W_LONGTEXT.
          APPEND IT_OBJBIN. CLEAR IT_OBJBIN.
    LOOP AT ITAB_BSAD_TRN_NEW4 INTO W_ITAB_BSAD_TRN_NEW4.
            DRAMT_NEW = W_ITAB_BSAD_TRN_NEW4-DRAMT.
            CRAMT_NEW = W_ITAB_BSAD_TRN_NEW4-CRAMT.
            CUMAMT_NEW = W_ITAB_BSAD_TRN_NEW4-CUMAMT.
            WRBTR_NEW = W_ITAB_BSAD_TRN_NEW4-WRBTR.
            CONCATENATE W_ITAB_BSAD_TRN_NEW4-BELNR      W_ITAB_BSAD_TRN_NEW4-BUDAT
                        W_ITAB_BSAD_TRN_NEW4-BLDAT      W_ITAB_BSAD_TRN_NEW4-VBELN
                        W_ITAB_BSAD_TRN_NEW4-BLART      W_ITAB_BSAD_TRN_NEW4-BI_DESC
                        W_ITAB_BSAD_TRN_NEW4-UMSKZ      W_ITAB_BSAD_TRN_NEW4-WEVWV
                          DRAMT_NEW
                        CRAMT_NEW
                        CUMAMT_NEW
                           W_ITAB_BSAD_TRN_NEW4-ZUONR
                        WRBTR_NEW
                         W_ITAB_BSAD_TRN_NEW4-WAERS
                        W_ITAB_BSAD_TRN_NEW4-AUGBL      W_ITAB_BSAD_TRN_NEW4-FLAG
                        W_ITAB_BSAD_TRN_NEW4-PRCTR      W_ITAB_BSAD_TRN_NEW4-XBLNR
                        W_ITAB_BSAD_TRN_NEW4-SGTXT      W_ITAB_BSAD_TRN_NEW4-ZTERM
                        W_ITAB_BSAD_TRN_NEW4-ZTERMT     W_ITAB_BSAD_TRN_NEW4-VKAUS
                        W_ITAB_BSAD_TRN_NEW4-VKAUST     W_ITAB_BSAD_TRN_NEW4-BAANR
                      INTO I_DLOAD-DLOAD
                      SEPARATED BY CON_TAB.
            IT_OBJBIN = I_DLOAD-DLOAD.
            APPEND IT_OBJBIN. CLEAR IT_OBJBIN.
          ENDLOOP.
    CALL FUNCTION 'SO_RAW_TO_RTF'
          TABLES
            OBJCONT_OLD = IT_OBJBIN
            OBJCONT_NEW = IT_OBJBIN.
    Kindly guide me in this matter.
    Thanks & Regards,
    Bharti Jain
    Edited by: Bharti Jain on Aug 25, 2011 7:23 AM

    This is the code which I have written.
          CONCATENATE 'Display Message' ' ' INTO IT_OBJTXT
          SEPARATED BY SPACE.
          APPEND IT_OBJTXT.
          CLEAR IT_OBJTXT.
          IT_RECLIST-RECEIVER = WS_EMAIL.
          IT_RECLIST-REC_TYPE = 'U'.
          IT_RECLIST-EXPRESS  = ' '.
          IT_RECLIST-COM_TYPE = 'INT'.
          APPEND IT_RECLIST.
          CLEAR: W_TEXT.
          DOC_CHNG-OBJ_DESCR = 'Customer Balance'.
          DOC_CHNG-OBJ_NAME  = 'INBOUND'.
          DESCRIBE TABLE IT_OBJTXT LINES TAB_LINES.
          READ TABLE IT_OBJTXT INDEX TAB_LINES.
          DOC_CHNG-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( IT_OBJTXT ).
         CLEAR: W_LONGTEXT.
          W_LONGTEXT = 'GRASIM INDUSTRIES LIMITED.'.
          IT_OBJBIN = W_LONGTEXT.
          APPEND IT_OBJBIN. CLEAR IT_OBJBIN.
    *****Here looping at internal table
    Loop at itab into wtab
    CONCATENATE WTAB-BELNR      WTAB-BUDAT etc.......
    INTO I_DLOAD-DLOAD
                      SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
            CONCATENATE CON_CRET I_DLOAD-DLOAD INTO I_DLOAD-DLOAD.
            IT_OBJBIN-LINE = I_DLOAD-DLOAD.
            APPEND IT_OBJBIN. CLEAR IT_OBJBIN.
          ENDLOOP.
    DESCRIBE TABLE IT_OBJTXT LINES TAB_LINES.
      CLEAR IT_OBJPACK-TRANSF_BIN.
      IT_OBJPACK-HEAD_START = 1.
      IT_OBJPACK-HEAD_NUM   = 0.
      IT_OBJPACK-BODY_START = 1.
      IT_OBJPACK-BODY_NUM   = TAB_LINES.
      IT_OBJPACK-DOC_TYPE   = 'RAW'.
      APPEND IT_OBJPACK.
      DESCRIBE TABLE IT_OBJBIN LINES TAB_LINES.
      IT_OBJPACK-HEAD_START = 1.
      IT_OBJPACK-HEAD_NUM   = 0.
      IT_OBJPACK-BODY_START = 1.
      IT_OBJPACK-BODY_NUM   = TAB_LINES.
      IT_OBJPACK-TRANSF_BIN = 'X'."'C'.
      IT_OBJPACK-DOC_TYPE   = 'CSV'.
      IT_OBJPACK-OBJ_DESCR  = W_FILENAME.
      IT_OBJPACK-OBJ_NAME   = 'BILLING'.
    IT_OBJPACK-DOC_SIZE   = TAB_LINES * 255.
      IT_OBJPACK-DOC_SIZE   = 100000.
      APPEND IT_OBJPACK.
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
         EXPORTING
           DOCUMENT_DATA              = DOC_CHNG
         PUT_IN_OUTBOX              = c_x
           COMMIT_WORK                = 'X'
         TABLES
           PACKING_LIST               = IT_OBJPACK
         object_header              = it_objhead
           CONTENTS_BIN               = IT_OBJBIN
           CONTENTS_TXT               = IT_OBJTXT
           RECEIVERS                  = IT_RECLIST
         EXCEPTIONS
           TOO_MANY_RECEIVERS         = 1
           DOCUMENT_NOT_SENT          = 2
           OPERATION_NO_AUTHORIZATION = 4
           OTHERS                     = 99.
      IF SY-SUBRC <> 0.
       WRITE: / 'failure in sending mail'.
        MESSAGE 'Mail Could Not Be Sent To This Customer.' TYPE 'S'.
      ELSE.
        MESSAGE 'Mail Successfully Sent To This Customer.' TYPE 'S'.
      ENDIF.
    Regards,
    Bharti Jain

  • Problem with EXCEL format while sending a mail with excel attachment

    Hi,
    I'm trying to send a report through mail as an excel attchment. But though I get all the details in the attachmnet format in excel is not proper. It's in a very hapazard way. I tried putting control break statements after each record then also though there is slight betterment it's not ok. If I send the same thing as a pdf attachment it's perfect. May I know what else i need to do for excel.....? I tried compressing and then sending no luck......
    I'm in version 4.6c.....
    Thanks in advance....

    Hi,
    Just check out this..
    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.
      CONCATENATE 'EBELN' 'EBELP' 'AEDAT' 'MATNR'
             INTO it_attach SEPARATED BY space.
      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 space.
        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 = 'This mail is scheduled automatically and excel file is
                    attached for your reference'.
      APPEND it_message.
    endform.                    " POPULATE_EMAIL_MESSAGE_BODY
    Regards,
    Sriram.
    PS: Reward Points if it is useful.

  • 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

  • Excel 2007 Problems while sending E-Mail with Excel Attachment

    Hello all,
    i wrote a small WD application for uploading a file and sending this file
    vie e-mail to some recipients.
    I'm using class "cl_document_bcs". No problem with ".doc", ".pdf", also no problem
    with ".xls" files generated by old Excel version. But when generating an .xls document with
    Excel 2007, the attached file is not readable (just non usable signs).
    For attaching the .xls file i use:
      TRY.
          lr_attachment =  cl_document_bcs=>create_document(
              i_type        = lv_filetype " --> 'XLS'
              i_subject     = 'excel document'
              i_hex         = lt_file_solix
        CATCH cx_document_bcs .
      ENDTRY.
    Are there any restrictions regarding Excel 2007?
    The data element of i_type is just char3, so XLSX
    wouldn't be possible.

    hello Christopher Linke ,
    if you Programatically generation a excel file and you have 2007 version you can use OLE automation to save file as .xls i.e. a 2003 work book ..
    if you have a excel file ready and you just want to send it across the you will have to convert the xlsx to xls and then send it you can do this as well using OLE automation
    (in 2007 in SAVE AS option you can save it excel 97 2003 workbook)
    Edited by: Anup Deshmukh on Mar 3, 2010 3:38 PM

  • How to send Java Mail with EXCEL attachment?

    I tried the following:
    ByteArrayDataSource bs = new ByteArrayDataSource (is, "application/excel");
    as my datasource (all other apis are fine)
    But when I send this message with this datasource as attachment,I get a ParseException with the VM complaining about malformed headers.
    Please help

    Exactly when do you get the ParseException, and what's the message
    with the exception?
    BTW, "application/excel" is not the correct MIME type for Microsoft Office
    Excel files. The correct MIME type is "application/vnd.ms-excel".
    http://www.iana.org/assignments/media-types/application/vnd.ms-excel

  • Issue with Excel Attachement in BI 7.0

    Hi,
    I have developed a custom report to send an e-mail with excel attachment in BI 7.0. When we are trying to open the excel sheet attachment in the e-mail. I am getting a message warning message stating that<b> 'This file is not in a recognizable format'</b>. but if we click on ok button then everything looks fine i.e the data is displaying as expected.
    I have developed the same reports in SAP R/3 and SRM but I don't see any issues over there.
    Can any one help me on this issue.
    Thanks in advance,
    Venkat Bomma

    When the selection screen pops up choose the KEY only function on the TOOLS on the top right corner of the screen. Then you will be able to enter the values manually.
    Hope this helps.

  • Mail sending with attachment

    Hi all,
            i'm working on badi i need to send a mail with excel attachment, if you have sample code pls
    send me.
    Regards
    Suprith

    hi
    refer to this thread
    Re: Send mails with attachment to external email id
    hope this helps
    regards
    Aakash Banga

Maybe you are looking for

  • Transformation issue while using IF condition.

    hi everyone, i am using bpel transformation based on the condition of field using IF condition. A       B          C          D 10     20          30          40 20     20          30          50 30     30          20          60 40     40          2

  • Metadata filter doesn't show counts 99,999

    I now have over 100,000 photos in my library, and for some reason the metadata filter (metadata browser) won't show image counts with 6 digits. Perhaps there is a setting (like a font I could choose) that would solve this problem? Or is this just ano

  • How to run query in parallel  to improve performance

    I am using ALDSP2.5, My data tables are split to 12 ways, based on hash of a particular column name. I have a query to get a piece of data I am looking for. However, this data is split across the 12 tables. So, even though my query is the same, I nee

  • VL 2000 Call for Participation

    VL'2000: IEEE Symposium on Visual Languages September 10-14, 2000 Seattle, Washington http://www.cs.orst.edu/~burnett/vl2000/ Call for Participation VL'2000 is the premier international conference on visual and multimedia languages for creating/under

  • Manual for 3GS ?

    Is there an 'official' manual for my 3GS so I can learn about voice activation etc thanks Pete