Usage of the class CL_BCS in order to send eMails from ABAP™ applications via the Business Communication Service.
With our development tips we address special, related to praxis topics around the exciting and inexhaustible topic software development.
Valid for: SAP NetWeaver ABAP Web AS from 6.10
- e-mail dispatch from SAP
- Class CL_BCS
- Method CREATE_PERSISTENT – compile of a sending task
- Method SET_DOCUMENT – attach text, data files and other objects
- Method ADD_ATTACHMENT of the class CL_DOCUMENT_BCS
- Method ADD_RECIPIENT – transfer of receiver
- Method SEND – Sending of e-mail
- Cases of application
- Copyright & disclaimer
Often it is important to have necessary information at disposal in order to react quickly and in the right way. Especially, when the information procurement, like a report, takes a long time and cannot be constantly watched, it is useful to release an action upon completion. That can for example be an eMail with the status of a batch job or even the ABAP list.
eMail dispatch from SAP
SAP provided with the web AS 6.10 (6.20) the Business Communication Services (BCS) to send objects from ABAP applications. This object orientated interface is the successor of the Business Communication Interface (BCI), which is implemented as objects of the Business Object Repository (BOR).
In this Cadaxo development tip I will give an overview of the e-mail dispatch via BCS.
Via BCS different objects with attachments and notes for several receivers can be sent also in different communication ways. Consequently the interface – the class CL_BCS – is constructed complex. In this development tip we therefore concentrate on sending an e-mail with attachment only.
A sending process breaks down into the following steps:
- Generation of a sending task
- Attaching an object
- Choice of receivers
- Sending of the mail
For all those tasks the class CL_BCA provides the following methods:
- CREATE_PERSISTENT Compilation of a sending task
- SET_DOCUMENT Attaching a text, data or other objects
- ADD_RECIPIENT Add the receiver
- SEND Sending of e-mail
Method CREATE_PERSISTENT – Compilation of a sending order
This method generates a sending task and returns an object of the class CL_BCS. All further steps are used upon that object.
Method SET_DOCUMENT – Attachment oft ext, data and other objects
With this method the content, meaning the actual text and data attachments of the e-mail is committed. The method expects an object with the interface IF_DOCUMENTS_BCS. Attachments are committed via this object too.
Via the statistic method CREATE_DOCUMENT of the class CL_DOCUMENT_BCS a respective object can be created.
The method expects the following parameters:
I_TYPE: Type of committed data, e.g. HTM für eine HTML Datei, TXT for text data, BIN for binary data like PDFs
I_TEXT/I_HEX: A chart with the actual text resp. the binary data according to the choosen type
I_SUBJECT: subject of the e-mail
Method ADD_ATTACHMENT of class CL_DOCUMENT_BCS
This method is similarly used to the CREATE_DOCUMENT:
I_ATTACHMENT_TYPE: Type of committed data, e.g. HTM for HTML data, TXT for text data, BIN for binary data like PDFs
I_ATTACHMENT_HEX: An internal table with the actuall text resp. the binary data according to the choosen type
I_ATTACHMENT_SUBJECT: Name of the attachment file
Method ADD_RECIPIENT – Transfer of receiver
Depending on the way of communication and type of the sent object different receivers can be transferred to the mail. E.g. no business object relation can be per e-mail.
The method expect at least one object which implements the interface IF_RECIPIENT_BCS:
I_RECIPIENT: receiver address (Interface IF_RECIPIENT_BCS)
I_EXPRESS: Express message; if the receiver is a SAP user, a pop-up appears at the next processing of the PBO event with the notice of a new message
I_COPY: The receiver receives the message as a copy
I_BLIND_COPY: The receiver receives the message as a blind copy
I_NO_FORWARD: no forwarding; if the receiver is a SAP user, he cannot forward the message
The two most important receiver types are probably e-mail addresses and SAP users. The respective objects are generated by the following statistic methods:
CL_SAPUSER_BCS=>CREATE For SAP users
CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS For e-mail addresses
Method SEND – Sending of an e-mail
The message is passed on to SAPconnect and sent via the respective interface. The actual sending process is usually scheduled by a batch job with the report RSCONN01, which periodically sends all upcoming messages. In order to avoid the waiting perioduntil the next job performance, the message can be tagged as “to be sent immediately”: Method SET_SEND_IMMEDIATELY( abap_true ) of the sending task.
With this method the SAPOffice dialogue opens itself for new messages, on which the user can maintain receivers, texts, attachments and their settings himself. Via parameters suggestion values for the respective fields and objects, e.g. receiver addresses, can be taken with at the time of selection, which later will be displayed in the message.
- Posted by Domi Bigl
- On März 7, 2016