4 Replies Latest reply: Dec 3, 2007 8:50 AM by chandra madapati RSS

Urgent: Sending an Email with Excel sheet attachment

satya srinivas mukkavilli
Currently Being Moderated

Hi All,

 

I am preparing a report and has to send mail with excel sheet attachement. In report i am getting everything fine. But in the mail i am not getting the data, data is passing to the FM succesfully. But in the mail, excel is not having full data.

 

the below mentioned is my code.

 

i_texts-line = c_stern.

  i_texts-line+254(1) = c_newline.

  APPEND i_texts.

 

  LOOP AT i_texc.

    i_att_line-line = i_texc.

    APPEND i_att_line.

  ENDLOOP.

 

  DATA: wa_doc_chng LIKE sodocchgi1.

  DATA: w_tab_lines LIKE sy-tabix.

  STATICS: c_body_start TYPE i VALUE '1'.

  CONSTANTS: lc_filename(10) TYPE c VALUE 'Attachment',

             lc_atthead(30)  TYPE c VALUE 'Manually released invoices'.

  DATA: i_objpack LIKE sopcklsti1 OCCURS 2 WITH HEADER LINE.

  DATA: w_doc_name(30) TYPE c.

  DATA: l_text1(15),

        l_text2(12),

        l_text3(15),

        l_text4(15),

        l_text5(14),

        l_text6(17),

        l_text7(10),

        l_text8(20),

        l_text9(19),

        l_text10(19),

        l_text11(19),

        l_text12(16),

        l_text13(20),

        l_text14(19),

        l_text15(19),

        l_text16(30).

 

  DATA: DATE(10),

        DT(2),

        MON(3),

        YR(4),

        lc_final(50).

 

  CLEAR: i_texts, i_reci,i_att_line.                "i_bname,

  REFRESH: i_texts, i_reci,i_att_line.              "i_bname,

  WRITE sy-datum TO w_datex.

  WRITE sy-uzeit TO w_timex.

 

 

  l_text1 = text-003.

  l_text2 = text-004.

  l_text3 = text-005.

  l_text4 = text-006.

  l_text5 = text-007.

  l_text6 = text-008.

  l_text7 = text-009.

  l_text8 = text-010.

  l_text9 = text-011.

  l_text10 = text-012.

  l_text11 = text-013.

  l_text12 = text-014.

  l_text13 = text-015.

  l_text14 = text-016.

  l_text15 = text-017.

  l_text16 = text-026.

 

  CONCATENATE

  l_text1

  l_text2

  l_text3

  l_text4

  l_text5

  l_text6

  l_text7

  l_text8

  l_text9

  l_text10

  l_text11

  l_text12

  l_text13

  l_text14

  l_text15

  l_text16

  INTO i_texts SEPARATED BY

  c_horz_tab.

 

  i_texts-line+254(1) = c_newline.

 

  APPEND i_texts.

  CLEAR  i_texts.

 

 

 

  LOOP AT i_texc.

    i_att_line-line = i_texc.

    APPEND i_att_line.

  ENDLOOP.

  LOOP AT so_rec.

    i_reci-receiver = so_rec-low.

    i_reci-express = 'X'.

    i_reci-rec_type = 'U'.

    APPEND i_reci.

  ENDLOOP.

 

  DESCRIBE TABLE i_texts LINES w_tab_lines.

  READ TABLE i_texts INDEX w_tab_lines.

  wa_doc_chng-doc_size = ( w_tab_lines - 1 ) * 255 + STRLEN( i_texts ).

 

  wa_obj_name   = 'ZFI_XX_REL_BLOCKED_INVOICE_01'.

 

  DT  = SY-DATUM+6(2).

  MON = SY-DATUM+4(2).

  YR  = SY-DATUM+0(4).

  CONCATENATE DT MON YR INTO DATE SEPARATED BY '-'.

 

  CONCATENATE lc_atthead date into lc_final separated by ' '.

 

  MOVE lc_final

               TO wa_obj_descr .

 

  wa_doc_chng-obj_name  = wa_obj_name.

  wa_doc_chng-obj_descr = wa_obj_descr.

 

 

  CLEAR i_objpack-transf_bin.

  i_objpack-head_start = 1.

  i_objpack-head_num = 0.

  i_objpack-body_start = 0.

  i_objpack-body_num = w_tab_lines.

  i_objpack-doc_type = 'RAW'.

  APPEND i_objpack.

 

  APPEND LINES OF i_att_line TO i_texts.

 

  LOOP AT i_arseg INTO wa_arseg.

    i_xmplt_d-belnr = wa_arseg-belnr.

    i_xmplt_d-budat = wa_arseg-budat.

    i_xmplt_d-bukrs = wa_arseg-bukrs.

    i_xmplt_d-lifnr = wa_arseg-lifnr.

    i_xmplt_d-name1_lifnr = wa_arseg-name1_lifnr.

    i_xmplt_d-wrbtr = wa_arseg-wrbtr.

    i_xmplt_d-waers = wa_arseg-waers.

    i_xmplt_d-ebeln = wa_arseg-ebeln.

    i_xmplt_d-ebelp =  wa_arseg-ebelp.

    i_xmplt_d-reason = wa_arseg-reason.

    i_xmplt_d-dmeng = wa_arseg-dmeng.

    i_xmplt_d-dwert = wa_arseg-dwert.

    i_xmplt_d-bname = wa_arseg-bname.

    i_xmplt_d-name_text = wa_arseg-name_text.

    i_xmplt_d-udate = wa_arseg-udate.

    i_xmplt_d-comment =  wa_arseg-comment.

    APPEND i_xmplt_d.

  ENDLOOP.

 

  LOOP AT i_xmplt_d.

    CONCATENATE i_xmplt_d-belnr

                i_xmplt_d-budat

                i_xmplt_d-bukrs

                i_xmplt_d-lifnr

                i_xmplt_d-name1_lifnr

                i_xmplt_d-wrbtr

                i_xmplt_d-waers

                i_xmplt_d-ebeln

                i_xmplt_d-ebelp

                i_xmplt_d-reason

                i_xmplt_d-dmeng

                i_xmplt_d-dwert

                i_xmplt_d-bname

                i_xmplt_d-name_text

                i_xmplt_d-udate

                i_xmplt_d-comment

                INTO i_texts SEPARATED

                BY c_horz_tab.

 

    i_texts-line+254(1) = c_newline.

 

    APPEND i_texts.

    CLEAR i_texts.

 

  ENDLOOP.

 

  DESCRIBE TABLE i_texts LINES w_tab_lines.

  READ TABLE i_texts INDEX w_tab_lines.

  wa_doc_chng-doc_size = ( w_tab_lines - 1 ) * 255 + STRLEN( i_texts ).

  DESCRIBE TABLE i_texts LINES w_tab_lines.

  i_objpack-transf_bin = ' '.

  i_objpack-head_start = 0.

  i_objpack-head_num = 0.

  i_objpack-body_start = 1.

  i_objpack-body_num = w_tab_lines.

  i_objpack-doc_type = 'XLS'.

  i_objpack-obj_name = 'Attachment'.

  • i_objpack-obj_descr = w_doc_name.

  i_objpack-obj_descr = lc_filename.

  i_objpack-doc_size = w_tab_lines * 255.

  APPEND i_objpack.

 

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

    EXPORTING

      document_data              = wa_doc_chng

    TABLES

      packing_list               = i_objpack

      contents_txt               = i_texts

      receivers                  = i_reci

    EXCEPTIONS

      too_many_receivers         = 1

      document_not_sent          = 2

      operation_no_authorization = 4

      OTHERS                     = 99.

 

  IF sy-subrc = 0.

    COMMIT WORK.

  ELSE.

    WRITE: / 'Error in send E-Mail' .

  ENDIF.

 

