Introduction:
SAP print outputs which are being sent to Outlook, Gmail, Yahoo, etc. as an attachment ( either as a Word document or Excel or PDF etc.), can also be displayed directly in mail body by converting it into HTML format.
This document deals with concept of displaying SAP print outputs (which are being sent as an attachment currently), directly in the mail body instead of attaching as an attachments with the mail.
Background:
Attachments can be added to mail using some standard Function modules or by using OOPs concepts as shown in the below screenshots.
These attachments can be opened either by single clicking in case of word, excel and any Microsoft products which will display the contents in the mail body or by double clicking in case of PDF which will open the documents separately.
In case, if there are limited data to be sent to user, separate software is required to open the file to view the contents.
Proposal:
Purpose of this document is to coin the idea of displaying the contents of the document directly in the mail body without adding any attachments separately. This can be achieved by converting the objects into HTML format and sending via mail. Objects like logos, internal table entries, hyperlinks, standard texts as well as normal texts from SAP can be send to mail body.
How it Works:
- Send Logos to Mail body :
- Logos which needs to be sent via mail should be uploaded in MIME repository as shown below:
- Go to SE80. Click on MIME Repository.
- Right click on Public and click Import MIME objects.
- Once the file is selected, give name and description for the uploaded logo and press save button.
- Uploaded logos can be accessed and converted to HTML by below mentioned steps.
- To retrieve the image from MIME repository:
Interface: IF_MR_API
Method: GET
- Pass the url to the exporting parameter and import the values in a structure or variable.
- Convert the image to Xstring table form.
- To attach the image in HTML body:
CLASS INTERFACE: CL_GBT_MULTIRELATED_SERVICE
METHOD: ADD_BINARY_PART
PARAMETERS:
Content => Xtring table form.
Filename => any name with extension of the image format.
Extension => JPG/BMP/… etc.
Description => any description.
Content type => image/ (extension of the image format).
Length => length of an image.
Content_id => same as filename.
- Below mentioned HTML tags needs to be passed to a final internal table of type SOLI_TAB.
- '<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xfa="http://www.xfa.org/schema/xfa-template/2.1/"><head></head>'
- '<body>'
- '<br><img alt="[image]" src="cid:<image name>.jpg" /><br>'
- Send Internal tables to Mail body:
- Internal tables which needs to be send directly to mail body can be converted to HTML by using below mentioned steps.
- Fill the fields which is to be displayed as header text in a field catalog.
- Use the below FMs to convert the header texts, layouts and internal table entries into HTML.
- WWW_ITAB_TO_HTML_HEADERS
- To convert the header texts into HTML.
- WWW_ITAB_TO_HTML_LAYOUT
- To convert the layout of an internal table into HTML.
- WWW_ITAB_TO_HTML
- To convert an internal table entries into HTML.
- If border is required, then pass table attributes as ‘BORDER=1’, if not then pass ‘BORDER=0’.
- WWW_ITAB_TO_HTML_HEADERS
- Final internal table (SOLI_TAB) should be filled with the above retrieved HTML contents.
- Send Normal text to Mail body:
- Texts which needs to be displayed in the mail body (Only Left-alignment) can be passed directly from the program by using below mentioned HTML tag.
- By directly passing the texts from program.
- By using Standard texts.
- By directly passing the texts from program:
- Below mentioned HTML tag can be used to pass texts to mail body.
'<p><font size="5" face="TIMES NEW ROMAN" color="black" fontstyle="bold"><b><required text>'
- Final internal table (SOLI_TAB) needs to be filled with above mentioned HTML tag.
- By using Standard texts.
- Use the FM READ_TEXT to retrieve data from any standard texts into an internal table.
- Use the FMs which was mentioned above to convert an internal table to HTML. In this case, pass table attributes as ‘BORDER=0’.
- Concluding steps to pass all the data to mail body:
- To display the final output internal table (SOLI_TAB), below steps needs to be followed.
- To create mail HTML body:
CLASS INTERFACE: CL_GBT_MULTIRELATED_SERVICE
METHOD: SET_MAIN_HTML
PARAMETERS:
Content => Final output internal table (SOLI_TAB).
Filename => ‘sapwebform.htm’ "filename for HMTL form
Description => any description.
- To create HTML using BCS class and attach HTML and image part to it:
CLASS INTERFACE: CL_DOCUMENT_BCS
METHOD:CREATE_FROM_MULTIRELATED
PARAMETERS:
Subject => any subject texts.
CLASS INTERFACE: CL_BCS
METHOD: CREATE_PERSISTENT
- To create document:
CLASS INTERFACE: CL_BCS
METHOD: SET_DOCUMENT
- To create sender, recipient and to send mail below class can be used:
CLASS INTERFACE: CL_CAM_ADDRESS_BCS, CL_BCS
- Below output can be achieved in the mail body.
Advantages:
- No proprietary software like Microsoft office or Adobe reader is required to open the attached file, as the contents are directly getting displayed in the mail body.
- This approach is more helpful when there is a requirement to show limited data to recipient.