Mailmerge for Training Correspondance: Recipient E-mail Address
Using Mailmerge in MS Word is a very popular way to deal with correspondence in Training and Event Management or LSO. However, to make use of it for emails, not just for printed documents, the email address needs to be available as a custom text variable.
In classic Training and Event Management as well as LSO (Learning Solution) you have two options for correspondence: SAP Script based documents and the Mail Merge function for letters or emails as in MS Word (LSO also offers correspondence through Adobe forms and text messages from version 6.02). The fields available for mail merge are the Text Variables included in the respective SAP Script forms. When only using MS Word Mail Merge, we often configur eonly one SAP Script form, which then includes all required variable fields. For print output, most of our customers prefer MS Word against SAP Script for two reasons:
- The HR department doesn’t depend on IT or 3rd party resources to create or change new letters, as long as no new text variables are required.
- It simply looks better.
However, most organisations are no longer using printed letters for communication around trainings, but email. SAP standard correspondence in TEM allows to directly send SAP Script documents by email and picks up the email address from the respective infotypes (e.g. 0105, subtype 0010, for employees). So, the email address doesn’t need to be provided explicitly as a text variable in the forms.
The MS Word Mail Merge function expects exactly that: if you want to use it to send emails, the recipients’ email addresses need to be available in a merge field, so you need to create it as a custom text variable. This isn’t a big issue, if you are familiar with the creation of custom text variables, but it can be a nuisance, if this really is the only one you need.
In this article we demonstrate the required configuration steps and provide some working sample coding to provide a Merge field for “Delegate email”. It’s the SAP standard procedure, so no modifications involved. However, it will require some programming.
1) Create a Data Element
It is important to create a bespoke data element, which doesn’t only have the right data format for the email address, but also clear field labels, as those are used in various places. E.g., the “long field label” is used in the merge field list in MS Word. So, make sure you pick a text users will recognise, when creating the documents in MS Word.
Use COMM_ID_LONG as domain, as this is the one also used for email addresses in infotype 0105.
2) Enhance Structure PPCARC
Text variables are included in one of two structures: PPVAR for SAP standard fields and PPVARC for custom fields. There’s already an empty shell for a customer include (CI_PPVARC) in PPVARC. To add the new field, just display structure PPVARC and double-click the include CI_PPVARC. If no custom fields have been created before, the system will ask, whether the CI should be created now. Just confirm and create the structure as you would any other. Then you are ready to create the new field within that structure. In our example, we’ve created 3 new fields: the email addresses for delegates, trainers and hotels:
All fields need to start with “ZZ”, to avoid collision with current or future SAP standard fields. Going forward, we’ll focus on field ZZTEMAIL only, which we are going to populate with the delegate’s email address.
3) Create a Custom Subroutine Pool
You require a custom subroutine pool to keep the routines, which get the data for the email address and possibly other custom fields. I suggest you copy the SAP program RHKMIT30 into your designated name space (e.g. ZHR*) and then delete all content except for these for leading lines:
INCLUDE mit30top. "global declarations
INCLUDE mit30f01. "help routines
INCLUDE mit30f02. "help routines
4) Routine to Get the Right Data
Then add the following code for the email address field: Coding_find-email_en
Most of this code has been copied from a SAP standard routine and amended slightly. The bespoke part to get the date for the email address is hidden in this form routine, which you can create in the same program (only recommended, if you have very few custom text variables) or in a new include: Coding_find-email_subform_en
The coding examples are not meant to be particularly elegant or clever, but succinct and easy to understand. So, you may want to amend them, but in a standard set-up they work as they are. We assume that delegates can be employees (object type P) or external persons (object type H). For other object types, our example won’t find an email address.
5) Define the New Text Variable
At long last, we are there: you can define the new text variable in the config table. You get there through IMG path Training and Event Management > Day-to-Day Activities > Correspondence > Form Layout > Specify Format for Text Variables (T77VC).
Here you add the new entry to define which routine is to be processed to provide the email address:
In our example we marked the new text variable as “required”, as the message can’t be sent without an email address. Should you plan to work with printed documents in exceptions, you should remove this flag, so you can print the document, even when the email data is missing.
6) Adding it the a Form
With steps 1 to 5 done, you can add the new text variable to a SAP Script form and use it as a merge field in MS Word just as you would do it with any SAP standard text variable.