HTML Template in ABAP is a powerfull to tool to save template for document, SAP long texts and email in HTML format in SAP.
The SAP HTML Template contains more than the content with layout and data reference to generate dynamic Email and/or rich text.
These fields will be replaced by the corresponding value.
Table of Contents
First, you have to implement the HTML template. Use WYSWYG tools or even a notepad editor.
Check here how to set ABAP Synthax in Notepad++.
Once the HMTL file is ready, run the tcode SMW0 to enter the SAP Web Repository.
The SMW0 Tcode can be used to store HMTL Template as well as to upload Binary data ( such as Picture, PDF … )
for HTML files, select the first option : HTML templates for WebRFC applications.
Here a simple of HTML Template for an email
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <META http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <META content="MSHTML 6.00.2800.1400" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Verdana size=3><STRONG>HANDLING HTML TEMPLATE in ABAP / SAP </STRONG></FONT></DIV> <FONT face="Verdana,Arial,Helvetica" size=2> <DIV> </DIV> <DIV>Hello;</DIV> <DIV> </DIV> <DIV>This is a test for HTML Template in SAP </DIV> <DIV> </DIV> <DIV>Your SAP UserId is <strong>!USERID!</strong></DIV> <DIV>The date is <strong>!DATE!</strong></DIV> <DIV> </DIV> </FONT> </BODY> </HTML>
Once uploaded, the system generates some attributes for HTML such as:
You can add your own attributes ( to handle language for example )
SAP offers a function module to Merge two HTML.
The function Module WWW_HTML_MERGER can remplace the variables declared in the HTML template with their value.
The input:
The output:
Here an ABAP Tutorial sample code, to retrieve a template and exchange the variables with the data.
*&---------------------------------------------------------------------* *& ABAP CODE : HOW TO HANDLE HTML TEMPLATE IN ABAP *& REMPLACE THE VARIABLES IN HTML WITH VALUE *&---------------------------------------------------------------------* REPORT ZTEST_HTML_TEMPLATE. " Declare the SWWW Type-Pool TYPE-POOLS: swww. " Data Declarations DATA: lt_merge_table TYPE swww_t_merge_table. DATA: lt_html_table TYPE swww_t_html_table. DATA: ls_merge_table LIKE LINE OF lt_merge_table. DATA: ls_html_table LIKE LINE OF lt_html_table. DATA: lv_string TYPE string. " Selection Screen PARAMETERS: p_temp TYPE swww_t_template_name DEFAULT 'ZZ_HTML_TEMPLATE_TEST'. PARAMETERS: p_user TYPE syuname DEFAULT sy-uname. PARAMETERS: p_date TYPE sydatum DEFAULT sy-datum. START-OF-SELECTION. REFRESH lt_html_table. " Remplace USERID with its value CLEAR ls_merge_table. ls_merge_table-name = '!USERID!'. ls_merge_table-command = 'R'. lv_string = p_user. APPEND LV_string to ls_merge_table-html[]. APPEND ls_merge_table TO lt_merge_table. " Remplace DATE with its value CLEAR ls_merge_table. ls_merge_table-name = '!DATE!'. ls_merge_table-command = 'R'. lv_string = p_date. APPEND LV_string to ls_merge_table-html[]. APPEND ls_merge_table TO lt_merge_table. " Call the HTML MERGE function CALL FUNCTION 'WWW_HTML_MERGER' EXPORTING template = p_temp IMPORTING html_table = lt_html_table[] CHANGING merge_table = lt_merge_table[]. END-OF-SELECTION. LOOP AT lt_html_table INTO ls_html_table. WRITE / ls_html_table-line. ENDLOOP.
When aving a HTML template in the SAP Web Repository, you will be asked to select a Transport. You can also save them locally in you are making some ABAP testing.
In Transport, the line corresponding to the Template:
If you want to even deeper into HTML Template, visit the official documentaire at help.sap.com
SAP ISU Tables for Technical master data, for Billing Master Data, Billing and invoicing Tables?…
SAP Fiori 3 UX and Design of SAP Fiori Apps for SAP S/4HANA, SAP TechEd…
Dunning is the business practice of informing a customer of past due payment. Dunning letters…
SAP AP Tcodes & SAP AR Tcodes: House Banks Tcodes, Advance Payments or Down Payments,…
What are the main SAP Payment Terms Tables ? What are the related Tables in…
Work center consists of master data related to routing of products. It contains data related…