SAP MDG · UTILITIES
How do I read SAP MDG approval information and workflow decisions for a master data Change Request?
Use CL_USMD_MODEL_EXT=>GET_INSTANCE and IF_USMD_MODEL~READ_CHAR_VALUE to find the master data object, then IF_USMD_CREQUEST_API~RETRIEVE_CREQUEST to get the Change Request, and CL_USMD4_CREQUEST_PROTOCOL=>WORKITEMS_TO_OBJECT, GET_WORKITEM_DETAIL, and READ_CONTAINER to read approver and decision data from the workflow log.
Use CL_USMD_MODEL_EXT=>GET_INSTANCE and IF_USMD_MODEL~READ_CHAR_VALUE to find the master data object, then IF_USMD_CREQUEST_API~RETRIEVE_CREQUEST to get the Change Request, and CL_USMD4_CREQUEST_PROTOCOL=>WORKITEMS_TO_OBJECT, GET_WORKITEM_DETAIL, and READ_CONTAINER to read approver and decision data from the workflow log.
Use the MDG API sequence to go from master data to Change Request and then to workflow history: search the object with CL_USMD_MODEL_EXT=>GET_INSTANCE plus READ_CHAR_VALUE, retrieve the Change Request with IF_USMD_CREQUEST_API~RETRIEVE_CREQUEST, and read workflow protocol items with WORKITEMS_TO_OBJECT, GET_WORKITEM_DETAIL, and READ_CONTAINER. The approver is taken from WI_AAGENT / WI_AA_NAME, and the decision is read from ACTION_RESULT when it is populated.
Process flow
- Get the MDG model instance with CL_USMD_MODEL_EXT=>GET_INSTANCE.
- Build selection conditions in
USMD_TS_SELand call IF_USMD_MODEL~READ_CHAR_VALUE. - Read the Change Request with IF_USMD_CREQUEST_API~RETRIEVE_CREQUEST into
USMD_TS_CREQUEST. - Build the BOR object key for BUS2250 by concatenating the Change Request number with index 000000.
- Call CL_USMD4_CREQUEST_PROTOCOL=>WORKITEMS_TO_OBJECT to get workflow items.
- Loop over only dialog work items where WI_TYPE = 'W'.
- Call CL_USMD4_CREQUEST_PROTOCOL=>GET_WORKITEM_DETAIL to read approver details.
- Call CL_USMD4_CREQUEST_PROTOCOL=>READ_CONTAINER to read ACTION_RESULT from the workflow container.
Referenced tables
| Object | Purpose |
|---|---|
USMD_TS_CREQUEST | Holds the Change Request result returned by RETRIEVE_CREQUEST. |
USMD_TS_SEL | Selection criteria table used for READ_CHAR_VALUE. |
USMD_TS_VALUE | Entity-key table used to identify the master-data object for RETRIEVE_CREQUEST. |
USMD220T | Text/description of the user decision. |
USMD220C | Description of action results for data element USMD_CREQUEST_ACTION. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1*---------------------------------------------------------------------*
2* SAP MDG - Read Approval Information for Master Data
3*---------------------------------------------------------------------*
4
5*---------------------------------------------------------------------*
6* 2.1.2 Search Account
7*---------------------------------------------------------------------*
8
9 DATA: lr_model TYPE REF TO if_usmd_model_ext.
10
11 DATA: lt_sel TYPE usmd_ts_sel.
12 DATA: ls_sel TYPE usmd_s_sel.
13 DATA: lr_data TYPE REF TO data.
14
15 FIELD-SYMBOLS: <lt_data> TYPE SORTED TABLE.
16 FIELD-SYMBOLS: <ls_data> TYPE any.
17 CONSTANTS: lc_incl TYPE ddsign VALUE 'I'.
18
19 CONSTANTS: lc_equal TYPE ddoption VALUE 'EQ'.
20 CONSTANTS: lc_model TYPE usmd_model VALUE '0G'.
21 CONSTANTS: lc_fld_account TYPE usmd_fieldname VALUE 'ACCOUNT'.
22
23* Get model instance
24 CALL METHOD cl_usmd_model_ext=>get_instance
25 EXPORTING
26 i_usmd_model = lc_model
27 IMPORTING
28 eo_instance = lr_model.
29
30 CALL METHOD lr_model->create_data_reference
31 EXPORTING
32 i_fieldname = lc_fld_account
33 i_struct = lr_model->gc_struct_key
34 if_table = abap_true
35 i_tabtype = lr_model->gc_tabtype_sorted
36 IMPORTING
37 er_data = lr_data.
38 ASSIGN lr_data->* TO <lt_data>.
39
40* Convert end user input into selection for read method
41* Here is only simple example
42*---------------------------------------
43 ls_sel-sign = lc_incl.
44 ls_sel-option = lc_equal.
45
46 CLEAR lt_sel.
47 ls_sel-fieldname = 'ACCTYP'.
48 ls_sel-low = '2'.
49
50 INSERT ls_sel INTO TABLE lt_sel.
51*-----------------------------------------
52
53* Read Account by selection criteria
54 CALL METHOD lr_model->read_char_value
55 EXPORTING
56 i_fieldname = lc_fld_account
57 it_sel = lt_sel
58 i_readmode = if_usmd_model_ext=>GC_READMODE_ALL_INACT
59 IMPORTING
60 et_data = et_data.
61
62
63*---------------------------------------------------------------------*
64* 2.2.1 Read Change Request by G/L Account Key
65*---------------------------------------------------------------------*
66
67 DATA:
68 lt_entity TYPE usmd_ts_value,
69 ls_entity_value TYPE usmd_s_value,
70 lt_crequest TYPE usmd_ts_crequest.
71
72 CONSTANTS:
73 lc_model TYPE usmd_model VALUE '0G',
74 lc_fld_coa TYPE usmd_fieldname VALUE 'COA',
75 lc_fld_account TYPE usmd_entity VALUE 'ACCOUNT',
76 lc_entity_account TYPE usmd_entity VALUE 'ACCOUNT'.
77
78* Set Key
79 ls_entity_value-fieldname = lc_fld_coa.
80 ls_entity_value-value = 'INT'.
81
82 INSERT ls_entity_value INTO TABLE lt_entity.
83 ls_entity_value-fieldname = lc_fld_account.
84 ls_entity_value-value = '0000113100'.
85
86 INSERT ls_entity_value INTO TABLE lt_entity.
87
88* Read Change request by object
89 cl_usmd_crequest_api=>if_usmd_crequest_api~retrieve_crequest(
90 EXPORTING
91 iv_model = lc_model
92 iv_entity = lc_entity_account
93 it_entity_key = lt_entity
94 if_activeonly = abap_false
95 IMPORTING
96 et_crequest = lt_crequest ).
97
98
99*---------------------------------------------------------------------*
100* 2.2.2 Read Workflow Log by Change Request
101*---------------------------------------------------------------------*
102
103 CONSTANTS: lc_bor_bus2250 TYPE swo_objtyp VALUE 'BUS2250',
104 lc_index TYPE swc_index VALUE '000000',
105
106 BEGIN OF lcs_witype,
107 w TYPE sww_witype VALUE 'W', "Dialog task
108 b TYPE sww_witype VALUE 'B', "Background tasks
109 f TYPE sww_witype VALUE 'F', "Subworkflow
110 END OF lcs_witype.
111
112 FIELD-SYMBOLS: <ls_items> TYPE swr_wihdr.
113
114 DATA: lt_items TYPE usmd4_t_swr_wihdr,
115 lt_message_struct TYPE usmd4_t_swr_mstruc,
116 lt_simple_container TYPE usmd4_t_swr_cont,
117
118 ls_wf_result TYPE usmd4_s_alv_wf_result,
119 ls_message_struct TYPE swr_mstruc,The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How can I retrieve approver and approval decision information from an SAP MDG Change Request?
- Which MDG API reads workflow history and approver data for a master data object?
- How do I get the approval status and user decision for an MDG Change Request?
Possible questions
- How do I read SAP MDG approval information and workflow decisions for a master data Change Request?
- Which classes and methods are used to read MDG workflow approver data?
- How can I adapt the MDG approval-reading logic from G/L Account to another object?
- How do I filter workflow items and read ACTION_RESULT in MDG?
- What are the key return-code checks when reading MDG workflow protocol?