SAP MDG · WORKFLOWS
How do I implement dynamic agent selection in SAP MDG supplier creation workflow using IF_USMD_SSW_DYNAMIC_AGT_SELECT?
Implement the dynamic agent BAdI so it reads the CR scenario and service name, then fills `CT_USER_AGENT_GROUP`, `CT_NON_USER_AGENT_GROUP`, `CV_NEW_STEP`, and `CV_NEW_CR_STATUS` based on scenario-specific routing. In the supplied pattern, `ZCL_SUP_CRE_DYN_AGENT` dispatches to scenario handlers and uses technical services for special steps such as GTS before activation.
Implement the dynamic agent BAdI so it reads the CR scenario and service name, then fills `CT_USER_AGENT_GROUP`, `CT_NON_USER_AGENT_GROUP`, `CV_NEW_STEP`, and `CV_NEW_CR_STATUS` based on scenario-specific routing. In the supplied pattern, `ZCL_SUP_CRE_DYN_AGENT` dispatches to scenario handlers and uses technical services for special steps such as GTS before activation.
Use a custom dynamic-agent class implementing `IF_USMD_SSW_DYNAMIC_AGT_SELECT` and branch by change request scenario and workflow service name. The supplied supplier-creation pattern in `ZCL_SUP_CRE_DYN_AGENT` reads the scenario from the CR, fetches key attributes like `KTOKK`, `ZTERM`, `ZZOCOMCOD`, and `ZZOPU_DEP`, then fills `CT_USER_AGENT_GROUP` or `CT_NON_USER_AGENT_GROUP` and sets the next step/status accordingly. For special cases, it can switch to a technical service such as `ZMDG_GTS_CALL` before activation.
Process flow
- Create or identify a custom class that implements `IF_USMD_SSW_DYNAMIC_AGT_SELECT`.
- In the BAdI method, clear the export message table and read the CR scenario first.
- Read the request attributes required for routing, such as company code, payment terms, purchasing department, or account group.
- Branch by `IV_SERVICE_NAME` and call a scenario-specific handler method.
- Fill `CT_USER_AGENT_GROUP` for dialog approvers or `CT_NON_USER_AGENT_GROUP` for technical/system routing.
- Set `CV_NEW_STEP`, `CV_NEW_CR_STATUS`, `CV_MERGE_TYPE`, and `CV_MERGE_PARAM` where needed.
- Remove duplicate user-agent entries before leaving the method.
- If required, replace the approval step with a technical step such as `ZMDG_GTS_CALL` before activation.
Referenced tables
| Object | Purpose |
|---|---|
USMD120C | Change request header data used to derive the request type when the app context is not available. |
TVARVC | Stores the `ZMDG_GTS_ALLOWED_CR` list used to decide whether to trigger the GTS technical step. |
ZMDG_BP_COMM | Custom company-code mapping used in the legal approver branch to check `ZCOM_BPM`. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1class ZCL_SUP_CRE_DYN_AGENT definition
2 public
3 final
4 create public .
5
6public section.
7
8 interfaces IF_BADI_INTERFACE .
9 interfaces IF_USMD_SSW_DYNAMIC_AGT_SELECT .
10
11 methods HANDLE_SCENARIO_1
12 importing
13 !IV_CR_NUMBER type USMD_CREQUEST
14 !IV_SERVICE_NAME type USMD_SERVICE_NAME
15 !IV_PAR_AGT_GRP_NUM type USMD_AGENT_GROUP optional
16 exporting
17 !ET_MESSAGE type USMD_T_MESSAGE
18 changing
19 !CT_NON_USER_AGENT_GROUP type USMD_T_NON_USER_AGENT_GROUP
20 !CV_EXP_COMP_HOURS type INT2
21 !CT_USER_AGENT_GROUP type USMD_T_USER_AGENT_GROUP
22 !CT_CONTEXT_TAB type USMD_T_GENERIC_CONTEXT
23 !CV_NEW_STEP type USMD_CREQUEST_APPSTEP
24 !CV_NEW_CR_STATUS type USMD_CREQUEST_STATUS
25 !CV_MERGE_TYPE type USMD_STATUS_MERGE_TYPE
26 !CV_MERGE_PARAM type USMD_SERVICE_NAME .
27 methods HANDLE_SCENARIO_2
28 importing
29 !IV_CR_NUMBER type USMD_CREQUEST
30 !IV_SERVICE_NAME type USMD_SERVICE_NAME
31 !IV_PAR_AGT_GRP_NUM type USMD_AGENT_GROUP optional
32 exporting
33 !ET_MESSAGE type USMD_T_MESSAGE
34 changing
35 !CT_NON_USER_AGENT_GROUP type USMD_T_NON_USER_AGENT_GROUP
36 !CV_EXP_COMP_HOURS type INT2
37 !CT_USER_AGENT_GROUP type USMD_T_USER_AGENT_GROUP
38 !CT_CONTEXT_TAB type USMD_T_GENERIC_CONTEXT
39 !CV_NEW_STEP type USMD_CREQUEST_APPSTEP
40 !CV_NEW_CR_STATUS type USMD_CREQUEST_STATUS
41 !CV_MERGE_TYPE type USMD_STATUS_MERGE_TYPE
42 !CV_MERGE_PARAM type USMD_SERVICE_NAME .
43 methods HANDLE_SCENARIO_7
44 importing
45 !IV_CR_NUMBER type USMD_CREQUEST
46 !IV_SERVICE_NAME type USMD_SERVICE_NAME
47 !IV_PAR_AGT_GRP_NUM type USMD_AGENT_GROUP
48 exporting
49 !ET_MESSAGE type USMD_T_MESSAGE
50 changing
51 !CV_NEW_STEP type USMD_CREQUEST_APPSTEP
52 !CV_NEW_CR_STATUS type USMD_CREQUEST_STATUS
53 !CV_MERGE_TYPE type USMD_STATUS_MERGE_TYPE
54 !CV_MERGE_PARAM type USMD_SERVICE_NAME
55 !CT_NON_USER_AGENT_GROUP type USMD_T_NON_USER_AGENT_GROUP
56 !CV_EXP_COMP_HOURS type INT2
57 !CT_USER_AGENT_GROUP type USMD_T_USER_AGENT_GROUP
58 !CT_CONTEXT_TAB type USMD_T_GENERIC_CONTEXT .
59 methods HANDLE_DYNAMIC_APPROVERS
60 importing
61 !IV_CR_NUMBER type USMD_CREQUEST
62 !IV_SERVICE_NAME type USMD_SERVICE_NAME
63 !IV_PAR_AGT_GRP_NUM type USMD_AGENT_GROUP
64 exporting
65 !ET_MESSAGE type USMD_T_MESSAGE
66 changing
67 !CV_NEW_STEP type USMD_CREQUEST_APPSTEP
68 !CV_NEW_CR_STATUS type USMD_CREQUEST_STATUS
69 !CV_MERGE_TYPE type USMD_STATUS_MERGE_TYPE
70 !CV_MERGE_PARAM type USMD_SERVICE_NAME
71 !CT_NON_USER_AGENT_GROUP type USMD_T_NON_USER_AGENT_GROUP
72 !CV_EXP_COMP_HOURS type INT2
73 !CT_USER_AGENT_GROUP type USMD_T_USER_AGENT_GROUP
74 !CT_CONTEXT_TAB type USMD_T_GENERIC_CONTEXT .
75protected section.
76private section.
77ENDCLASS.
78
79
80
81CLASS ZCL_SUP_CRE_DYN_AGENT IMPLEMENTATION.
82
83
84 METHOD handle_dynamic_approvers.
85
86 DATA: ls_user_agent_group TYPE usmd_s_user_agent_group.
87 DATA: ls_user_agent TYPE usmd_s_user_agent.
88
89* Clear exporting parameter
90 CLEAR et_message.
91 CALL METHOD zcl_mdg_suppl_rule_context=>get_scenario_from_cr
92 EXPORTING
93 iv_crequest = iv_cr_number
94 IMPORTING
95 ev_scenario = DATA(lv_scenario).
96
97 CALL METHOD zcl_mdg_suppl_utility=>get_single_attribute
98 EXPORTING
99 im_crnumber = iv_cr_number
100 im_field = 'KTOKK'
101 IMPORTING
102 ex_value = DATA(lv_ktokk).
103
104 CALL METHOD zcl_mdg_suppl_utility=>get_single_attribute
105 EXPORTING
106 im_crnumber = iv_cr_number
107 im_field = 'ZTERM'
108 IMPORTING
109* ex_value = data(l
110 ct_value = DATA(lt_zterm_values).
111
112 CALL METHOD zcl_mdg_suppl_utility=>get_single_attribute
113 EXPORTING
114 im_crnumber = iv_cr_number
115 im_field = 'ZZOCOMCOD'
116 IMPORTING
117 ex_value = DATA(lv_com_code).
118
119 CALL METHOD zcl_mdg_suppl_utility=>get_single_attribute
120 EXPORTINGThe remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How can I route SAP MDG supplier creation change requests to different approvers dynamically?
- How do I implement a custom dynamic agent BAdI for supplier creation in MDG?
- How do I assign approvers based on change request scenario and service name in MDG supplier workflow?
Possible questions
- What is the purpose of ZCL_SUP_CRE_DYN_AGENT?
- How are scenario-specific handlers used in MDG dynamic agent selection?
- How do I set user and non-user agent groups in a dynamic agent BAdI?
- How do I trigger GTS before activation in an MDG workflow?
- Which workflow structures are used for MDG dynamic agent routing?