Use CL_BCS library to send email with ABAP

Many a time you need a report for which the output needs to be an email. SO_NEW_DOCUMENT_SEND_API1 is heavily used to achieve the task but let's explore another way of achieving the same using CL_BCS.

This post talks about how to use the CL_BCS library provided by SAP to easily send emails.

CL_BCS Library

The class serves as the interface from BCS to the applications. The methods of the class cater for the send functions.

Using CL_BCS, You can:

– Attach files to email
– Build the HTML/raw of the body.
– Set email’s Senders & Receiver
– Send an email, etc.
Let's see the steps one by one:

Initiating CL_BCS:

The first thing you need is to initiate a persistent send request.

Creating BCS Document:

Create the BCS document object which will be sent with the CL_BCS interface to BCS. In this case the Email.

SET_DOCUMENT

Once we have the document, It needs to be set to the send request.

SET_SENDER

Assign the sender to the send request.

ADD_RECIPIENT

Pass a recipient to the send request.

SEND

Send the email.

Here is a small working code snippet to send an email with a text file as an attachment,

As always, hope you like the post and use this knowledge in your day to day work.

Popular posts from this blog

ABAP read excel(.XLSX) file to internal table in ABAP using CL_FDT_XL_SPREADSHEET

ABAP convert internal table to excel (.xlsx) format and Send email or download

Application Logging in ABAP