Introduction:

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

standard global class

Send req is type reference to cl bcs.

standard global class

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.

standard global class

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.

standard global class

Lv_data_string, lv_string1 is type of string.

Convert string data into Xstring using function module HR_KR_STRING_TO_XSTRING.

standard global class

Convert Xstring data to binary data using function module SCMS_XSTRING_TO_BINARY.

standard global class

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

standard global class

Lv_att is name of the file.

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

standard global class

Step 4: set immediate sending.

standard global class

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

standard global class

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

In SOST tcode:

standard global class

In mail:

In the mail body, you can see the following:

standard global class

Leave a comment

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