Skip to Content
Technical Articles

Email Rendering using SAP DMS

I find it quite often that my team and I are asked to insert different kinds of email notifications/reminders into our programs. Sometimes the requirements for these kinds of emails is simple (plain text), in other cases however, the users want texts with different fonts, colors and sizes, hyperlinks, attached files, or even embedded images.

Usually, I’ve seen developers insert their HTML coding between ABAP lines. Even though this is a working solution, it’s not optimum as the overall flexibility (openness to changes) and maintainability is close to none.

Yet, being lazy as I am, I wanted to build a more generic solution, something easy to modify (hopefully, not by myself). I called it Email Rendering Framework, in short ERF. I figured a relatively cool name will make this even more successful.

As a prerequisite to this alternative, you must have CA-DMS (Document Management System) installed on your SAP system. A content server is helpful, but it’s not mandatory.

Also, the SMTP-based mail server (mlunxsnd) must be configured.

As a short description of the solution:

The system administrator or process expert creates the body of the email using Microsoft Word. Inserts place holders for dynamic values, hyperlinks and embedded images. Saves this file as a Web Page, Filtered (.html) and uploads it into SAP using DMS. Except for a small configuration database table, everything else is taken care of by the ERF class.

For this solution to be as efficient as possible, it should be both easy to use and even easier to maintain. In order to see which email and when to send it, the email framework reads data from a database configuration table.

Data element YERF_DTE_SOURCE_TYPE is defined by its underlying domain YERF_DOM_SOURCE_TYPE, which is also defined by its value range { ‘C’ (Content), ‘I’ (Image) }.

All this will make sense in just a little bit. So, here’s the rest of the structures:

The corresponding table types must be created. I’ve used ‘STR’ and ‘TTY’ for naming conventions and ‘T’ for database tables.

The following picture describes the rendering class which makes use of the above configuration:

I haven’t directly inserted the code here, as the content would grow out of proportions, but I’ve attached the class in source code-based at the bottom. Also, for this to work, a number of exception classes must be created.

The QUERY_DIR method can of course be rewritten using the /PLM/ framework. I chose not to do this because of authorization problems.

After creating the configuration table and the email rendering class, we are now going to generate the first template and write a DEMO report.

Open a new Word document, and type-in whatever you wish.

  1. Set &&<fieldname>&& for dynamic values. That is, values that you want to get at runtime from the SAP system.

2. As an image tag, you just type in the name of the picture which you will later set in the configuration table.

Save the file as Web Page, Filtered:

Check in the document into the SAP system using DMS (I want to show you the steps as they might differ from system or DMS version). But remember the document information record (DIR) key.

You will need to fill this in the configuration table afterwards:

To try out how it works, just copy-paste the following code into a new report:

report yrisctu1_app5.

” as an example, a nested structure
  begin of ts_struct1,
      scarr type scarr_tab,
    end of ts_struct1,
  begin of ts_struct2,
      struct1 type ts_struct1,
      dir_id type /plmb/s_dir_id,
    end of ts_struct2,
  begin of ts_struct3,
      struct2 type ts_struct2,
      matnr   type /plmb/matnr,
    end of ts_struct3.

  lo_mail       type ref to ycl_erf_request,
  lt_recipients type yerf_tty_recipient,
  ls_config_id  type yerf_str_config_id,
  ls_data       type ts_struct3.

  <fs_recipient> type yerf_str_recipient.

” object name is unique in the system (you have to maintain database table YERF_T_CONFIG)
ls_config_id–applicationid = `YERF_DEMO`.
ls_config_id–counter       = `001`.

” set recipient(s)
append initial line to lt_recipients[] assigning <fs_recipient>.
<fs_recipient>–smtp          = sy–uname.   ” OR ``
<fs_recipient>–is_copy       = abap_false. ” abap_true for CC
<fs_recipient>–is_blind_copy = abap_false. ” abap_true for BCC

perform fill_data.

   ” create email request
    create object lo_mail
        iv_subject     = `TEST`
        iv_sender      = ``
        it_recipients  = lt_recipients[]
*       it_attachments = ” for this example, I didn’t use any attachments
        is_data        = ls_data
        is_config_id   = ls_config_id.

    if lo_mail is bound.
      lo_mail->send( ).

  catch ycx_erf_not_created
    ” handle exception

*&      Form  FILL_DATA
form fill_data.
  ls_data–matnr = `12345600`.
  ls_data–struct2–dir_id–documenttype    = `D11`.
  ls_data–struct2–dir_id–documentnumber  = `1234567890123456789012345`.
  ls_data–struct2–dir_id–documentpart    = `001`.
  ls_data–struct2–dir_id–documentversion = `01`.

  select *
         up to 10 rows
         from scarr
         into corresponding fields of table ls_data–struct2–struct1–scarr[].


After creating all the necessary data structures and rendering class in Part 2, followed by a test template and a demo report in Part 3, we now have our first initial sample:


This is just a test. Of course, you are more than welcomed to discover the possibilities and limits of this framework. Also, any kind of extensions, bug fixes, or suggestions will be greatly considered.

PS: I forgot to mention the hyperlinks in Part 2, so I’ll just add it here.

First step, you need to create the following structure:


Step two: Enhance the rendering class with an extra SET_HYPERLINKS method:

method set_hyperlinks.

type string value is initial.

type yerf_str_hyperlink.

loop at it_hyperlinks[] assigning <fs_hyperlink>.
concatenate ‘<a href=”‘ <fs_hyperlink>url ‘”>’ <fs_hyperlink>tag ‘</a>’ into lv_value.

replace <fs_hyperlink>tag in mv_content with lv_value. clear lv_value.


1 Comment
You must be Logged on to comment or reply to a post.