Mobile Menu

How-To Create Email Content Sections Using /SKYBFR/YCA1 Add-On

This article describes parameters and samples of how to use CONVERT_VALUES_TO_HTML Method.

CONVERT_VALUES_TO_HTML is a powerful method having a huge functional for email content creation in HTML format. It can create HTML sections containing header, text paragraphs, name-value pairs lists, data tables. These sections can be combined one by one into a complete neat email like this one:


Each aspect of that Section can be adjusted using method importing parameters or HTML templates for each element. Section itself (background color, width, etc.), Header, Text String, Name-Value whole table and/or each of its rows, Data Table and/or each row, header row, data cell, data cell for numeric values, etc – absolutely everything can be customized via custom templates.

We will show now only a simplified variant without templates customization, so that Add-On will use its own templates.

What is HTML section

Section is an HTML fragment that can be put into <BODY>…</BODY> HTML tag. Any amount of Sections can be combined one by one in a sequence. There are three sections in our example. The first one contains Header, Text String and Name-Value Pairs, the second one contains Header and Name-Value pairs and the last one contains Header and Data Table:


Section elements

Each Section can contain one or some or even all possible elements: Header, Text String, Name-Value Pairs and Data Table. This method creates Section and puts those elements in order in the list above if they passed into the Method.

Header is text string passed as IV_HEADER parameter.

Text String is passed as IV_STRING parameter. Both Header and Text String can contain <br/> tag to divide it into several lines or paragraphs.

Name-Value Pairs look like a table of two columns. The left column contains Names and the right column contains their Values. They are passed as IT_VALUES parameter into Method. It is a table with string values for Name and for Value in each line.

Data Table represent table with data of any structure. You can pass it via IT_DATA parameter and additionally pass Table Headers as IT_DATAHEADER parameter, otherwise the Add-On will use descriptions of data elements from you Data Table. Also, you can specify using borders around all cells via IV_DATACELLBORDERSINDEFAULT parameter (otherwise only header cells will be underlined) and using separate template for numeric values via IV_DATACELLNUMSPECTEMPLATE parameter (numeric will be right justified).

Code examples

To create the first Section of our example we use the following code:

DATA: lv_header            TYPE string,
lv_header_txt        TYPE string,
lv_string_txt        TYPE string,
lt_values            TYPE /skybfr/yca1_t_name_value_pair.
FIELD-SYMBOLS: <ls_value>      TYPE /skybfr/yca1_s_name_value_pair.
CONCATENATE 'Dear'(005) iv_fullname
INTO lv_header_txt SEPARATED BY space.
CONCATENATE lv_header_txt ',' INTO lv_header_txt.

lv_number = is_header-qmnum.
CLEAR lv_string_txt.
CONCATENATE 'You are defined by SAP Workflow system'(006)
'as a person responsible for General Notification '(007)
lv_number 'approval.'(008) INTO lv_string_txt SEPARATED BY space.

CLEAR lt_values.
<ls_value>-name = 'Notification'(011).
<ls_value>-value = lv_number.
<ls_value>-name = 'Description'(012).
<ls_value>-value = is_header-qmtxt.
<ls_value>-name = 'Notification Status'(013).
<ls_value>-value = is_header-qmstat.

lv_header = convert_values_to_html( iv_header = lv_header_txt
iv_string = lv_string_txt
it_values = lt_values ).

Here we complete and pass Header and Text String values and Name-Value Pairs table into Method. As a result, we have Section created as HTML code.

To create the second Section the code is mostly the same but without using IV_STRING parameter.

To create the last Section of our example the code looks like this:

TYPES: BEGIN OF lty_row,
item         TYPE i,
text         TYPE string,
defect_loc   TYPE string,
code_group   TYPE string,
defect_type  TYPE string,
defect_class TYPE string,
END OF lty_row.
DATA: lv_header_txt        TYPE string,
lv_table             TYPE string,
lt_data              TYPE STANDARD TABLE OF lty_row.
FIELD-SYMBOLS: <ls_data>       TYPE lty_row.
lv_header_txt = 'Items'(023).
DATA(lt_headers) = VALUE /skybfr/yca1_t_table_headers(
( CONV string( 'Item'(024) ) )
( CONV string( 'Text'(025) ) )
( CONV string( 'Defect Location'(026) ) )
( CONV string( 'Code Group'(027) ) )
( CONV string( 'Defect Type'(028) ) )
( CONV string( 'Defect Class'(029) ) ) ).
LOOP AT it_items ASSIGNING <ls_item>.
<ls_data>-item = <ls_item>-fenum.
<ls_data>-text = <ls_item>-fetxt.
"Defect Location
CONCATENATE <ls_item>-oteil <ls_item>-txtcdot
INTO <ls_data>-defect_loc SEPARATED BY space.
"Code Group
CONCATENATE <ls_item>-fegrp <ls_item>-txtgr
INTO <ls_data>-code_group SEPARATED BY space.
"Defect Type
CONCATENATE <ls_item>-fecod <ls_item>-txtcd
INTO <ls_data>-defect_type SEPARATED BY space.
"Defect Class
CONCATENATE <ls_item>-feqklas <ls_item>-fehlkltext
INTO <ls_data>-defect_class SEPARATED BY space.
lv_table = convert_values_to_html( iv_header     = lv_header_txt
it_dataheader = lt_headers
it_data       = lt_data
iv_datacellbordersindefault = abap_true ).

Here we create a Data Table row structure, Table Headers, complete Header and Data Tables with values and pass them into the Method. Here we ask the Add-On to create a table with borders around all cells. As a result, we have HTML coded Section created.


As you can see, the Add-On is easy to understand, and the sample code can be easily reused with small adjustments for any situation and any content that should be included into the email. All you need to do is to prepare values and/or data tables and pass them into the Method.