SAP MDG · WORKFLOWS
How do I derive the MDG supplier workflow rule context and scenario in ABAP for rule-based workflow?
Use IF_USMD_SSW_RULE_CNTX_PREPARE in a helper class such as ZCL_MDG_SUPPL_RULE_CONTEXT to derive a scenario from the change request, resolve the BRF+ element ID for ZSCENARIO, and append the derived context value to ET_RULE_CONTEXT_VALUE.
Use IF_USMD_SSW_RULE_CNTX_PREPARE in a helper class such as ZCL_MDG_SUPPL_RULE_CONTEXT to derive a scenario from the change request, resolve the BRF+ element ID for ZSCENARIO, and append the derived context value to ET_RULE_CONTEXT_VALUE.
In the supplier workflow example, the rule context is prepared by a helper class that derives a scenario from the change request, looks up the BRF+ element ID for `ZSCENARIO`, and passes the scenario into `ET_RULE_CONTEXT_VALUE`. The same helper also contains the logic to read CR type, commodity code, account group, commodity indicator, and critical-field flags before deciding the workflow scenario.
Process flow
- Read CR type from `USMD120C` or application context fallback.
- Derive scenario from the change request attributes and customizing.
- Resolve BRF+ element ID for `ZSCENARIO` using `CL_USMD_WF_SSW_RULE_SERVICE=>GET_CR_TYPE_APP_ID` and BRF+ query.
- Create typed context data for `ZMDG_SUPP_WF_SCENARIO`.
- Append the context entry to `ET_RULE_CONTEXT_VALUE`.
- Return error text when configuration or source data is incomplete.
Application for the relevant MDG CR type -> Data Object Element -> `ZSCENARIO`
Store the rule-context element that receives the derived supplier workflow scenario.
Referenced tables
| Object | Purpose |
|---|---|
USMD120C | Stores the change request type for the change request. |
ZMD_SUPP_WF_SCEN | Scenario mapping table used to pick the best supplier workflow scenario. |
ZMDG_BP_COMM | Commodity code to direct/indirect indicator mapping. |
ZMDG_SUP_WF | Workflow routing configuration used to detect critical changes. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1class ZCL_MDG_SUPPL_RULE_CONTEXT definition
2 public
3 final
4 create public .
5
6public section.
7
8 interfaces IF_BADI_INTERFACE .
9 interfaces IF_USMD_SSW_RULE_CNTX_PREPARE .
10
11 class-data GT_ACTIVE_DATA type USMD_TS_DATA_ENTITY .
12
13 class-methods GET_ELEMENT_ID
14 importing
15 !IV_CR_TYPE type USMD_CREQUEST_TYPE
16 !IV_NAME type IF_FDT_TYPES=>NAME
17 exporting
18 !EV_BRF_EXPR_ID type IF_FDT_TYPES=>ID .
19 class-methods GET_SCENARIO_ID
20 importing
21 value(IV_CR_TYPE) type USMD_CREQUEST_TYPE optional
22 value(IV_COMMCODE) type MATKL optional
23 value(IV_ZCOM_D_I) type ZCOM_D_I optional
24 value(IV_ACCGROUP) type KTOKK optional
25 value(IV_IS_CRITICAL) type BOOLE_D optional
26 exporting
27 !EV_SCENARIO type ZMDG_SUPP_WF_SCENARIO
28 !EV_ERROR_DESC type TEXT200 .
29 class-methods GET_SCENARIO_FROM_CR
30 importing
31 value(IV_CREQUEST) type USMD_CREQUEST optional
32 exporting
33 value(EV_SCENARIO) type ZMDG_SUPP_WF_SCENARIO
34 !EV_ERROR_DESC type TEXT200 .
35protected section.
36private section.
37ENDCLASS.
38
39
40
41CLASS ZCL_MDG_SUPPL_RULE_CONTEXT IMPLEMENTATION.
42
43
44METHOD get_element_id.
45 DATA:
46 lv_application_id TYPE if_fdt_types=>id,
47 lo_brf_factory TYPE REF TO if_fdt_factory,
48 lo_brf_query TYPE REF TO if_fdt_query,
49 lt_selection TYPE if_fdt_query=>ts_selection,
50 ls_selection LIKE LINE OF lt_selection,
51 ls_obj_category TYPE if_fdt_query=>s_object_category_sel,
52 lt_names TYPE if_fdt_query=>ts_name,
53 ls_names TYPE if_fdt_query=>s_name.
54
55*--------------------------------------------------------------------*
56
57 ASSERT iv_cr_type IS NOT INITIAL.
58 ASSERT iv_name IS NOT INITIAL.
59
60* get the ID of the brf+ application depending on the CR type
61 lv_application_id = cl_usmd_wf_ssw_rule_service=>get_cr_type_app_id( iv_cr_type ).
62 IF lv_application_id IS INITIAL.
63 MESSAGE x000(usmd1). "no brf+ application exists for this cr type
64 ENDIF.
65
66 lo_brf_factory = cl_fdt_factory=>if_fdt_factory~get_instance( ).
67
68* create a query object instance ...
69 lo_brf_query = lo_brf_factory->get_query(
70 iv_object_type = if_fdt_constants=>gc_object_type_data_object
71 iv_data_object_type = if_fdt_constants=>gc_data_object_type_element ).
72
73* ... and define the selection criteria
74 ls_selection-queryfield = if_fdt_admin_data_query=>gc_fn_name.
75 ls_selection-sign = 'I'.
76 ls_selection-option = 'EQ'.
77 ls_selection-low = iv_name.
78 INSERT ls_selection INTO TABLE lt_selection.
79
80 ls_selection-queryfield = if_fdt_admin_data_query=>gc_fn_application_id.
81 ls_selection-sign = 'I'.
82 ls_selection-option = 'EQ'.
83 ls_selection-low = lv_application_id.
84 INSERT ls_selection INTO TABLE lt_selection.
85
86 ls_obj_category-system_objects = abap_true.
87 ls_obj_category-customizing_objects = abap_true.
88 ls_obj_category-masterdata_objects = abap_false.
89
90* select the data
91 lo_brf_query->select_data(
92 EXPORTING
93 its_selection = lt_selection
94 is_object_category_sel = ls_obj_category
95 IMPORTING
96 eta_data = lt_names ).
97
98 READ TABLE lt_names INTO ls_names INDEX 1.
99 ev_brf_expr_id = ls_names-id.
100
101ENDMETHOD.
102
103
104 METHOD get_scenario_from_cr.
105*&---------------------------------------------------------------------*
106*& Method : GET_SCENARIO_FROM_CR
107*&---------------------------------------------------------------------*
108*& Description : Derives the supplier workflow scenario ID for a change
109*& request. Collects the attributes that identify the
110*& scenario (CR type, account group, commodity code and
111*& its direct/indirect indicator), evaluates whether the
112*& CR contains critical field changes, and passes them to
113*& the rule context. Also returns a description of any
114*& missing configuration or mandatory field.
115*&---------------------------------------------------------------------*
116*& Parameters :
117*& IV_CREQUEST IMPORTING Change request number
118*& EV_SCENARIO EXPORTING Derived workflow scenario ID
119*& EV_ERROR_DESC EXPORTING Error / missing-field description,
120*& initial when the derivation is completeThe remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How is the supplier workflow scenario determined from the change request in SAP MDG?
- How do I implement IF_USMD_SSW_RULE_CNTX_PREPARE for a supplier workflow?
- How do I pass a custom scenario into BRF+ rule context in MDG workflow?
Possible questions
- What class prepares the BRF+ rule context for the supplier workflow?
- Which method derives the supplier workflow scenario from a change request?
- How does the code determine whether a supplier change is critical?
- How is the BRF+ expression ID read for a rule context element?
- Which tables are checked for commodity code indicator and workflow scenario mapping?