Triggering Emails in SAP ABAP Using CL_BCS Class (2025)

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.

  • cl_bcs
  • cl_document_bcs
  • cl_cam_address_bcs
  • cx_bcs

Blog content:

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

Create Persistent

 

 

Send req is type reference to cl bcs.

Create Document

 

 

 

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.

Set Document

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.

 

Convert Internal Table

Lv_data_string, lv_string1 is type of string.

Convert string data into Xstring using function module HR_KR_STRING_TO_XSTRING.

convert string data

 

 

 

 

 

 

 

Convert Xstring data to binary data using function module SCMS_XSTRING_TO_BINARY.

scms_xstring_to_binary

 

 

 

 

Create an attachment with the attachment name, the attachment type, and the attachment data.

Create an attachment

 

 

 

 

 

Lv_att is name of the file.

Step 3: set sender and recipient (to,cc and bcc).

set sender and recipient

Step 4: set immediate sending.

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

send email

 

 

 

 

Finally send e-mail with all the data in send_req.

In SOST tcode:

display document

 

 

 

 

 

 

 

 

 

 

 

 

 

 

In mail:

In the mail body, you can see the following:

Output Log

Leave a comment

Your email address will not be published. Required fields are marked *