SAP MDG · UTILITIES
How do I build MDG change-document HTML for an email notification?
Use the MDG change-document API to read the change request header and lines, derive the model from the change request, collect field descriptions plus old/new values, and render the result as an HTML table in `SOLI_TAB` for email body usage.
Use the MDG change-document API to read the change request header and lines, derive the model from the change request, collect field descriptions plus old/new values, and render the result as an HTML table in `SOLI_TAB` for email body usage.
Use the MDG change-document APIs to read the change request header and line details, derive the model from the request, and convert the changed fields into an HTML table with Field, Description, Old Value, and New Value columns. The helper in the source also supports optional attribute-tag filtering so you can restrict the output to selected fields before embedding it in an email body.
Process flow
- Insert the change request into a sorted table of `usmd_crequest`.
- Derive the MDG model from `usmd110c` joined with `usmd120c`.
- Get the change-document instance with `cl_usmd_mdf_change_document=>get_instance`.
- Get the model instance with `cl_usmd_model=>get_instance`.
- Read the document header for the change request.
- Read the first document lines and, if present, the latest document lines.
- Build the merged change-field list from old and new details.
- Sort and remove duplicate field names.
Referenced tables
| Object | Purpose |
|---|---|
USMD110C | Stores the MDG model assignment used to derive the model from the change request type. |
USMD120C | Maps the change request to the change request type used in the model lookup. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1METHOD get_change_docs.
2*&- Local types
3 TYPES:
4 ltt_change_request TYPE SORTED TABLE
5 OF usmd_crequest
6 WITH UNIQUE KEY table_line .
7*&- Types for change data
8 TYPES: BEGIN OF lty_change_data,
9 fieldname TYPE usmd_fieldname,
10 desc TYPE usmd_txtlg,
11 old_value TYPE usmd_value,
12 new_value TYPE usmd_value,
13 END OF lty_change_data.
14*&- Table type for changes
15 TYPES: ltt_change_data TYPE STANDARD TABLE OF lty_change_data WITH DEFAULT KEY.
16*&- Create mesh structure for Changed value and Changed details
17 TYPES: BEGIN OF MESH lty_change_docs,
18*&- Changed value
19 value TYPE usmd_ts_change_document_value ASSOCIATION chg_detail
20 TO detail ON seqnr = seqnr,
21*&- Changed detail
22 detail TYPE usmd_th_change_document_change ASSOCIATION chg_value
23 TO value ON seqnr = seqnr,
24 END OF MESH lty_change_docs.
25*&- Consants
26 CONSTANTS: 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>',
27 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>',
28 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>',
29 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>',
30 lc_row_tag TYPE string VALUE '<div style="width:611px;height:40px;float:left;font-size:12px">',
31 lc_row_tag_head TYPE string VALUE '<div style="width:611px;height:25px;float:left;font-size:12px">',
32 lc_cell_tag TYPE string VALUE '<div style="border:1px gray solid;width:150px;height:40px;float:left;font-size:12px;overflow:hidden;overflow-wrap:break-normal;font-family:arial;">',
33 lc_container TYPE string VALUE '<div style="width :800px;height:800px;">',
34 lc_attr_fld TYPE string VALUE '<%CHANGE_DOC%>',
35 lc_end_div TYPE char6 VALUE '</div>'.
36*&- Data declarations
37 DATA: lt_crequest TYPE ltt_change_request,
38 lt_change_data TYPE STANDARD TABLE OF lty_change_data,
39 lt_output TYPE soli_tab,
40 ld_change_doc_html TYPE string VALUE IS INITIAL,
41 ld_old_value TYPE char100,
42 ld_new_value TYPE char100,
43 ls_mesh_old TYPE lty_change_docs,
44 ls_mesh_new TYPE lty_change_docs,
45 ls_change_data TYPE lty_change_data.
46*&- Get string length of the tag
47 IF id_attr_tag NE lc_attr_fld AND id_attr_tag IS NOT INITIAL.
48 SPLIT id_attr_tag AT '-' INTO TABLE DATA(lt_attr_fields).
49 REPLACE ALL OCCURRENCES OF '<%' IN TABLE lt_attr_fields WITH ''.
50 REPLACE ALL OCCURRENCES OF '%>' IN TABLE lt_attr_fields WITH ''.
51 ENDIF.
52*&- Insert Change request to sorted table
53 INSERT id_crequest INTO TABLE lt_crequest.
54*&- Get the data model based on CR
55 SELECT SINGLE usmd_model INTO @DATA(ld_model) FROM usmd110c AS a
56 INNER JOIN usmd120c AS b
57 ON a~usmd_creq_type = b~usmd_creq_type
58 WHERE b~usmd_crequest = @id_crequest.
59 IF sy-subrc NE 0.
60 RETURN.
61 ENDIF.
62*&- Get instance of change document
63 CALL METHOD cl_usmd_mdf_change_document=>get_instance
64 RECEIVING
65 eo_instance = DATA(ldo_cd_ref).
66*&- Get the instance of model for CR
67 CALL METHOD cl_usmd_model=>get_instance
68 EXPORTING
69 i_usmd_model = ld_model
70 IMPORTING
71 eo_instance = DATA(ldo_model)
72 et_message = DATA(lt_message) ##NEEDED.
73*&- Get change documents for the model
74 IF ldo_model IS BOUND AND ldo_cd_ref IS BOUND.
75 CALL METHOD ldo_cd_ref->read_document_header
76 EXPORTING
77 it_crequest = lt_crequest
78 io_model = ldo_model
79 IMPORTING
80 et_document_header = DATA(lt_doc_header).
81 ENDIF.
82*&- Get number of change documents
83 DATA(ld_lines) = lines( lt_doc_header ).
84*&- Read document lines
85 DATA(ls_doc_header_old) = lt_doc_header[ 1 ].
86 CALL METHOD ldo_cd_ref->read_document_lines
87 EXPORTING
88 is_document_header = ls_doc_header_old
89 io_model = ldo_model
90 IMPORTING
91 et_changed_value = ls_mesh_old-value
92 et_changed_detail = ls_mesh_old-detail
93 et_message = lt_message ##NEEDED.
94*&- Check if the data has more than one change document
95 IF ld_lines GT 1.
96 DATA(ld_change_made) = abap_true.
97 DATA(ls_doc_header_new) = lt_doc_header[ ld_lines ].
98*&- Read document lines
99 CALL METHOD ldo_cd_ref->read_document_lines
100 EXPORTING
101 is_document_header = ls_doc_header_new
102 io_model = ldo_model
103 IMPORTING
104 et_changed_value = ls_mesh_new-value
105 et_changed_detail = ls_mesh_new-detail
106 et_message = lt_message ##NEEDED.
107 ENDIF.
108*&- Get list of fields from all the change documents
109 IF ld_change_made EQ abap_true.
110 lt_change_data = VALUE #( FOR ls_old IN ls_mesh_old-detail
111 FOR ls_new IN ls_mesh_new-detail
112 ( fieldname = ls_old-fieldname
113 new_value = ls_old-value_newThe remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How can I render change documents as HTML in an SAP MDG email?
- How do I extract MDG change document values, descriptions, old values, and new values for mail output?
- What is the ABAP pattern for displaying MDG change documents in a table format?
Possible questions
- How do I build MDG change-document HTML for an email notification?
- How can I render change documents as HTML in an SAP MDG email?
- How do I extract MDG change document values, descriptions, old values, and new values for mail output?
- What is the ABAP pattern for displaying MDG change documents in a table format?
- How do I filter change-document output by attribute tag?