Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem while sending attachment thru 'SO_DOCUMENT_SEND_API1'

Former Member
0 Likes
761

Hi Experts ,

I am trying to send two excel files thrugh the function module 'SO_DOCUMENT_SEND_API1' .

Attachments are reaching the destination email address successfully , But along with two attacments its sending one more .txt file also in which email body text is included .

Please help me to resolve the issue .

Thanks in advance .

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
723

Hi,

This is probably due to wrong setting in SCOT...

PLease follow this link to check this:

If this doesn't solve your issue, drop some code over here so we can help you more easily... The problem then surely comes from your FM parameters.

Kr,

Manu.

5 REPLIES 5
Read only

Former Member
0 Likes
724

Hi,

This is probably due to wrong setting in SCOT...

PLease follow this link to check this:

If this doesn't solve your issue, drop some code over here so we can help you more easily... The problem then surely comes from your FM parameters.

Kr,

Manu.

Read only

0 Likes
723

Hi Manu ,

Thanks for your reply .

I checked with setting and everything is as expected .

Attaching the code which I have used in my program for sending 2 excel , Please help .

gd_doc_data-doc_size = 1.

*Fill the document data for attachment 2

  • Populate the subject/generic message attributes

READ TABLE it_attach INDEX gd_cnt.

gd_doc_data-doc_size =

( gd_cnt - 1 ) * 255 + STRLEN( it_attach ).

gd_doc_data-obj_langu = sy-langu.

gd_doc_data-obj_name = 'SAPRPT'.

gd_doc_data-obj_descr = psubject.

gd_doc_data-sensitivty = 'F'.

CLEAR it_attachment.

REFRESH it_attachment.

it_attachment[] = it_attach[].

  • Describe the body of the message

CLEAR it_packing_list.

REFRESH it_packing_list.

it_packing_list-transf_bin = space.

it_packing_list-head_start = 1.

it_packing_list-head_num = 0.

it_packing_list-body_start = 1.

DESCRIBE TABLE it_message LINES it_packing_list-body_num.

it_packing_list-doc_type = 'RAW'.

APPEND it_packing_list.

  • Create attachment notification

it_packing_list-transf_bin = 'X'.

it_packing_list-head_start = 1.

it_packing_list-head_num = 1.

it_packing_list-body_start = 1.

DESCRIBE TABLE it_attachment LINES it_packing_list-body_num.

it_packing_list-doc_type = 'XLS'.

it_packing_list-obj_descr = 'Successful Ser.no'.

it_packing_list-obj_name = 'Allot'.

it_packing_list-doc_size = it_packing_list-body_num * 255.

APPEND it_packing_list.

  • Fill the document data attachment 2

  • Populate the subject/generic message attributes

READ TABLE it_attach_1 INDEX gd_cnt.

gd_doc_data-doc_size =

( gd_cnt - 1 ) * 255 + STRLEN( it_attach_1 ).

gd_doc_data-obj_langu = sy-langu.

gd_doc_data-obj_name = 'SAPRPT'.

gd_doc_data-obj_descr = psubject.

gd_doc_data-sensitivty = 'F'.

CLEAR it_attachment.

REFRESH it_attachment.

it_attachment[] = it_attach_1[].

  • Describe the body of the message

  • CLEAR it_packing_list.

  • REFRESH it_packing_list.

it_packing_list-transf_bin = space.

it_packing_list-head_start = 1.

it_packing_list-head_num = 0.

it_packing_list-body_start = 1.

DESCRIBE TABLE it_message LINES it_packing_list-body_num.

it_packing_list-doc_type = 'RAW'.

APPEND it_packing_list.

  • Create attachment notification

it_packing_list-transf_bin = 'X'.

it_packing_list-head_start = 1.

it_packing_list-head_num = 1.

it_packing_list-body_start = 1.

DESCRIBE TABLE it_attachment LINES it_packing_list-body_num.

it_packing_list-doc_type = 'XLS'.

it_packing_list-obj_descr = 'Unsuccessful Ser.no'.

it_packing_list-obj_name = 'Allot1'.

it_packing_list-doc_size = it_packing_list-body_num * 255.

APPEND it_packing_list.

  • Call the FM to post the message to SAPMAIL

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = gd_doc_data

put_in_outbox = 'X'

sender_address = 'Traking System'

sender_address_type = 'INT'

commit_work = 'X'

IMPORTING

sent_to_all = gd_sent_all

TABLES

packing_list = it_packing_list

contents_bin = it_attachment

contents_txt = it_message

receivers = it_receivers

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

Read only

0 Likes
723

