Sending Smartform Output To Email
Sending Smartform Output To Email
1. Introduction
To send mail into PDF, we will make use of the various standard classes related to BCS (
Business Communication Services ).
We can use SOST transaction code while sending the mail to external system in order to
check whether everything is perfect fine or not in our system.
CL_BCS :-
This class is used for creating the send request, adding the recipient, sending the
document etc.
CL_DOCUMENT_BCS :-
This class is used for creating the document, adding the attachment etc.
CL_CAM_ADDRESS_BCS :-
This class is used to for sending the mail to outside address of SAP.
Out of these above classes, the first two are most important for Email purpose.
We write the text for the email purpose (i.e. Description for mail ) .
CL_BCS
CL_DOCUMENT_BCS
10. Send
11. Commit
5. Implementation
Step 1 :- Call the function module of the smartform to get the OTF data.
START-OF-SELECTION.
Step 2 :- Now we have OTF data, so we will convert it to BIN_FILE using CONVERT_OTF
function module, It will return me the BIN_FILE.
Step 3 :- We have got our BIN_FILE in form of XSTRING format, now we need to convert
it into binary format. So, we will use SCMS_XSTRING_TO_BINARY function module for
the same purpose.
Step 4 :- Now, we have the contents which I want to send a email, So now I will create a
send request using CL_BCS class.
TRY.
Step 5 :- Now, to send the mail to the external user,I will have to create a recipient for
external user.
For the same purpose, we have CL_CAM_ADDRESS_BCS class and we will call its
method CREATE_INTERNET_ADDRESS, it will return the object of this class.
TRY.
CALL METHOD CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS
EXPORTING
I_ADDRESS_STRING = '[email protected]'
* I_ADDRESS_NAME =
* I_INCL_SAPUSER =
RECEIVING
RESULT = LO_EXTERNAL_USER
.
CATCH CX_ADDRESS_BCS.
ENDTRY.
Step 6 :- Now, we have got the external address, then we will add this recipient to CL_BCS
class using ADD_RECIPIENT method.
TRY.
CALL METHOD LO_BCS->ADD_RECIPIENT
EXPORTING
I_RECIPIENT = LO_EXTERNAL_USER
* I_EXPRESS =
* I_COPY =
* I_BLIND_COPY =
* I_NO_FORWARD =
Step 7 :- Now, we have added the recipient, now we will create the document for the same
purpose.
We will provide, subject, text and will attach the PDF for the same purpose in the
document part.
TRY.
CALL METHOD CL_DOCUMENT_BCS=>CREATE_DOCUMENT
EXPORTING
Step 8 :- Now we will add the smartform and a Subject for the Mail, for that purpose we will
use ADD_ATTACHMENT method of CL_DOCUMENT_BCS class.
TRY.
CALL METHOD LO_DOCUMENT->ADD_ATTACHMENT
EXPORTING
I_ATTACHMENT_TYPE = 'PDF'
I_ATTACHMENT_SUBJECT = 'Employee Details Using Smartform'
* I_ATTACHMENT_SIZE =
* I_ATTACHMENT_LANGUAGE = SPACE
* I_ATT_CONTENT_TEXT =
I_ATT_CONTENT_HEX = LT_BINARY_TAB
* I_ATTACHMENT_HEADER =
* IV_VSI_PROFILE =
.
CATCH CX_DOCUMENT_BCS.
ENDTRY.
TRY.
CALL METHOD LO_BCS->SET_DOCUMENT
EXPORTING
I_DOCUMENT = LO_DOCUMENT
.
CATCH CX_SEND_REQ_BCS.
ENDTRY.
Step 10 :- Last step is to prepare mail for sending so we will call the
SET_SEND_IMMEDIATELY method of CL_BCS class and we will pass it to true.
TRY.
CALL METHOD LO_BCS->SET_SEND_IMMEDIATELY
EXPORTING
I_SEND_IMMEDIATELY = 'X'
.
CATCH CX_SEND_REQ_BCS.
ENDTRY.
Code
PARAMETERS : P_EMP_ID TYPE ZAR_EMP_ID.
START-OF-SELECTION.
TRY.
CALL METHOD CL_BCS=>CREATE_PERSISTENT
RECEIVING
RESULT = LO_BCS
.
CATCH CX_SEND_REQ_BCS.
ENDTRY.
TRY.
CALL METHOD CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS
TRY.
CALL METHOD LO_BCS->ADD_RECIPIENT
EXPORTING
I_RECIPIENT = LO_EXTERNAL_USER
* I_EXPRESS =
* I_COPY =
* I_BLIND_COPY =
* I_NO_FORWARD =
.
CATCH CX_SEND_REQ_BCS.
ENDTRY.
TRY.
CALL METHOD CL_DOCUMENT_BCS=>CREATE_DOCUMENT
EXPORTING
I_TYPE = 'RAW'
I_SUBJECT = 'Employee Details'
* I_LENGTH =
* I_LANGUAGE = SPACE
* I_IMPORTANCE =
* I_SENSITIVITY =
I_TEXT = LT_TEXT
* I_HEX =
* I_HEADER =
* I_SENDER =
* IV_VSI_PROFILE =
RECEIVING
RESULT = LO_DOCUMENT
.
CATCH CX_DOCUMENT_BCS.
ENDTRY.
TRY.
CALL METHOD LO_DOCUMENT->ADD_ATTACHMENT
EXPORTING
I_ATTACHMENT_TYPE = 'PDF'
I_ATTACHMENT_SUBJECT = 'Employee Details Using Smartform'
* I_ATTACHMENT_SIZE =
* I_ATTACHMENT_LANGUAGE = SPACE
TRY.
CALL METHOD LO_BCS->SET_DOCUMENT
EXPORTING
I_DOCUMENT = LO_DOCUMENT
.
CATCH CX_SEND_REQ_BCS.
ENDTRY.
TRY.
CALL METHOD LO_BCS->SET_SEND_IMMEDIATELY
EXPORTING
I_SEND_IMMEDIATELY = 'X'
.
CATCH CX_SEND_REQ_BCS.
ENDTRY.
Output
We can go to SOST and check the contents of Mail.