HTML Template in ABAP

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.

SAP HTML Template Tcode

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.

HTML Template Uploading

  1. Click to Create a new HTML file in SAP Web Repository.
  2. Fill a name and a description
  3. Upload the created HTML

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>&nbsp;</DIV>
<DIV>Hello;</DIV>
<DIV>&nbsp;</DIV>
<DIV>This is a test for HTML Template in SAP </DIV>
<DIV>&nbsp;</DIV>
<DIV>Your SAP UserId is <strong>!USERID!</strong></DIV>
<DIV>The date is <strong>!DATE!</strong></DIV>
<DIV>&nbsp;</DIV>

</FONT> </BODY>
</HTML>

SAP Template Attributes

Once uploaded, the system generates some attributes for HTML such as:

Related Post
  • fileextension .html
  • filename C:tempHTML_TEMPLATE.html
  • filesize 693
  • mimetype text/html
  • version 00001

You can add your own attributes ( to handle language for example )

Handling HTML Template in ABAP

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:

  • TEMPLATE: the name of the Template in the SAP Web Repository
  • MERGE_TABLE: is the table containing the variables and their values:
    • name(30): The name of Variable : placeholder: ‘<!list!>’
    • html like w3html occurs 100, ” HTML code to be inserted ( it is a table ! )
    • command: the action to take place when merging.
      • ‘?’-replace placeholderline(default)
      • ‘b’ insert before placeholder line
      • a’ insert after placeholder line
      • ‘r’ replace placeholder only

The output:

  • HTML_TABLE: type SWWW_T_HTML_TABLE and containing HTML line (255)

ABAP Sample How to handle HTML Template in SAP

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.

SAP Transporting HTML Template

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:

  • Description: Web Reporting/Internet Transaction Server HTML Templates
  • Program Id: R3TR
  • Object Type: W3HT
  • Object Name: ZZ_HTML_TEMPLATE_TEST

If you want to even deeper into HTML Template, visit the official documentaire at help.sap.com

Share
Published by
John

Recent Posts

The Most Important SAP ISU Tables

SAP ISU Tables for Technical master data, for Billing Master Data, Billing and invoicing Tables?…

December 22, 2020

SAP Fiori 3 UX and Design of SAP Fiori Apps for SAP S/4HANA, SAP TechEd Lecture

SAP Fiori 3 UX and Design of SAP Fiori Apps for SAP S/4HANA, SAP TechEd…

November 18, 2020

The Main SAP Dunning Transaction Codes

Dunning is the business practice of informing a customer of past due payment. Dunning letters…

November 28, 2019

SAP Accounts Payable Tcodes & Accounts Receivable Tcodes ( SAP AP Tcodes & SAP AR Tcodes)

SAP AP Tcodes & SAP AR Tcodes: House Banks Tcodes, Advance Payments or Down Payments,…

August 1, 2019

The Most Important SAP Payment Terms Tables (ZTERM, Text…)

What are the main SAP Payment Terms Tables ? What are the related Tables in…

October 21, 2018

The most Important SAP Work Center Tables in SAP PP

Work center consists of master data related to routing of products. It contains data related…

October 21, 2018