‎2008 Feb 22 9:11 PM
Hello,
Since upgrading from version 4.5 to version 4.7, about a year ago, a function module that we were using to send e-mail was no longer delivering an error message to the sender's e-mail address if the address to which the e-mail was sent was invalid. We found that this error was occurring with the several function modules we were using, SO_NEW_DOCUMENT_ATT_SEND_MAPI, SO_NEW_DOCUMENT_ATT_SEND_API1, and SO_OBJECT_SEND.
I found a couple different examples on this forum that were using classes and methods from package SBCOMS to send e-mails. So far so good.
Now I have come across a situation where the point in the code where the e-mail is being sent, a commit work cannot be executed without causing an abend.
So, my question is, how can you send an e-mail using classes and methods from package SBCOMS that does not require a commit work to be executed?
Thanks
Bruce
Here is an example of the code I am using.
try.
Create persistent send request
send_request = cl_bcs=>create_persistent( ).
*
************************************************************************
Now we are ready to create the e-mail content itself. The first
record in our documents importing parameter will become the main
e-mail document. All other content will be inserted as attachments
to this document.
************************************************************************
data: first(1) type c.
clear first.
data: documents_line like line of documents.
loop at documents into documents_line.
if first is initial.
move 'X' to first.
Build the Main Document
if documents_line-content_hex[] is initial.
document = cl_document_bcs=>create_document(
i_type = documents_line-type
i_text = documents_line-content_text
i_subject = documents_line-subject ).
else.
document = cl_document_bcs=>create_document(
i_type = documents_line-type
i_hex = documents_line-content_hex
i_subject = documents_line-subject ).
endif.
else.
if documents_line-content_hex[] is initial.
Add Attachment
call method document->add_attachment
exporting
i_attachment_type = documents_line-type
i_attachment_subject = documents_line-subject
i_att_content_text = documents_line-content_text
i_attachment_header = documents_line-attachment_header.
else.
call method document->add_attachment
exporting
i_attachment_type = documents_line-type
i_attachment_subject = documents_line-subject
i_att_content_hex = documents_line-content_hex
i_attachment_header = documents_line-attachment_header.
endif.
endif.
endloop.
************************************************************************
Now we can add our document (and its attachments) to our send request
************************************************************************
Add document to send request
call method send_request->set_document( document ).
************************************************************************
Next we will create a sender object (this function module
automatically uses the current user) and places it into our send
request.
************************************************************************
Get sender object
sender = cl_sapuser_bcs=>create( sy-uname ).
Add sender
call method send_request->set_sender
exporting
i_sender = sender.
************************************************************************
Following the sender, we can add our recipients to the e-mail. If
requested by the calling program we will lookup the recipients e-mail
address from their SAP User Master using the BAPI,
BAPI_USER_GET_DETAIL. If an e-mail address isn't maintained there,
we will try and create one by concatenating their user id together
with our default company domain name.
************************************************************************
data: recipients_line like line of recipients.
loop at recipients into recipients_line.
if recipients_line-c_address is initial.
Create recipient
clear iaddsmtp.
refresh iaddsmtp.
clear bapiadsmtp.
clear recipient.
Read the E-Mail address for the user
call function 'BAPI_USER_GET_DETAIL'
exporting
username = recipients_line-uname
tables
return = ireturn
addsmtp = iaddsmtp.
loop at iaddsmtp where std_no = 'X'.
clear bapiadsmtp.
move iaddsmtp to bapiadsmtp.
endloop.
If no E-mail address was found, create one.
if bapiadsmtp-e_mail = ''.
concatenate recipients_line-uname local_domain
into recipients_line-c_address.
else.
move bapiadsmtp-e_mail to recipients_line-c_address.
endif.
endif.
recipient = cl_cam_address_bcs=>create_internet_address(
recipients_line-c_address ).
Add recipient with its respective attributes to send request
call method send_request->add_recipient
exporting
i_recipient = recipient
i_express = recipients_line-i_express
i_copy = recipients_line-i_copy
i_blind_copy = recipients_line-i_blind_copy
i_no_forward = recipients_line-i_no_forward.
endloop.
************************************************************************
Set the return status attributes of the message.
************************************************************************
Set that you don't need a Return Status E-mail
data: status_mail type bcs_stml.
status_mail = requested_status.
call method send_request->set_status_attributes
exporting
i_requested_status = requested_status
i_status_mail = status_mail.
************************************************************************
Here is opportunity to send e-mail immediately. The E-mails still
get logged in the system and can be monitored from SCOT (or SOST).
The following code will trigger the send immediately.
************************************************************************
set send immediately flag
send_request->set_send_immediately( 'X' ).
************************************************************************
Finally we tell the system to send our email. We follow this up with
a commit work statement. Because the BCS is written as a Persistent
Object Class, no activity will take place until we trigger the commit
work. We close by catching the BCS errors into the BCS exception
class.
************************************************************************
Send document
call method send_request->send( ).
commit work.
catch cx_bcs into bcs_exception.
raise exception bcs_exception.
************************************************************************
endtry.
‎2008 Feb 23 7:21 AM
a commit work cannot be executed without causing an abend.
commit work is required here.
have you analyzed whats causing the abend? i have been using a similar code without problem.
‎2008 Feb 25 6:54 PM
Durairaj,
I have exchanged several emails with the author of the FM I copied from this forum, Thomas Jung.
He said:
If you can't issue a commit work that should be OK. Regardless of what you are within, you will eventually get an implicit commit work at the end of the LUW and the should be enough to trigger the mail.
I sent him the program calling the email FM and the FM source code.
He said:
Well I was unable to recreate your situation in my 7.10 system. This could mean that there is a bug in your system that is not responding well to the implicit commit work.
=============================================
This is what is currently happening in our 620 system, patch level 061.
If I remove the commit work from the FM, the request gets created but the request staus in Tcode scot is 'No entry in queue yet'. The request then has to be manually resent, changing the status to waiting. The request can then be transmitted either manually from scot or programmatically using RSCONN01.
If the commit work is in the FM, the request is automatically transmitted and the email is sent.
Here is a link to the blog that Thomas created showing how he created a FM. I am using the FM described in this blog.
/people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface
Thanks
Bruce
‎2008 Feb 28 12:15 AM
An explicit commit work was required in our 620 system. As Thomas Jung surmised, an implicit work was not enough.
Bruce