In this recipe, we will see how we can create a simple program that will send an e-mail (SAP Office Mail) to an SAP user AJON1
. There are no attachments involved in this recipe. However, we will want the SAP user AJON1
to see a pop-up express message when the e-mail document is received in his or her inbox.
We will now perform the steps shown as follows:
sendrequest
and myrecpient
to the classes cl_bcs
and cl_sapuser_bcs
.email_text
. This is based on the type bcsy_text
. We also declare an object reference to the class cl_document_bcs
with the name document
.create_persistent
of the class cl_bcs
.sendrequest
reference variable declared earlier.CREATE
method. This will be used later for specifying the e-mail recipient. The returned object is stored in myrecipient
variable. The corresponding object for the user AJON1
is created.add_recipient
method of the cl_bcs
class for the object reference sendrequest
. We supply the recipient through the myrecipient
object and we pass the value 'X'
for the i_express
parameter.My first email content
is added to the internal table email_text
. In addition, the factory method create_document
is called for class cl_document_bcs
. The type RAW
is specified through the parameter i_type
.SET_DOCUMENT
method and pass the document object as the parameter. The send
method of the class cl_bcs
for the object reference sendrequest
is also called.COMMIT WORK
statement.TRY .. ENDTRY
statement and the cx_bcs
exception class will be used for catching exceptions.We created object references for the send request and the e-mail document as well for the recipient user object. The static factory method create_persistent
of the cl_bcs
class is called in order to create a send request.
Then, we define appropriate text for the content of the e-mail body and add it to the created send request along with the subject of the e-mail.
A recipient object (based upon the class cl_sapuser_bcs
) is created for the SAP user AJON1
. This recipient is then added to the send request using the method add_recipient
of the cl_bcs
class. For the i_express
parameter of the add_recipient
method, the value 'X'
is passed so that the user receives an express message when the e-mail is received in his or her inbox. A new document is created using the static create_document
method of the cl_document_bcs
class. The document is having type RAW
and relevant subject and content. The add_document
method is then called in order to add the document to the send request. Finally, the COMMIT WORK
statement is called and the e-mail is sent.
An express message is generated as shown in the following screenshot:
The message appears in the document (Unread Documents
) of the SAP Business Workplace (transaction SBWP
). The message header for the corresponding message appears as shown in the following screenshot:
It contains the red icon that denotes an express message has been generated. The title (Title), author name (Author), and the date received (Date received) are shown as well. The preview of the document body is shown in the following screenshot:
The My first email content text is the e-mail text, whereas as the my email subject text is the subject as coded in the program.
18.225.57.126