SAP MDG · UTILITIES
How do I read approval, approver, workflow, and decision information for an SAP MDG master-data object using MDG APIs?
Use the MDG APIs in this order: search the master data with `CL_USMD_MODEL_EXT=>GET_INSTANCE` and `IF_USMD_MODEL~READ_CHAR_VALUE`, retrieve the related Change Request with `IF_USMD_CREQUEST_API~RETRIEVE_CREQUEST`, then read workflow items with `CL_USMD4_CREQUEST_PROTOCOL=>WORKITEMS_TO_OBJECT`, work-item details with `GET_WORKITEM_DETAIL`, and the workflow container with `READ_CONTAINER` to obtain approver and decision data.
Use the MDG APIs in this order: search the master data with `CL_USMD_MODEL_EXT=>GET_INSTANCE` and `IF_USMD_MODEL~READ_CHAR_VALUE`, retrieve the related Change Request with `IF_USMD_CREQUEST_API~RETRIEVE_CREQUEST`, then read workflow items with `CL_USMD4_CREQUEST_PROTOCOL=>WORKITEMS_TO_OBJECT`, work-item details with `GET_WORKITEM_DETAIL`, and the workflow container with `READ_CONTAINER` to obtain approver and decision data.
Use the MDG master-data read API to identify the object key, then retrieve the related Change Request and workflow history. The standard flow is: search the object with `CL_USMD_MODEL_EXT=>GET_INSTANCE` and `IF_USMD_MODEL~READ_CHAR_VALUE`, call `IF_USMD_CREQUEST_API~RETRIEVE_CREQUEST`, then read workflow items with `CL_USMD4_CREQUEST_PROTOCOL=>WORKITEMS_TO_OBJECT`, details with `GET_WORKITEM_DETAIL`, and the workflow container with `READ_CONTAINER` to extract approver and decision information.
Process flow
- Search the master data object with `CL_USMD_MODEL_EXT=>GET_INSTANCE` and `IF_USMD_MODEL~READ_CHAR_VALUE`.
- Build the entity key for the identified record.
- Retrieve the related Change Request with `IF_USMD_CREQUEST_API~RETRIEVE_CREQUEST`.
- Read workflow items with `CL_USMD4_CREQUEST_PROTOCOL=>WORKITEMS_TO_OBJECT` for BOR object type `BUS2250`.
- Read work-item details with `CL_USMD4_CREQUEST_PROTOCOL=>GET_WORKITEM_DETAIL` and extract `WI_AAGENT` and `WI_AA_NAME`.
- Read the workflow container with `CL_USMD4_CREQUEST_PROTOCOL=>READ_CONTAINER`.
- Extract the approval decision from `ACTION_RESULT` and map it with `USMD220T` / `USMD220C` if needed.
MDG-F data model `0G`
Standard example data model used by the guide for G/L Account approval retrieval.
Change Request processing with standard, extended, or rule-based MDG workflow
Workflow context required for approval and approver history.
Referenced tables
| Object | Purpose |
|---|---|
USMD_TS_CREQUEST | Returned Change Request result table. |
USMD_TS_SEL | Selection table used for master-data search criteria. |
USMD_TS_VALUE | Entity-key value table. |
USMD4_T_SWR_WIHDR | Workflow item header table. |
USMD4_T_SWR_CONT | Workflow container value table. |
USMD4_S_ALV_WF_RESULT | Workflow log result structure. |
USMD220T | Text or description of the user decision. |
USMD220C | Description of action results for data element `USMD_CREQUEST_ACTION`. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example: read_approval_MDG_API.abap
Exact relevant implementation excerpt from the knowledge document set.
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 approval information be read for an SAP MDG master-data object?
- Which API is used to search a G/L Account in data model `0G`?
- How is a Change Request retrieved from an MDG entity key?
Possible questions
- How can approval information be read for an SAP MDG master-data object?
- Which API is used to search a G/L Account in data model `0G`?
- How is a Change Request retrieved from an MDG entity key?
- Why is the Change Request the central object for approval-log retrieval?
- Which class retrieves workflow items for a Change Request?
- What is BOR object type `BUS2250` used for?
- How is the workflow object key built?
- Which workflow item type represents a dialog task?
- Where are the approver user name and description stored?
- Which method reads the workflow container?
- What does the `ACTION_RESULT` container element represent?
- Which tables provide descriptions for Change Request actions?
- How can this approach be adapted to a different MDG data model or entity?
- Why must the return code be checked after workflow API calls?
- What is the purpose of `GC_READMODE_ALL_INACT`?