07-20-2016 12:31 PM
Hello Expert,
My client has a requirement for mail trigger during PO & PR Creation
On PO Creation Mail should be triggered to user for 1st release --> On 1st release mail for 2nd Release --> On 2nd release mail to PO Creator
On PR Creation Mail should be triggered to user for 1st release --> On 1st release mail for 2nd Release --> On 2nd release mail to PR Creator
Please suggest how can i achieve the same.
We need to do the same using SMTP.
Regards
07-20-2016 1:16 PM
Reinventing the wheel standard workflow or message output control?
07-20-2016 5:55 PM
Hi Sam,
We are using user exit EXIT_SAPMM06E_013 to send email to the PR creator, when PO item is created for that PR or when there are error messages for the PO.
We use class CL_BCS to send the mail.
You can check the release status and send mail.
Teresa
07-21-2016 11:05 AM
If you already use some OO Abap to send the mail, you could use BAdI ME_PROCESS_PO_CUST instead of Cusotmer-Exit.
Regards,
Raymond
07-22-2016 10:30 AM
And we use... We have user-exits and badi´s implemented for PO and PR.
Regards,
Teresa
07-22-2016 4:45 PM
Hello, Raymond,
M using the same BAdI ME_PROCESS_PO_CUST during Po Creation.
But can u please tell me how can i get data of my header to now Release strategy applied to PO Type and send mail accordingly to specific user.
Also how can i get mail id of user who has to release it.
Please help me out.
if you have any document regarding the same, please mail me abap.issue@gmail.com.
Regards
07-22-2016 4:46 PM
Hello Teresa,
Which badi u implemented for PR Creation.
Also suggest me for Po n Pr Release.
Regards
07-28-2016 4:04 PM
Hi Sam,
For PR, you can use Badi ME_PROCESS_REQ_CUST.
For PO release i´m using ME_PURCHDOC_POSTED. It´s used to check if user has authorization to release PO in a Z table.
If you put breakpoints in the methods you´ll find the data you need.
Regards,
Teresa
08-16-2016 6:05 AM
Hello Raymond,
Sorry for late response. I have applied my logic in BAdI ME_PROCESS_PO_CUST~CLOSE.
But when i m trying to write logic for mail trigger through SMTP it gives me dump.
In the function module interface, it was stipulated that only fields of
a specific type and length can be specified under "DOCUMENT_DATA". The
currently
specified field )"LT_MAILSUBJECT") has the right type, but its length is
incorrect.
Below is my code:
DATA: LT_MAILSUBJECT TYPE STANDARD TABLE OF SODOCCHGI1.
DATA: LT_MAILRECIPIENTS TYPE STANDARD TABLE OF SOMLREC90.
DATA: LT_MAILTXT TYPE STANDARD TABLE OF SOLI.
DATA: wa_LT_MAILSUBJECT TYPE SODOCCHGI1.
DATA: WA_LT_MAILRECIPIENTS TYPE SOMLREC90.
DATA: wa_LT_MAILTXT TYPE SOLI.
* Recipients
wa_LT_MAILRECIPIENTS-REC_TYPE = 'U'.
wa_LT_MAILRECIPIENTS-RECEIVER = 'abap.issue @gmail.com'.
APPEND wa_LT_MAILRECIPIENTS to LT_MAILRECIPIENTS.
CLEAR wa_LT_MAILRECIPIENTS .
* Subject.
wa_LT_MAILSUBJECT-OBJ_NAME = 'TEST'.
wa_LT_MAILSUBJECT-OBJ_LANGU = SY-LANGU.
wa_LT_MAILSUBJECT-OBJ_DESCR = 'PO Created'.
APPEND wa_LT_MAILSUBJECT to LT_MAILSUBJECT.
CLEAR wa_LT_MAILSUBJECT.
* Mail Contents
wa_LT_MAILTXT = 'PO Created. Waiting for your release'.
APPEND wa_LT_MAILTXT to LT_MAILTXT.
CLEAR wa_LT_MAILTXT.
* Send Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = LT_MAILSUBJECT
TABLES
OBJECT_CONTENT = LT_MAILTXT[]
RECEIVERS = LT_MAILRECIPIENTS[]
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 EQ 0.
COMMIT WORK.
* Push mail out from SAP outbox
SUBMIT RSCONN01 WITH MODE = 'INT' AND RETURN.
ENDIF.
Also i need to attach my PO PDF to the mail. Kindly suggest how can i achieve it.
08-16-2016 7:45 AM
Hello Terasa,
I have applied my logic in BAdI ME_PROCESS_PO_CUST~CLOSE.
But when i m trying to write logic for mail trigger through SMTP it gives me dump.
In the function module interface, it was stipulated that only fields of
a specific type and length can be specified under "DOCUMENT_DATA". The
currently
specified field )"LT_MAILSUBJECT") has the right type, but its length is
incorrect.
Below is my code:
DATA: LT_MAILSUBJECT TYPE STANDARD TABLE OF SODOCCHGI1.
DATA: LT_MAILRECIPIENTS TYPE STANDARD TABLE OF SOMLREC90.
DATA: LT_MAILTXT TYPE STANDARD TABLE OF SOLI.
DATA: wa_LT_MAILSUBJECT TYPE SODOCCHGI1.
DATA: WA_LT_MAILRECIPIENTS TYPE SOMLREC90.
DATA: wa_LT_MAILTXT TYPE SOLI.
* Recipients
wa_LT_MAILRECIPIENTS-REC_TYPE = 'U'.
wa_LT_MAILRECIPIENTS-RECEIVER = 'abap.issue @gmail.com'.
APPEND wa_LT_MAILRECIPIENTS to LT_MAILRECIPIENTS.
CLEAR wa_LT_MAILRECIPIENTS .
* Subject.
wa_LT_MAILSUBJECT-OBJ_NAME = 'TEST'.
wa_LT_MAILSUBJECT-OBJ_LANGU = SY-LANGU.
wa_LT_MAILSUBJECT-OBJ_DESCR = 'PO Created'.
APPEND wa_LT_MAILSUBJECT to LT_MAILSUBJECT.
CLEAR wa_LT_MAILSUBJECT.
* Mail Contents
wa_LT_MAILTXT = 'PO Created. Waiting for your release'.
APPEND wa_LT_MAILTXT to LT_MAILTXT.
CLEAR wa_LT_MAILTXT.
* Send Mail
CALL FUNCTION 'SO_NEW_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA = LT_MAILSUBJECT
TABLES
OBJECT_CONTENT = LT_MAILTXT[]
RECEIVERS = LT_MAILRECIPIENTS[]
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 EQ 0.
COMMIT WORK.
* Push mail out from SAP outbox
SUBMIT RSCONN01 WITH MODE = 'INT' AND RETURN.
ENDIF.
Also i need to attach my PO PDF to the mail. Kindly suggest how can i achieve it.
Regards
08-16-2016 9:08 AM
DOCUMENT_DATA is not an internal table but a single structure. (And better use CL_BCS than old FM...)
If you are stuck with old FM, better use SO_NEW_DOCUMENT_ATT_SEND_API1 for attachment (OBJBIN is container parameter, many threads already)
Regards,
Raymond
08-16-2016 10:30 AM
I converted it to structure and mail triggered.
Can you please guide me how can I attach my PO PDF in the mail.
08-16-2016 10:31 AM
08-16-2016 11:37 AM
Hello,
Under IF_EX_ME_PURCHDOC_POSTED~POSTED we are writing code for PO Release.
CHECK SY-TCODE EQ 'ME29N' .
IF SY-UCOMM EQ 'MESAVE' OR SY-UCOMM EQ 'OPT1'.
GET PARAMETER ID 'BES' FIELD LV_EBELN .
include zmail.
Please help me how can we check before save PO release indicator is changed or not.
During login user simply view or change some other field and save.
how to identify during transaction run status is changed.
help me out.
08-17-2016 6:42 AM
Hello expert,
I need to send mail for PO release to send level user for release . how can i check for PO release and save process.
here i am able to track save not PO release changes.
regards.
08-19-2016 3:23 PM
Hello Expert,
i have written below code for mail.
FUNCTION ZMAIL_PO_CREATED .
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(LV_SEND_USER_ID) TYPE FITP_USER-UNAME OPTIONAL
*" REFERENCE(LV_REC_MAIL_ID) TYPE AD_SMTPADR OPTIONAL
*" REFERENCE(LV_SEND_MAIL_ID) TYPE AD_SMTPADR OPTIONAL
*" REFERENCE(LV_EBELN) TYPE EBELN
*"----------------------------------------------------------------------
*FUNCTION-pool ZMAIL_PO_CREATED.
DATA:it_receivers TYPE STANDARD TABLE OF somlreci1,
wa_it_receivers LIKE LINE OF it_receivers,
it_packing_list TYPE STANDARD TABLE OF sopcklsti1,
gd_doc_data TYPE sodocchgi1,
wa_it_packing_list LIKE LINE OF it_packing_list,
psubject(90) TYPE c,
it_message TYPE STANDARD TABLE OF solisti1,
wa_it_message LIKE LINE OF it_message,
c1(99) TYPE c,
c2(15) TYPE c,
num_lines TYPE i.
"*&-- Assign the Email id and User id to Whom you want to Send -------------&
FREE wa_it_receivers.
wa_it_receivers-receiver = lv_rec_mail_id. "&---- 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'.
APPEND wa_it_receivers TO it_receivers .
FREE wa_it_receivers.
wa_it_receivers-receiver = lv_send_mail_id. "&----- Assign SAP User Id
wa_it_receivers-rec_type = 'U'. "&-- Send to SAP Inbox
wa_it_receivers-com_type = 'INT'.
wa_it_receivers-notif_del = 'X'.
wa_it_receivers-notif_ndel = 'X'.
APPEND wa_it_receivers TO it_receivers .
"*& - 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
*&----------------------------------------------------------------------
*&-- Subject of the mail -------------&*
CONCATENATE 'PO Created'':' lv_ebeln INTO psubject.
*psubject = 'Send Mail from ABAP Program.'(001).
*&-- Body of the mail ----------------&*
CLEAR wa_it_message.
c1 = 'Dear'(005).
c2 = lv_send_user_id.
CONCATENATE c1 c2 ',' INTO
wa_it_message-line SEPARATED BY space.
APPEND wa_it_message TO it_message.
*** insert Blank Line *********************************************
CLEAR wa_it_message.
wa_it_message-line = ' '.
APPEND wa_it_message TO it_message.
******* Assign your Text below *************************************
CLEAR wa_it_message.
wa_it_message-line = 'PO Created in system, waiting for release.'(002).
APPEND wa_it_message TO it_message.
*** insert Blank Line{} *********************************************
CLEAR wa_it_message.
wa_it_message-line = ' '.
APPEND wa_it_message TO it_message.
**********Assign your Text below ********************************
CLEAR wa_it_message.
wa_it_message-line = 'This mail generate automatically. Please do not reply.'(003).
APPEND wa_it_message TO it_message.
*********************************************************************
**********& Send EMAIL MESSAGE &*********************************
gd_doc_data-doc_size = 1.
*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'.1
*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 = 'TXT'.
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
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.
ENDFUNCTION.
but the mail body not printed . infact it get printed in PDF attached.
Please help me.
We need to print mail body as
HI,
PO Created, Waiting for release.
This is system generated mail . don't reply.
And pdf should contain PO Print
08-19-2016 4:49 PM
Hi sam,
Your post is quite confusing...
I send you a file with my code to send mail using class cl_bcs.
Best regards,
Teresa Gonçalves
08-19-2016 5:27 PM
Hello Teresa,
can you please mail me on sap.abap1711@gmail.com
My requirement is when a PO is Created the User who has to release it has to get a mail about PO creation notification with PO form attached to It.
Also in mail body we need to give some message.
Kindly provide me code for the same.
If you have any documentation please provide me
Regards
08-19-2016 5:31 PM
I have written my code under IF_EX_ME_PROCESS_PO_CUST~CLOSE
for PO Created it call a Custom FM where i have written above mail trigger code.
09-07-2016 8:28 AM
Hello Teresa,
I have written my code for mail using cl_bcs.
But its mail body is blank infact it get attached as pdf with raw data(un-formatted).
I need it in body not in attachment. also need excel data in body.
Please refer below code:
FUNCTION ZMAIL_PR_CREATED .
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(LV_SEND_USER_ID) TYPE FITP_USER-UNAME OPTIONAL
*" REFERENCE(LV_REC_MAIL_ID) TYPE AD_SMTPADR OPTIONAL
*" REFERENCE(LV_SEND_MAIL_ID) TYPE AD_SMTPADR OPTIONAL
*" REFERENCE(LV_BANFN) TYPE BANFN
*"----------------------------------------------------------------------
*FUNCTION-pool ZMAIL_PO_CREATED.
*Prepare Mail Object
DATA: LO_SEND_REQUEST TYPE REF TO CL_BCS VALUE IS INITIAL.
CLASS CL_BCS DEFINITION LOAD.
LO_SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).
* Message body and subject
DATA: LO_DOCUMENT TYPE REF TO CL_DOCUMENT_BCS VALUE IS INITIAL. "document object
DATA : I_TEXT TYPE BCSY_TEXT. "Table for body
DATA : W_TEXT LIKE LINE OF I_TEXT. "work area for message body
DATA: lx_document_bcs TYPE REF TO cx_document_bcs.
DATA: lx_ADDRESS_BCS TYPE REF TO CX_ADDRESS_BCS.
DATA: P_SUB TYPE CHAR50, "email subject
P_EMAIL TYPE ADR6-SMTP_ADDR. "Email input
DATA: wa_eban_temp TYPE eban,
wa_zt16fc TYPE zt16fc.
*CONCATENATE 'PR Created : 'lv_banfn ' Wating for ' wa_zt16fc-zfrgct ' Release' INTO p_sub.
SELECT SINGLE * from eban into wa_eban_temp WHERE banfn = lv_banfn.
SELECT SINGLE * from zt16fc INTO wa_zt16fc WHERE frggr = wa_eban_temp-frggr and frgco = wa_eban_temp-FRGSt.
P_EMAIL = wa_zt16fc-ZMAIL_ID.
CONCATENATE 'PR Created : 'lv_banfn ', ' wa_zt16fc-zfrgct ' Release' INTO p_sub.
*Set body
CONCATENATE 'Dear ' wa_zt16fc-zfrgct ',' INTO W_TEXT-LINE.
*W_TEXT-LINE = 'Dear,'.
APPEND W_TEXT TO I_TEXT.
CLEAR W_TEXT.
W_TEXT-LINE = ' '.
APPEND W_TEXT TO I_TEXT.
CLEAR W_TEXT.
CONCATENATE 'PR' lv_banfn 'Created In System, Waiting for your release' INTO W_TEXT-LINE.
APPEND W_TEXT TO I_TEXT.
CLEAR W_TEXT.W_TEXT-LINE = ' '.
APPEND W_TEXT TO I_TEXT.
CLEAR W_TEXT.
W_TEXT-LINE = 'This is the system generated mail for your notification'.
APPEND W_TEXT TO I_TEXT.
CLEAR W_TEXT.
W_TEXT-LINE = 'Do Not Reply'.
APPEND W_TEXT TO I_TEXT.
CLEAR W_TEXT.
*Create Email document
LO_DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT( "create document
I_TYPE = 'TXT' "Type of document HTM, TXT etc
I_TEXT = I_TEXT "email body internal table
I_SUBJECT = P_SUB ). "email subject here p_sub input parameter
* Pass the document to send request
LO_SEND_REQUEST->SET_DOCUMENT( LO_DOCUMENT ).
* Declare internal table and work area for MARA, add logic to get data from MARA.
DATA : IT_eban TYPE TABLE OF eban,
WA_eban TYPE eban.
DATA : IT_makt TYPE TABLE OF makt, "
WA_makt TYPE makt.
TYPES: BEGIN OF ty_final.
include structure eban.
types:maktx TYPE maktx,
qty TYPE c,
unit_price TYPE c,
value_price TYPE c,
END OF ty_final.
DATA : IT_final TYPE TABLE OF ty_final, "internal table for Ekko
WA_final LIKE LINE OF it_final.
SELECT * from eban INTO TABLE it_eban WHERE banfn = lv_banfn.
LOOP AT it_eban INTO wa_eban.
wa_final-banfn = wa_eban-banfn.
wa_final-matnr = wa_eban-matnr.
SELECT SINGLE * from makt INTO wa_makt WHERE matnr = wa_eban-matnr.
wa_final-maktx = wa_makt-maktx.
wa_final-bsart = wa_eban-bsart.
wa_final-ernam = wa_eban-ernam.
wa_final-afnam = wa_eban-afnam.
wa_final-menge = wa_eban-menge.
wa_final-qty = wa_eban-menge.
wa_final-meins = wa_eban-meins.
wa_final-preis = wa_eban-preis.
wa_final-unit_price = wa_final-preis.
wa_final-rlwrt = wa_eban-rlwrt.
wa_final-value_price = wa_final-rlwrt.
APPEND wa_final to it_final.
CLEAR: wa_final, wa_makt, wa_eban.
ENDLOOP.
*Declare strings, convert internal table data into string with horizantal tab (tab) and new line.
DATA : LV_STRING TYPE STRING, "declare string
LV_DATA_STRING TYPE STRING. "declare string
CONCATENATE 'PR NO.' 'Materal Name' 'Material No' 'Dco. Type' 'Requisitioner' 'Quantity' 'UOM' 'Unit_Price' 'Value' INTO LV_STRING SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
CONCATENATE LV_DATA_STRING LV_STRING INTO LV_DATA_STRING SEPARATED BY CL_ABAP_CHAR_UTILITIES=>NEWLINE.
LOOP AT IT_final INTO WA_final.
CONCATENATE WA_final-banfn WA_final-maktx WA_final-matnr WA_final-bsart WA_final-afnam WA_final-qty WA_final-meins WA_final-unit_price WA_final-value_price INTO LV_STRING SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
* CONCATENATE 'Vendor NO.' 'Vendor Name''Document Type' 'Created BY' 'Value' INTO LV_STRING SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
CONCATENATE LV_DATA_STRING LV_STRING INTO LV_DATA_STRING SEPARATED BY CL_ABAP_CHAR_UTILITIES=>NEWLINE.
CLEAR: WA_final, LV_STRING.
ENDLOOP.
*Convert string data into xstring using function module HR_KR_STRING_TO_XSTRING.
DATA LV_XSTRING TYPE XSTRING .
**Convert string to xstring
CALL FUNCTION 'HR_KR_STRING_TO_XSTRING'
EXPORTING
* codepage_to = '8300'
UNICODE_STRING = LV_DATA_STRING
* OUT_LEN =
IMPORTING
XSTRING_STREAM = LV_XSTRING
EXCEPTIONS
INVALID_CODEPAGE = 1
INVALID_STRING = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
IF SY-SUBRC = 1 .
ELSEIF SY-SUBRC = 2 .
WRITE:/ 'invalid string ' .
ENDIF.
ENDIF.
*Convert xstring data to binary data using function module SCMS_XSTRING_TO_BINARY .
DATA: LIT_BINARY_CONTENT TYPE SOLIX_TAB.
***Xstring to binary
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
BUFFER = LV_XSTRING
TABLES
BINARY_TAB = LIT_BINARY_CONTENT.
*Create attachment with attachment name, attachment type (ex: XLS, TXT etc) and attachment data .
DATA L_ATTSUBJECT TYPE SOOD-OBJDES.
**add attachment name
CLEAR L_ATTSUBJECT .
CONCATENATE 'PR Report' SY-DATUM INTO L_ATTSUBJECT.
* Create Attachment
TRY.
LO_DOCUMENT->ADD_ATTACHMENT( EXPORTING
I_ATTACHMENT_TYPE = 'XLS'
I_ATTACHMENT_SUBJECT = L_ATTSUBJECT
I_ATT_CONTENT_HEX = LIT_BINARY_CONTENT ).
CATCH cx_document_bcs INTO lx_document_bcs.
ENDTRY.
*Set Sender and Recipient to send request
*For every email, there is a sender and reciever (recipient), set sender and recipient for send request.
*Set Sender
DATA: LO_SENDER TYPE REF TO IF_SENDER_BCS VALUE IS INITIAL.
TRY.
LO_SENDER = CL_SAPUSER_BCS=>CREATE( SY-UNAME ). "sender is the logged in user
* Set sender to send request
LO_SEND_REQUEST->SET_SENDER(
EXPORTING
I_SENDER = LO_SENDER ).
* CATCH CX_ADDRESS_BCS INTO lx_ADDRESS_BCS.
****Catch exception here
ENDTRY.
*Set recipient for the send request
**Set recipient
DATA: LO_RECIPIENT TYPE REF TO IF_RECIPIENT_BCS VALUE IS INITIAL.
LO_RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( P_EMAIL ). "Here Recipient is email input p_email
TRY.
LO_SEND_REQUEST->ADD_RECIPIENT(
EXPORTING
I_RECIPIENT = LO_RECIPIENT
I_EXPRESS = 'X' ).
* CATCH CX_SEND_REQ_BCS INTO BCS_EXCEPTION .
**Catch exception here
ENDTRY.
*Set send email for send request
*Set immediate sending
TRY.
CALL METHOD LO_SEND_REQUEST->SET_SEND_IMMEDIATELY
EXPORTING
I_SEND_IMMEDIATELY = 'X'.
* CATCH CX_SEND_REQ_BCS INTO BCS_EXCEPTION .
**Catch exception here
ENDTRY.
*Finally send email using send request.
TRY.
** Send email
LO_SEND_REQUEST->SEND(
EXPORTING
I_WITH_ERROR_SCREEN = 'X' ).
COMMIT WORK.
IF SY-SUBRC = 0.
WRITE :/ 'Mail sent successfully'.
ENDIF.
* CATCH CX_SEND_REQ_BCS INTO BCS_EXCEPTION .
*catch exception here
ENDTRY.
ENDFUNCTION.