11-10-2011 11:39 AM
Hi all,
I am getting the error code '2' (Document not send). Anyone knows whichever part that I did wrongly below??
Whichever part is the most suspicious for document not send? Is it the gd_doc_data? Or the it_packing_list? Or objhead/objbin?
*&Get the Email id and User id Whom you want to Send ******
sort the lt_p0105 according to uname
SORT lt_p0105 by uname ASCENDING.
&-- Assign the Email id and User id to Whom you want to Send -------------&
LOOP AT lt_p0105 INTO ls_p0105.
wa_it_receivers-receiver = ls_p0105-usrid_long. "&---- Assign Email id
wa_it_receivers-rec_type = 'U'. "&---- Send to External Email id
wa_it_receivers-com_type = 'INT'.
wa_it_receivers-notif_del = 'X'.
wa_it_receivers-notif_ndel = 'X'.
lv_uname = ls_p0105-uname.
APPEND wa_it_receivers TO it_receivers .
CLEAR wa_it_receivers.
CLEAR ls_p0105.
ENDLOOP.
& - END of Assign the Email id and User id to Whom you want to Send --&
"&--- Read the Number of lines in the Internal Table
DESCRIBE TABLE it_receivers LINES num_lines.
"&--- Check the Sender Email id or SAP User id is got or not.
IF num_lines IS NOT INITIAL.
*&----
Add thetext to mail text table
*&----
*********& Send EMAIL MESSAGE &********************************
DESCRIBE TABLE it_message LINES tab_lines.
READ TABLE it_message INDEX tab_lines.
gd_doc_data-doc_size = 1.
gd_doc_data-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( it_message ).
*Populate the subject/generic message attributes
gd_doc_data-obj_langu = sy-langu.
gd_doc_data-obj_name = 'SAPRPT'.
gd_doc_data-obj_descr = psubject.
gd_doc_data-sensitivty = 'F'.
*Describe the body of the message
CLEAR wa_it_packing_list.
REFRESH it_packing_list.
wa_it_packing_list-transf_bin = space.
wa_it_packing_list-head_start = 1.
wa_it_packing_list-head_num = 0.
wa_it_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES wa_it_packing_list-body_num.
wa_it_packing_list-doc_type = 'RAW'.
APPEND wa_it_packing_list TO it_packing_list.
Creation of the document attachment
LOOP AT int_storage.
CONCATENATE int_storage-P0000-PERNR
int_storage-P0002-VORNA
int_storage-P0002-NACHN
int_storage-P0019-MNDAT
int_storage-P0019-BVMRK
int_storage-TEXT_P0019_BVMRK
int_storage-P0019-TERMN
int_storage-P0019-TMART
int_storage-TEXT_P0019_TMART
int_storage-SYHR_A_P0019_AF_TEXT1
int_storage-SYHR_A_P0019_AF_TEXT2
int_storage-SYHR_A_P0019_AF_TEXT3
INTO OBJBIN.
APPEND OBJBIN.
ENDLOOP.
DESCRIBE TABLE OBJBIN LINES TAB_LINES.
OBJHEAD = 'Monitoring Task Email'.
APPEND OBJHEAD.
Creation of the entry for the compressed attachment
wa_it_packing_list-TRANSF_BIN = 'X'.
wa_it_packing_list-HEAD_START = 1.
wa_it_packing_list-HEAD_NUM = 1.
wa_it_packing_list-BODY_START = 1.
wa_it_packing_list-BODY_NUM = TAB_LINES.
wa_it_packing_list-DOC_TYPE = 'TXT'.
wa_it_packing_list-OBJ_NAME = 'Monitoring Task Email List'.
wa_it_packing_list-OBJ_DESCR = 'EMAIL_LIST.TXT'.
wa_it_packing_list-DOC_SIZE = TAB_LINES * 255.
APPEND wa_it_packing_list to it_packing_list.
.
*&------ Call the Function Module to send the message to External and SAP Inbox
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = gd_doc_data
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_packing_list
object_header = objhead
contents_bin = objbin
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.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF. "&---- END of Check the Sender Email id or SAP User id is got or not.
Edited by: Siong Chao on Nov 10, 2011 12:39 PM
Edited by: Siong Chao on Nov 10, 2011 12:41 PM
11-10-2011 12:27 PM
Compare your code with this. This code works fine in our production system.
Other things you may want to look is whether the system settings in SCOT transaction are complete and there are other programs that are able to send emails.
*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.
11-10-2011 12:35 PM
Questions about this ancient API have been asked many, many times. Search the forum for posts, including references to an SAP Note that contains both correct documentation for the API and working code. Compare your code to the working version....better still, convert email processing to utilize current toolset, BCS, for which there are SAP demo programs, named like BCS_TEST* and BCS_EXAMPLE*.