Compare with this code that works without issues. You need to append the packing list only two times one for doc_type = RAW and one for doc_type = XLS. I see that you are appending it 3 times, which may be the problem.



*Populating the body
  lv_message = l_c_mess_1 .
  APPEND lv_message TO gt_message.

  lv_message = space.
  APPEND lv_message TO gt_message.

  CONCATENATE l_c_mess_5 p_fname '.' INTO lv_message SEPARATED BY space.
  APPEND lv_message TO gt_message.

  lv_message = space.
  APPEND lv_message TO gt_message.

  lv_message = l_c_mess_6.
  APPEND lv_message TO gt_message.

  lv_message = space.
  APPEND lv_message TO gt_message.

  lv_message = l_c_mess_7.
  APPEND lv_message TO gt_message.

  lv_message = space.
  APPEND lv_message TO gt_message.

  lv_message = l_c_mess_8.
  APPEND lv_message TO gt_message.

* Populate attachment
    LOOP AT gt_error INTO gs_error.
      CONCATENATE gs_error-client_id gs_error-client_run_id
                  gs_error-vendor_id
                  gs_error-row_id gs_error-carrier_vendor_code
                  gs_error-carrier_id
                  gs_error-invoice_number
                  gs_error-msg
               INTO gs_attachment SEPARATED BY gc_tab.
      gs_attachment+253(2) = '##'.
      REPLACE '##' WITH l_c_newline INTO gs_attachment.
      APPEND gs_attachment TO gt_attachment.
    ENDLOOP.

**File Type
  ld_format = 'XLS'.
**File Name
  IF NOT gt_error[] IS INITIAL.
    CONCATENATE 'Error Report' sy-datum sy-sysid sy-uname
      INTO ld_attfilename SEPARATED BY space.
  ELSE.
    CONCATENATE 'Success Report' sy-datum sy-sysid sy-uname
      INTO ld_attfilename SEPARATED BY space.
  ENDIF.

* Fill the document data and get size of attachment
  CLEAR gd_doc_data.

* Populate the subject/generic message attributes
  gd_doc_data-obj_langu = sy-langu.
  gd_doc_data-doc_size = 1.
  gd_doc_data-obj_name = 'SAPRPT'.
  IF NOT gt_error[] IS INITIAL.
    gd_doc_data-obj_descr = gv_err_subject.
  ELSE.
    gd_doc_data-obj_descr = gv_suc_subject.
  ENDIF.
  gd_doc_data-sensitivty = 'F'.

* Describe the body of the message
  CLEAR gt_packing_list.
  REFRESH gt_packing_list.
  gs_packing_list-transf_bin = space.
  gs_packing_list-head_start = 1.
  gs_packing_list-head_num = 0.
  gs_packing_list-body_start = 1.
  DESCRIBE TABLE gt_message LINES gs_packing_list-body_num.
  gs_packing_list-doc_type = 'RAW'.
  APPEND gs_packing_list TO gt_packing_list.
  CLEAR gs_packing_list.

*Describe the attachment info
  gs_packing_list-transf_bin = 'X'.
  gs_packing_list-head_start = 1.
  gs_packing_list-head_num = 1.
  gs_packing_list-body_start = 1.
  DESCRIBE TABLE gt_attachment LINES gs_packing_list-body_num.
  gs_packing_list-doc_type = ld_format.
  gs_packing_list-obj_name = ld_attfilename.
  gs_packing_list-obj_descr = ld_attfilename.
  gs_packing_list-doc_size = gs_packing_list-body_num * 255.
  APPEND gs_packing_list TO gt_packing_list.

**Populating Mail Recepients
  gs_receivers-receiver = p_email.
  gs_receivers-rec_type = 'C'.
  gs_receivers-com_type = 'INT'.
  gs_receivers-notif_del = 'X'.
  gs_receivers-notif_ndel = 'X'.
  gs_receivers-express = 'X'.
  APPEND gs_receivers TO gt_receivers.

*Function Module to send mail
  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
       EXPORTING
            document_data              = gd_doc_data
            put_in_outbox              = 'X'
            commit_work                = 'X'
       TABLES
            packing_list               = gt_packing_list
            contents_bin               = gt_attachment
            contents_txt               = gt_message
            receivers                  = gt_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 e024.
  ENDIF.

*Executing the standard mail sending program for immediate dispatch of
*mail
  SUBMIT rsconn01 WITH mode = 'INT' AND RETURN.

Read only

0 Likes
723

Hi,

At first look, you seem to describe two times the body of your message in it_packing_list. I guess one time is enough...

Kr,

Manu.

Read only

0 Likes
723

Hi Manu ,

Thanks alot ...

Issue got resolved , Message body was described 2 times .

Regards,

Nusrat