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 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.
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:
report yrisctu1_app5.
” as an example, a nested structure
types:
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.
data:
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.
field-symbols:
<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 `myEmailAddress@Company.com`
<fs_recipient>–is_copy = abap_false. ” abap_true for CC
<fs_recipient>–is_blind_copy = abap_false. ” abap_true for BCC
perform fill_data.
try.
” create email request
create object lo_mail
exporting
iv_subject = `TEST`
iv_sender = `test_mail@xyz.com`
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( ).
endif.
catch ycx_erf_not_created
ycx_erf_not_sent.
” handle exception
endtry.
*&———————————————————————*
*& 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[].
endform.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
2 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 |