SAP MDG · UTILITIES

How do I implement an MDG email notification framework for change requests with links, application logs, change documents, and optional attachment handling?

Implement the email flow as a reusable MDG utility: resolve the change request context, build a navigable CR link, fetch recent application log messages, render change-document HTML when needed, replace template placeholders, send the mail through the standard outbound API or BCS, and persist send history for traceability.

Implement the email flow as a reusable MDG utility: resolve the change request context, build a navigable CR link, fetch recent application log messages, render change-document HTML when needed, replace template placeholders, send the mail through the standard outbound API or BCS, and persist send history for traceability.

This MDG email framework is built around a reusable utility class that can resolve recipients, construct a change-request link, enrich the message with SLG1 log output and change-document HTML, and then send the mail through the standard SAP outbound mechanisms. The documented flow also includes template-driven placeholder replacement and send-history persistence for traceability.

Process flow

  1. Read the change request from USMD120C.
  2. Load the email template variant and subject/body text.
  3. Build the change-request URL with get_cr_link.
  4. Fetch application log entries with fetch_slg1_logs if needed.
  5. Render change-document HTML with get_change_docs if needed.
  6. Replace all template tokens with runtime values.
  7. Resolve recipient addresses from configuration or master data.
  8. Send the email using SO_DOCUMENT_SEND_API1 or CL_BCS depending on the setup record and attachment mode. Note the code uses CL_DOCUMENT_BCS, CL_CAM_ADDRESS_BCS, and CL_SAPUSER_BCS for BCS delivery. In classic mode it writes to zmd_wonof_logs

Custom MDG email setup for template, attachment, and immediate send control

Stores the template variant, body/subject text, attachment flag, and immediate processing control used by the utility.

Custom recipient-attribute mapping for master-data-based recipient resolution

Maps the change request setup key to the entity and attribute that contain the recipient email address.

Referenced tables

ObjectPurpose
zmd_wonof_templTemplate store for email subject and body text, including variant-based content blocks.
zmd_wonof_setupSetup source for recipient resolution, attachment mode, and immediate-send control.
zmd_wonof_logsPersistence for send history, recipient tracking, and escalation level.
USMD120CChange request header and workflow-related request context.
USMD1213Change-request data used for template enrichment and optional data blocks.
USMD110CUsed to resolve the MDG model from the change request type.
USMD0020Used to resolve the entity-to-model relationship for attribute-based email lookup.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example

Exact relevant implementation excerpt from the knowledge document.

