Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Problem in sending mail

Hi all

I have a probleem in sending the rejected records after the user uploads an excel sheet, to the users inbox.I hav populated the int table it_rej and hav used the form send_mail as given below.

My problem is dat, eventhogh the int table contains 2 entries other than the header, the excel sheet in the email contains only the 1st record other than the header. and also in the comments field the entire text is not beig displayed.i hav been sittin with dis for the past 2 days without ny solution...Please help me out.

useful answers will be awarded.

Regards

Winnie


FORM send_mail .

  REFRESH objtxt.
  CLEAR : objtxt,
          index.

  CONCATENATE 'The Number of Records Rejected are : ' temprej INTO objtxt-line.
  APPEND objtxt.         "to be displayed on the screen not in xcel sheet


  LOOP AT it_rej               INTO wa_rej.

    index = sy-tabix.
    MOVE wa_rej-zfg            TO   lv_zfg.
    MOVE wa_rej-zflag           TO   lv_zflag.
    MOVE wa_rej-comments          TO   lv_comments.

    IF index <> 1.
      CONDENSE: lv_zfg,
                lv_zflag
                 NO-GAPS.
    ENDIF.

    CONCATENATE lv_zfg
                lv_zflag
                lv_comments
                INTO objtxt-line SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
    APPEND objtxt.


    CLEAR wa_rej.
  ENDLOOP.

  DESCRIBE TABLE objtxt LINES v_tab_lines.
  READ     TABLE objtxt INDEX v_tab_lines.

  CONCATENATE c_title_mail
              sy-datum INTO v_header SEPARATED BY space.


***************************************************************************************************************
*Populating The Title Of The Email In The Internal Table Doc_chng                                            *
***************************************************************************************************************

  doc_chng-obj_name = c_title_mail.
  doc_chng-obj_descr = v_header.
  doc_chng-doc_size = ( v_tab_lines - 1 ) * 255 + STRLEN( objtxt ).
  CLEAR objpack-transf_bin.

  objpack-head_start = 1.
  objpack-head_num   = 0.
  objpack-body_start = 1.
  objpack-body_num   = 1.
  objpack-doc_type   = c_raw.
  APPEND objpack.

  v_totlinexfer = 0.
  v_totxfer     = 0.
  v_binmaxlen   = 255.
  v_tgtmaxlen   = v_binmaxlen.
  v_tgtlen      = 0.

***************************************************************************************************************
*Determining The Size Of The File Which Will Be Sent In The Form Of Attachment                                *
*Populating the contents to be sent in the email(records sent to E2open)                                      *
***************************************************************************************************************
  lv_cr = cl_abap_char_utilities=>cr_lf.

  LOOP AT objtxt FROM 2 .         "from 2 coz 1st row is the text to be displayed on the screen

    CONCATENATE objtxt-line lv_cr INTO v_buffer.

    v_srcobjlen = STRLEN( v_buffer ).
    v_srcobjptr = 0.

    WHILE v_srcobjlen > 0 .

      v_xferlen = v_tgtmaxlen - v_tgtlen.

      IF v_xferlen > v_srcobjlen.
        v_xferlen = v_srcobjlen.
        MOVE v_buffer+v_srcobjptr TO objbin-line+v_tgtlen.
        v_tgtlen = v_tgtlen + v_srcobjlen.
        v_srcobjlen = 0.
        CLEAR v_buffer.
      ELSE.
        MOVE v_buffer+v_srcobjptr(v_xferlen) TO
        objbin-line+v_tgtlen(v_xferlen).
        APPEND objbin.
        CLEAR objbin-line.
        v_tgtlen = 0.
        v_srcobjlen = v_srcobjlen - v_xferlen.
        v_srcobjptr = v_srcobjptr + v_xferlen.
        v_totlinexfer = v_totlinexfer + 1.
      ENDIF.
      v_totxfer = v_totxfer + v_xferlen.

    ENDWHILE.

  ENDLOOP.

  IF v_tgtlen > 0.
    APPEND objbin.
    v_totlinexfer = v_totlinexfer + 1.
  ENDIF.
***************************************************************************************************************
*Appending The Size, Title, Format Of The File And Also The User Name Who Ran The Transaction                 *
***************************************************************************************************************

  CLEAR objpack-transf_bin.

  objpack-transf_bin = c_x.
  objpack-head_start = 1.
  objpack-head_num   = 0.
  objpack-body_start = 1.
  objpack-body_num   = v_totlinexfer.
  objpack-doc_type   = c_xls.
  objpack-obj_name   = c_title_mail.
  objpack-obj_descr  = v_header.
  objpack-doc_size   = v_totxfer.
  APPEND objpack.

  reclist-receiver   = sy-uname.
  reclist-rec_type   = 'B'.
  APPEND reclist.
***************************************************************************************************************
*This Function Module Is Used To Send A Mail To The Specified User In The Internal Table RECLIST              *
***************************************************************************************************************

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = doc_chng
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list               = objpack
      object_header              = objhead
      contents_bin               = objbin
      contents_txt               = objtxt
      receivers                  = reclist
    EXCEPTIONS
      too_many_receivers         = 1
      document_not_sent          = 2
      document_type_not_exist    = 3
      operation_no_authorization = 4
      parameter_error            = 5
      x_error                    = 6
      enqueue_error              = 7
      OTHERS                     = 8.


  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    MESSAGE 'Rejected records sent to user mail' TYPE 'S'.
  ENDIF.


  REFRESH : objtxt,
            objpack,
            objhead,
            objbin,
            reclist.
  CLEAR   : doc_chng.

ENDFORM.                    " send_mail


Tags:
Not what you were looking for? View more on this topic or Ask a question