Triggering e-mail using standard global class rather than using function module in a program
Triggering e-mail through the function module takes some time to update and load. It will trigger an e-mail quickly and update as fast as possible in SOST Tcode.
With the help of the below mentioned standard global classes, we are going to compose and trigger the e-mail with an attachment (not mandatory) in a program.
For example, let’s trigger an e-mail with Excel file attachment in a program.
Step 1: Maintain e-mail document for class cl_bcs
E-mail is a binary document; we need to add document to the e-mail object. Document contains parameters like e-mail type, e-mail subject, e-mail body
Send req is type reference to cl bcs.
document is type ref to cl_document_bcs.
Here i_type is for type of the document, i_subject is for subject for the mail and i_text is for e-mail body text (it’s an internal table).
Now pass the e-mail document with subject, body and type to send request.
Step 2: Attaching an Excel sheet to e-mail
Before attaching an Excel sheet to e-mail: The class accepts the data only in binary format. So, we have to convert our internal table data into binary format. We can’t directly convert data into binary format. We have to follow below-mentioned steps.
- Initially, we have to take data into a string type.
- Then we have to convert this string type of table into Xstring using function module HR_KR_STRING_TO_XSTRING.
- Then we have to convert that Xstring into a binary format using function module SCMS_XSTRING_TO_BINARY.
Let’s consider that we have data in gt_data table.
Convert internal table data into string with horizontal tab (tab) and new line.
Lv_data_string, lv_string1 is type of string.
Convert string data into Xstring using function module HR_KR_STRING_TO_XSTRING.
Convert Xstring data to binary data using function module SCMS_XSTRING_TO_BINARY.
Create an attachment with the attachment name, the attachment type, and the attachment data.
Lv_att is name of the file.
Step 3: set sender and recipient (to,cc and bcc).
Step 4: set immediate sending.
gc_mark is constant of value ‘X’.
Here we can set period to trigger like trigger immediately or specific period.
Step 5: send e-mail using send_req
Finally send e-mail with all the data in send_req.
In SOST tcode:
In the mail body, you can see the following: