Send Emails Using Object Oriented Method – CL_BCS

In newer versions of SAP (newer than 6.10 release) best practice is to send emails using BCS interface instead of API1 interface. BCS interface is easier to use than the older API1 interface. Plus you are not required to fill the packing list which makes it less complicated.

These function modules can be used to send email in older versions.

  • SO_DOCUMENT_SEND_API1
  • SO_NEW DOCUMENT_ATT_SEND_API1
  • SO_NEW_DOCUMENT_SEND_API1

These functions could be replaced by ABAP class CL_BCS (Business Communication Service).

 

How to handle Email Queues in SAPConnect Send Request (SOST).

When you trigger emails using these FMs or CL_BCS ABAP OO class, queues get generated under SOST (SAPconnect Send Requests). SOST queued emails can be processed using program RSCONN01 (SAPconnect: Start Send Process).

rsconn01-sost-send-email-cl_bcs-abap-oo
Process SOST queues using RSCONN01

 

Set correct parameters such that you do not send out unwanted messages and affect the performance of the servers.

rsconn01-address-type-cl_bcs-abap-00
rsconn01 address type

 

Also these messages can be sent manually using transaction SOST.

post-queue-execute-end-email-abap-oo
Execute SOST email queue

ABAP Program to Send Emails using ABAP OO Class CL_BCS.

When using class CL_BCS to send emails there are few basic steps which should be considered. Depending on the email format and attachment type parameter should be set differently.

In the shown example email is send in HTML format with a text file (.txt) attachment. Email subject, body, recipient email and text for attachment are given in the selection screen.

  • Selection Screen

asap-oo-email-program-selection-screen-cl_bcs
ABAP OO email program selection screen

 

As we are using HTML email format, body text in selection should be converted to HTML format. When attaching TXT or any other attachments to email, attached data should be converted to “SOLIX” format which is accepted by BCS class. Attachments can be text files, PDF files, world documents etc.

 

  • Data Declaration

abap-oo-data-declaration-email-program
data declaration
  • Setting email subject, HTML email body and initializing.

set-html-email-body-cl_bcs-abap-oo
Set email body
  • Convert Data Formats.

Converting attachment string to xstring, converting xstring to SOLIX format and calculating attachment size.

asap-oo-program-convert-data-cl_bcs
convert data
  • Adding email recipients and finally pushing the email to SOST.

add-email-recipients-cl_bcs-abap-oo-program
Add email recipient
SOST
created-email-using-cl_bcs-abap-oo-sost
Created email in SOST

 

email-delivered-cl_bcs-abap-oo
Email received

 

email-attachment-abap-oo-cl_bcs
Email attachent

 

Please leave a comment if you have any queries on CL_BCS class, email driver program or SOST.

Encode Message Payload to Base64 on CPI!

How to use Base64 message encoder in SAP Integration Suite.

Subscribe for more

My First Interface on CPI!

Learn how to develop your first iFlow on SAP Integration Suite within 7 minutes!

Subscribe for more

4 thoughts on “Send Emails Using Object Oriented Method – CL_BCS

  1. Angel Acosta says:

    Thanks , really helpfull, in the case of needing multiple recipients based on distribution lists or custom roles is there any class or fm to do so?

Leave a Reply

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