09-11-2007 8:13 PM
Hi,
I am sending a custom IDoc from source to target system (both system are SAP). In the Target system i written code for sending mail if IDoc failed. If i am sending an IDoc from source to target ( and I know IDoc will fail) but i am not getting mails, But if i am in the Target system using WE19 again reprocessing the failed IDoc again i am getting mails.
Following is the code used for mailing in target system
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.
data v_status type bcs_stml.
data v_request_status type bcs_rqst.
data v_string type string.
data v_length type i.
data v_hlength type so_obj_len.
data v_sender type sy-uname.
if not i_recipient[] is initial.
v_sender = 'BATUSER'. " <(^|^)> Hardcoded !!
read table i_idoc_status with key msgty = c_e.
if sy-subrc eq 0.
perform f_create_mail_text.
concatenate 'CTC Interface Errors in (' sy-sysid ')' into v_subject
.
v_length = strlen( v_string ).
v_hlength = v_length. .
send_request = cl_bcs=>create_persistent( ).
try.
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = i_content[]
i_subject = v_subject ).
call method send_request->set_document( document ).
sender = cl_sapuser_bcs=>create( v_sender ).
call method send_request->set_sender
exporting
i_sender = sender.
loop at i_recipient.
translate i_recipient-smtp_addr to lower case.
recipient = cl_cam_address_bcs=>create_internet_address(
i_recipient-smtp_addr ).
call method send_request->add_recipient
exporting
i_recipient = recipient
i_express = ' '
i_copy = ' '
i_blind_copy = ' '
i_no_forward = ' '.
endloop.
move : 'E' to v_request_status.
v_status = v_request_status.
call method send_request->set_status_attributes
exporting
i_requested_status = v_request_status
i_status_mail = v_status.
call method send_request->send( ).
commit work.
catch cx_document_bcs into bcs_exception.
endtry.
endif.
endif.
endform. " F_create_mail
a®
09-11-2007 11:23 PM
Solved by myself by adding the set flag "IMMEDIATLY"
ie
send_request->set_send_immediately( 'X' ).
send_request->send( ).