please revert me asap. It is very urgent to me. thanks in advance.

 

Bye

  • Re: Urgent: Sending an Email with Excel sheet attachment
    Currently Being Moderated

    hI

     

    The code below demonstrates how to send an email to an external email address(test@sapdev.co.uk),

    where the data is stored within a .xls attachment.

     

     

    *&---------------------------------------------------------------------*
    *& Report  ZEMAIL_ATTACH                                               *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    *& Example of sending external email via SAPCONNECT                    *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    REPORT  ZEMAIL_ATTACH                   .
    TABLES: ekko.
    
    PARAMETERS: p_email   TYPE somlreci1-receiver
                                      DEFAULT 'test@sapdev.co.uk'.
    
    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

     

  • Re: Urgent: Sending an Email with Excel sheet attachment
    Currently Being Moderated

    hI

     

    Have you build your Excel Data table to get attachement in Mail? If no then please find the Eg. code for your reference to send Excel attachment..

     

     

    ************************************************************************
    * End of Selection Event : Displaying the selected data                *
    ***********************************************************************
    END-OF-SELECTION.
        PERFORM EMAIL_EXCEL_ATTACHMENT.
     
    ******///form
    FORM EMAIL_EXCEL_ATTACHMENT .
     
    * Populate table with detaisl to be entered into .xls file
      PERFORM BUILD_XLS_DATA_TABLE.
    * 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 S_EMAIL
                                          TEXT-042
                                          C_XLS
                                          'filename'
                                          ' '
                                          ' '
                                          ' '
                                 CHANGING GD_ERROR
                                          GD_RECIEVER.
     
    *   Instructs mail send program for SAPCONNECT to send email(rsconn01)
      PERFORM INITIATE_MAIL_EXECUTE_PROGRAM.
     
    ENDFORM.                    " EMAIL_EXCEL_ATTACHMENT
     
    ********///form BUILD_XLS_DATA_TABLE
    FORM BUILD_XLS_DATA_TABLE .
     
      DATA :    LV_NETWR(20)     TYPE C,
                LV_BOL_DATE(20)  TYPE C,
                LV_KAWRT(20)     TYPE C,
                LV_FKDAT(20)     TYPE C,
                LV_WAERK(20)     TYPE C,
                LV_KURRF(20)     TYPE C,
                LV_SHIPDATE(20)  TYPE C,
                LV_DEPTDATE(20)  TYPE C.
     
     
      CONSTANTS:
          CON_TAB  TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
          CON_CRET TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF.  "#EC *
     
      DATA STR TYPE STRING.
    **********/ this parameter concatenate to get headers
      CONCATENATE STR
      'SLNO'
      'OWNER'
      'SERIAL NO'
      'FROM'
      'DESTINATION'
      'INVOICE VALUE'
      'DESCRIPTION'
      'CUSTOMER NAME'
      'BL NUMBER'
      'BL DATE'
      'VESSEL NAME/AIRLINE DETAILS'
      'MODE OF TRANSIT'
      'SHIPPING MARKS'
      'DUTY SUM INSURED'
      'FLAG'
      'OPEN COVERNO'
      'INVOICE DATE'
      'INVOICE NO'
      'LC WORDING'
      'QUANTITY'
      'PACKAGING DETAILS'
      'BASIS OF VALUATION'
      'EXCLUDE WAR SRCC'
      'CURRENCY'
      'EXCHANGE RATE'
      'ADDRESS'
      'VESSEL BUILT YEAR'
      'VESSEL FLAG'
      'VOYAGE NO'
      'SHIPMENT DATE'
      'DEPARTURE DATE'
      'SURVEYOR COUNTRY'
      'SURVEYOR CITY'
      'SURVEYOR AGENT'
      'SURVEYOR ADDRESS'
      'EXPORT CONSIGNMENT'
      'CONTAINER DETAILS'
     
      CL_ABAP_CHAR_UTILITIES=>CR_LF INTO STR SEPARATED BY CON_TAB.
     
      LOOP AT IT_FINAL.
    *******/ this is to pass body / row data 
        WRITE : IT_FINAL-NETWR    TO LV_NETWR,              "#EC UOM_IN_MES
                IT_FINAL-BOL_DATE TO LV_BOL_DATE,
                IT_FINAL-KAWRT    TO LV_KAWRT,              "#EC UOM_IN_MES
                IT_FINAL-FKDAT    TO LV_FKDAT,
                IT_FINAL-WAERK    TO LV_WAERK,
                IT_FINAL-KURRF    TO LV_KURRF,
                IT_FINAL-SHIPDATE TO LV_SHIPDATE,
                IT_FINAL-DEPTDATE TO LV_DEPTDATE.
     
        CONCATENATE
               STR
               IT_FINAL-SLNO
               IT_FINAL-OWNER
               IT_FINAL-SRNO
               IT_FINAL-PORT_LOAD
               IT_FINAL-PORT_DSCHR
               LV_NETWR
               IT_FINAL-DESCRIP
               IT_FINAL-CUSTNAME
               IT_FINAL-BOL_NUM
               LV_BOL_DATE
               IT_FINAL-VESSELNAME
               IT_FINAL-SHP_TYPE
               IT_FINAL-SHP_MARK
               LV_KAWRT
               IT_FINAL-FLAG
               IT_FINAL-OPEN_CONO
               LV_FKDAT
               IT_FINAL-VBELN
               IT_FINAL-LC_WORD
               IT_FINAL-QUANT
               IT_FINAL-PACKDETL
               IT_FINAL-INCO1
               IT_FINAL-EXCWSR
               LV_WAERK
               LV_KURRF
               IT_FINAL-ADDPAY
               IT_FINAL-VESSBYR
               IT_FINAL-VESSFLG
               IT_FINAL-VOY_FLY_NO
               LV_SHIPDATE
               LV_DEPTDATE
               IT_FINAL-SURCOUNT
               IT_FINAL-INCO2
               IT_FINAL-EXPORT_CON
               IT_FINAL-SURAGT
               IT_FINAL-SURADD
               IT_FINAL-CONTRNO
     
       CL_ABAP_CHAR_UTILITIES=>CR_LF INTO STR SEPARATED BY CON_TAB.
     
      ENDLOOP.
     
      CALL FUNCTION 'SCMS_STRING_TO_FTEXT'
        EXPORTING
          TEXT      = STR
        TABLES
          FTEXT_TAB = IT_ATTACH.
     
    ENDFORM.                    " BUILD_XLS_DATA_TABLE
     
    ******// form POPULATE_EMAIL_MESSAGE_BODY
    FORM POPULATE_EMAIL_MESSAGE_BODY .
     
      REFRESH IT_MESSAGE.
      IT_MESSAGE = TEXT-043.  " Please find attached Insurance Certificate details
      APPEND IT_MESSAGE.
     
    ENDFORM.                    " POPULATE_EMAIL_MESSAGE_BODY
     
     
    *******'/ form SEND_FILE_AS_EMAIL_ATTACHMENT
    *&---------------------------------------------------------------------*
    *&      Form  SEND_FILE_AS_EMAIL_ATTACHMENT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->PIT_MESSAGE           text
    *      -->PIT_ATTACH            text
    *      -->P_EMAIL               text
    *      -->P_MTITLE              text
    *      -->P_FORMAT              text
    *      -->P_FILENAME            text
    *      -->P_ATTDESCRIPTION      text
    *      -->P_SENDER_ADDRESS      text
    *      -->P_SENDER_ADDRES_TYPE  text
    *      -->P_ERROR               text
    *      -->P_RECIEVER            text
    *----------------------------------------------------------------------*
    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.       "#EC *
     
      DATA: LD_ERROR    TYPE SY-SUBRC,                          "#EC *
    *        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.                         "#EC *
     
    *  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.
      DESCRIBE TABLE IT_ATTACH LINES W_CNT.
      READ TABLE IT_ATTACH INDEX W_CNT.
      W_DOC_DATA-DOC_SIZE =
         W_CNT * 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.
      LOOP AT S_EMAIL.
        T_RECEIVERS-RECEIVER = S_EMAIL-LOW.
        T_RECEIVERS-REC_TYPE = 'U'.
        T_RECEIVERS-COM_TYPE = 'INT'.
        T_RECEIVERS-NOTIF_DEL = 'X'.
        T_RECEIVERS-NOTIF_NDEL = 'X'.
        APPEND T_RECEIVERS.
      ENDLOOP.
      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.                    " SEND_FILE_AS_EMAIL_ATTACHMENT
     
    *******/form
     
    *&---------------------------------------------------------------------*
    *&      Form  INITIATE_MAIL_EXECUTE_PROGRAM
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    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
    
    
    
    
    
    
    *********end of code to trigger mail in excel format....

     

     

    If any other help please let me know......

     

    I am sure this example code will help you to resolve your problem...

     

    please analyse above code for your requirement...

     

    In my scenario the message you said is not displaying.....

     

     

    Reward Points

Actions