Skip to Content
Technical Articles
Author's profile photo Nazia Khatoon

Email template in S/4 HANA using OOPs concept

 

Email template feature explained in very simple way using OOPs concept.

Very often we get a business requirement to send email with table format. Before S/4 HANA we use to design the table using HTML <table> <th> <td> tags which is tedious  and then use the conventional way of calling FM to send the mail but after S/4 HANA release SAP has ease by providing email template feature which can be send by calling methods.

Before S/4 HANA:

We first use to declare variables like shown below

Variable%20Declaration

Variable Declaration

we use to fill Subject detail and mail body content using html tags and append it to Internal table as shown below

Subject%20and%20Mail%20body%20content

Subject and Mail body content

to design table we use below HTML tags for header section and append to internal table

HTML%20table%20tags

HTML table tags for Header section

Loop through internal table to populate the table data using concatenate function as shown below

Table%20data

Table data

then conventional way of using FM to send the mail to the recipients as shown below

Calling%20FM%20to%20send%20mail

Calling FM to send mail

 

After S/4 HANA:

With basic HTML knowledge we can easily design the email templates with one or more table content in it.

  1. Go to transaction SE80 and select your package, right click on it and select the Email template and give any Z name as shown below

Email%20template

Email template

2. Under text tab then design the subject line and email body content

to add any dynamic text without using CDS views in either subject line or email body we have to give the placeholder variable names in {{ }} as highlighted in below image i.e., SID, NOTE

Dynamic%20text

Dynamic text

 

3. Simply add the html tags to design table header in the already generated BODY HTML section  as shown below

Table%20header

Table header

 

4. To fill the table data we need to insert the placeholder name in {{ }} which can have logic in our ABAP code i.e., TabContent

Table%20data

Table data

one of the coolest feature, it allow you to preview your email content

Email%20content%20preview

Email content preview

 

4. ABAP code to fill the dynamic variables declared in the email content and to send the mail to the recipients

Declaration

Declaration

5. Simple REPLACE statement to pass the required data to the placeholders declared in the email template

Placeholder%20data

Placeholder data

6. Filling the table data with LV_CONTENT and calling methods to build the HTML for sending

Methods%20to%20build%20HTML

Methods to build HTML

7. Finally adding the mail recipients and calling send mail method

Send%20mail%20method%20call

Send mail method call

Sample mail preview

Mail%20sample

Mail sample

 

I hope this blog will be useful to technical consultants who are looking to start using Email template feature with table format without using CDS views. 🙂

For more info on this topic please follow the below link

https://blogs.sap.com/2023/05/10/email-template-with-table-in-email-body-sap_basis-release-750-or-above-and-s-4/

 

Assigned Tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Alex Necula
      Alex Necula

      Didn't know this feature exists, thank you for taking the time to show us. 🙂

      Author's profile photo Varun Varshney
      Varun Varshney

      Hello @Nazia Khatoon ,

      Thanks for the nice blog.
      Is it possible to convert all the body(html) of an email template to pdf(without smartform appraoch) as we need to show this body of email which is email template in our case as pdf attachment.
      I tried converting this htlm body - xstring-binary and pass it to add attachment of class bcs. PDF got generated but unable to open , probably due to incorrect conversion ?

      Author's profile photo Nazia Khatoon
      Nazia Khatoon
      Blog Post Author

      Hello Varun Varshney,

      Thanks for the comment.

      Even I tried the possibility but PDF file is not supporting as the data has HTML tags in it so its not possible to display.