Cuando queremos mandar un mail o un adjunto en formato HTML podemos utilizar la Transacción SMW0 junto con la función WWW_HTML_MERGER.
Esto nos permitirá reemplazar textos predefinidos en el HTML de forma sencilla y de esta forma evitar andar concatenando strings en el código fuente.
1- Debemos armar nuestro HTML template y a los textos que queremos reemplazar definirlos con una “variable” por ejemplo:
<HTML>
<BODY>
Fecha del día: !DATE!
Usuario: !USER!
</BODY>
< /HTML>
Yo personalmente elegí escribirlos en mayúsculas y entre signos de exclamación pero como reemplazaremos dichas cadenas, pueden estar definidas o también podemos reemplazar masívamente cualquier cadena de textos.
2- Lo subimos al servidor por medio de la transacción SMW0
Acá podemos crear nuevos templates o editar, actualizar, subir, bajar ya existentes. Lo importante es el nombre que definamos, ya que luego será usado.
3- Código Fuente
" 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_html_string TYPE string.
REFRESH lt_html_table.
" Remplace !DATE! with value
CLEAR ls_merge_table.
ls_merge_table-name = ‘!DATE!’.
ls_merge_table-command = ‘R’. "Replace
lv_string = sy-datum.
APPEND lv_string TO ls_merge_table-html[].
APPEND ls_merge_table TO lt_merge_table.
" Remplace !USER! with value
CLEAR ls_merge_table.
ls_merge_table-name = ‘!USER!’.
ls_merge_table-command = ‘R’. "Replace
lv_string = sy-uname.
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 = ‘ZTEMPLATE_MAIL’ "Valor definido en transacción SMW0
IMPORTING
html_table = lt_html_table[]
CHANGING
merge_table = lt_merge_table[].
LOOP AT lt_html_table INTO ls_html_table.
lv_html_string = lv_html_string && ls_html_table-line.
ENDLOOP.
Tendremos como resultado el código html subido al servidor en string con los valores que nosotros definidos reemplazados.