1"============================================================================== 2" Class: ZCL_WONOF_FRAMEWORK_UTIL 3" Purpose: Generalized MDG email and change-request utility flow 4" Summary: 5" - Resolve recipients from workflow context, configuration, roles, and attributes 6" - Build email bodies from templates and replace placeholders with runtime values 7" - Enrich email content with change-request links, change documents, and application logs 8" - Send the mail, optionally with attachments, and persist send history for traceability 9" - Trigger immediate outbound processing when configured 10" Notes: 11" - This export is generalized for knowledge sharing and maintenance guidance 12" - Custom table names are kept only where the underlying implementation requires them 13" - Comments describe the business role of each block so the flow can be followed quickly 14"============================================================================== 15 16METHOD fetch_slg1_logs. 17 18 " Read application log entries that belong to the current change request. 19 DATA: ld_extnum TYPE balnrext, 20 ld_cr_activation_pattern TYPE string, 21 lt_messages TYPE STANDARD TABLE OF balm, 22 ls_msg_output TYPE bapiret2, 23 ld_recent_date TYPE cva_date, 24 ld_date TYPE cva_date, 25 ld_recent_time TYPE cva_time, 26 ld_time TYPE cva_time, 27 ld_date_diff TYPE i, 28 ld_time_diff TYPE cva_time, 29 ld_sec TYPE i. 30 31 " Build the application-log external number from the change request identifier. 32 CONCATENATE 'CRequest Activation-' iv_crequest_id INTO ld_cr_activation_pattern. 33 ld_extnum = ld_cr_activation_pattern. 34 35 " Read log messages from the application log repository. 36 CALL FUNCTION 'APPL_LOG_READ_DB' 37 EXPORTING 38 external_number = ld_extnum 39 TABLES 40 messages = lt_messages. 41 42 " Sort the messages so the newest entry is processed first. 43 SORT lt_messages BY time_stmp DESCENDING. 44 45 " Keep only the message type requested by the caller. 46 DELETE lt_messages WHERE msgty NE iv_message_type. 47 48 " Capture the newest timestamp as the reference point for the time-window filter. 49 READ TABLE lt_messages ASSIGNING FIELD-SYMBOL(<ls_latest_record>) INDEX 1. 50 IF <ls_latest_record> IS ASSIGNED. 51 CONVERT TIME STAMP <ls_latest_record>-time_stmp TIME ZONE sy-zonlo 52 INTO DATE ld_recent_date TIME ld_recent_time. 53 ENDIF. 54 55 " Format only the messages that fall inside the short time window. 56 LOOP AT lt_messages ASSIGNING FIELD-SYMBOL(<ls_messages>). 57 CONVERT TIME STAMP <ls_messages>-time_stmp TIME ZONE sy-zonlo 58 INTO DATE ld_date TIME ld_time. 59 60 CALL FUNCTION 'SCOV_TIME_DIFF' 61 EXPORTING 62 im_date1 = ld_date 63 im_date2 = ld_recent_date 64 im_time1 = ld_time 65 im_time2 = ld_recent_time 66 IMPORTING 67 ex_days = ld_date_diff 68 ex_time = ld_time_diff 69 EXCEPTIONS 70 start_larger_than_end = 1 71 OTHERS = 2. 72 73 " Convert the HHMMSS-like duration to seconds for a simple threshold check. 74 ld_sec = ( ( ld_time_diff+0(2) * 3600 ) + ( ld_time_diff+2(2) * 60 ) + ld_time_diff+4(2) ). 75 76 " Keep only logs that are close enough to the latest event to be useful in the email. 77 IF ld_date_diff LE 0 AND ld_sec LE 120. 78 CALL FUNCTION 'MESSAGE_TEXT_BUILD' 79 EXPORTING 80 msgid = <ls_messages>-msgid 81 msgnr = <ls_messages>-msgno 82 msgv1 = <ls_messages>-msgv1 83 msgv2 = <ls_messages>-msgv2 84 msgv3 = <ls_messages>-msgv3 85 msgv4 = <ls_messages>-msgv4 86 IMPORTING 87 message_text_output = ls_msg_output-message. 88 89 " Return the log entry in a mail-friendly BAPI structure. 90 APPEND ls_msg_output TO et_messages. 91 CLEAR ls_msg_output. 92 ENDIF. 93 ENDLOOP. 94 95ENDMETHOD. 96 97METHOD get_change_docs. 98 " Build a compact HTML view of field-level changes for a change request. 99 TYPES: 100 ltt_change_request TYPE SORTED TABLE OF usmd_crequest WITH UNIQUE KEY table_line. 101 TYPES: BEGIN OF lty_change_data, 102 fieldname TYPE usmd_fieldname, 103 desc TYPE usmd_txtlg, 104 old_value TYPE usmd_value, 105 new_value TYPE usmd_value, 106 END OF lty_change_data. 107 TYPES: ltt_change_data TYPE STANDARD TABLE OF lty_change_data WITH DEFAULT KEY. 108 TYPES: BEGIN OF MESH lty_change_docs, 109 value TYPE usmd_ts_change_document_value ASSOCIATION chg_detail TO detail ON seqnr = seqnr, 110 detail TYPE usmd_th_change_document_change ASSOCIATION chg_value TO value ON seqnr = seqnr, 111 END OF MESH lty_change_docs. 112 113 CONSTANTS: 114 lc_head1 TYPE string VALUE '<div style="border:1px gray solid;width:150px;height:25px;float:left;font-size:14px;text-align:center;background-color:#C00000;font-family:arial;color:#FFFFFF;"><strong>Field</strong></div>', 115 lc_head2 TYPE string VALUE '<div style="border:1px gray solid;width:150px;height:25px;float:left;font-size:14px;text-align:center;background-color:#C00000;font-family:arial;color:#FFFFFF;"><strong>Description</strong></div>', 116 lc_head3 TYPE string VALUE '<div style="border:1px gray solid;width:150px;height:25px;float:left;font-size:14px;text-align:center;background-color:#C00000;font-family:arial;color:#FFFFFF;"><strong>Old Value</strong></div>', 117 lc_head4 TYPE string VALUE '<div style="border:1px gray solid;width:150px;height:25px;float:left;font-size:14px;text-align:center;background-color:#C00000;font-family:arial;color:#FFFFFF;"><strong>New Value</strong></div></div>', 118 lc_row_tag

The remaining configuration, implementation details, and testing guidance continue from this answer more…

Related questions and keywords

Alternative questions

  • How can I build a reusable SAP MDG email utility for change requests?
  • How do I send MDG workflow emails with CR link and change history?
  • How can I enrich an MDG notification email with application log messages and change documents?

Possible questions

  • How do I create a navigable change-request link in an MDG email?
  • How do I fetch SLG1-style application log messages for a change request?
  • How do I render MDG change documents as HTML in an email body?
  • How do I send an SAP email with attachment handling using BCS?
  • How do I persist MDG email send history for resend control?

Keywords

SAP MDGchange requestemail notificationworkflowapplication logSLG1change documentHTML emailBCSSO_DOCUMENT_SEND_API1CL_BCSUSMD120CUSMD1213USMD0020ZCL_WONOF_FRAMEWORK_UTIL