SAP MDG · VALIDATION DERIVATION
How do I implement USMD_RULE_SERVICE_CROSS_ET derivation logic in SAP MDG?
Implement the BAdI through interface IF_EX_USMD_RULE_SERVICE2 and method DERIVE, then use a guarded router pattern: read the MDG application context, branch by change request type/process/step, read delta data, and write derived rows only through IO_WRITE_DATA.
Implement the BAdI through interface IF_EX_USMD_RULE_SERVICE2 and method DERIVE, then use a guarded router pattern: read the MDG application context, branch by change request type/process/step, read delta data, and write derived rows only through IO_WRITE_DATA.
USMD_RULE_SERVICE_CROSS_ET is implemented via IF_EX_USMD_RULE_SERVICE2~DERIVE. The documented pattern is to keep DERIVE as an orchestration method: guard unbound framework objects, read the MDG application context, route by change request type and process, then delegate supplier/customer derivation to focused submethods such as DERIVE_SUPPL_BUDET, DERIVE_SUP_DEFAULTS, DERIVE_SUPPL_ROLES, DERIVE_SUPPL_AD_EMAIL, DERIVE_SUPPL_ZBP_MSG, DERIVE_CUST_DEFAULTS, and DERIVE_CUST_ROLES.
Process flow
- Open SE18 and display
USMD_RULE_SERVICE_CROSS_ETto confirm interface IF_EX_USMD_RULE_SERVICE2 and method DERIVE. - Open SE19 and create or maintain the BAdI implementation and assign a Z class.
- Implement IF_EX_USMD_RULE_SERVICE2~DERIVE in the class.
- Add a guard clause for io_model, io_changed_data, and io_write_data.
- Read the MDG application context with CL_USMD_APP_CONTEXT=>GET_CONTEXT( ).
- Route by mv_process, mv_crequest_type, and mv_crequest_step.
- Call the relevant supplier/customer submethods such as DERIVE_SUPPL_BUDET, DERIVE_SUP_DEFAULTS, DERIVE_SUPPL_ROLES, DERIVE_SUPPL_AD_EMAIL, DERIVE_SUPPL_ZBP_MSG, DERIVE_CUST_DEFAULTS, and DERIVE_CUST_ROLES.
- Write derived records only through io_write_data->write_data( ). I18n: process_steps already numbered
Referenced tables
| Object | Purpose |
|---|---|
usmd_t_message | Return message table from IF_EX_USMD_RULE_SERVICE2~DERIVE |
usmd_crequest | Change request identifier type used in the derivation context |
bu_group | Business partner grouping value read during supplier-side routing |
ktokk | Account group value read during supplier-side routing |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example: CL_MDG_BS_MAT_CLF2DESCRIPTION.abap
Exact relevant implementation excerpt from the knowledge document set.
1class CL_MDG_BS_MAT_CLF2DESCRIPTION definition
2 public
3 final
4 create public .
5
6public section.
7
8 interfaces IF_BADI_INTERFACE .
9 interfaces IF_EX_USMD_RULE_SERVICE2 .
10
11 class-methods CLASS_CONSTRUCTOR .
12protected section.
13private section.
14
15 types:
16 ty_valuation_tab TYPE STANDARD TABLE OF /mdgmm/_s_mm_pp_valuation WITH DEFAULT KEY .
17
18 constants GC_CLASSTYPE type KLASSENART value '001'. "#EC NOTEXT
19 constants GC_CHARNAME1 type ATNAM value 'IB_TYPE'. "#EC NOTEXT
20 constants GC_CHARNAME2 type ATNAM value 'IB_COLOR'. "#EC NOTEXT
21 class-data GV_CHARID1 type MDG_BS_CLF_CHARID .
22 class-data GV_CHARID2 type MDG_BS_CLF_CHARID .
23
24 class-methods READ_CLASSIFICATION
25 importing
26 !IV_MATNR type MATNR
27 !IV_CLASSTYPE type KLASSENART
28 !IO_MODEL type ref to IF_USMD_MODEL_EXT
29 returning
30 value(RT_VALUATION) type TY_VALUATION_TAB
31 raising
32 CX_MDG_BS_MAT_GEN .
33 class-methods GET_ATINN
34 importing
35 !IV_CHARNAME type ATNAM
36 returning
37 value(RV_CHARID) type ATINN .
38ENDCLASS.
39
40
41
42CLASS CL_MDG_BS_MAT_CLF2DESCRIPTION IMPLEMENTATION.
43
44
45method CLASS_CONSTRUCTOR.
46 " Get the internal characteristic IDs
47 gv_charid1 = get_atinn( gc_charname1 ).
48 gv_charid2 = get_atinn( gc_charname2 ).
49endmethod.
50
51
52METHOD get_atinn.
53 DATA: lt_cabn TYPE STANDARD TABLE OF cabn.
54 DATA: ls_cabn TYPE cabn.
55 CLEAR rv_charid.
56 ASSERT iv_charname <> space.
57 " Read internal characteristic ID from characteristic name
58 CALL FUNCTION 'CLSE_SELECT_CABN_VIA_NAME'
59 EXPORTING
60 characteristic = iv_charname
61 TABLES
62 t_cabn = lt_cabn
63 EXCEPTIONS
64 OTHERS = 0.
65 READ TABLE lt_cabn INTO ls_cabn INDEX 1.
66 rv_charid = ls_cabn-atinn.
67ENDMETHOD.
68
69
70METHOD if_ex_usmd_rule_service2~derive.
71* Merges the valuation of two characteristics (hard-coded on IDs) into description
72* Assumptions:
73* - No change number
74* - No multi-value characteristics
75 DATA: lt_valuation TYPE ty_valuation_tab.
76 DATA: ls_valuation TYPE /mdgmm/_s_mm_pp_valuation.
77 DATA: lr_exc TYPE REF TO cx_mdg_bs_mat_gen.
78 DATA: ls_message TYPE usmd_s_message.
79 DATA: lr_mod TYPE REF TO data.
80 DATA: lt_attribute TYPE usmd_ts_fieldname.
81 DATA: lrt_entity_data TYPE REF TO data.
82 DATA: ls_description TYPE /mdgmm/_st_mm_pp_material.
83 DATA: lv_description TYPE usmd_txtmi.
84 DATA: lv_found1 TYPE abap_bool.
85 DATA: lv_found2 TYPE abap_bool.
86 DATA: lv_value1 TYPE atwrt.
87 DATA: lv_value2 TYPE atwrt.
88 DATA: lt_matnr TYPE SORTED TABLE OF matnr WITH UNIQUE KEY table_line.
89 DATA: lr_descr_struc TYPE REF TO data.
90 DATA: lo_structdescr TYPE REF TO cl_abap_structdescr.
91 FIELD-SYMBOLS: <lf_component> TYPE abap_compdescr.
92 FIELD-SYMBOLS: <lt_description> TYPE STANDARD TABLE.
93 FIELD-SYMBOLS: <ls_description> TYPE any.
94 FIELD-SYMBOLS: <lt_mod> TYPE SORTED TABLE.
95 FIELD-SYMBOLS: <ls_mod> TYPE any.
96 FIELD-SYMBOLS: <lv_matnr> TYPE matnr.
97 CLEAR: et_message_info.
98 " Only consider changed valuations
99 CALL METHOD io_changed_data->read_data
100 EXPORTING
101 i_entity = if_mdg_bs_mat_gen_c=>gc_entity_valuation
102 IMPORTING
103 er_t_data_mod = lr_mod.
104 CHECK lr_mod IS BOUND.
105 ASSIGN lr_mod->* TO <lt_mod>.
106 CHECK sy-subrc = 0 AND <lt_mod> IS ASSIGNED AND <lt_mod> IS NOT INITIAL.
107 " Get the material numbers
108 LOOP AT <lt_mod> ASSIGNING <ls_mod>.
109 ASSIGN COMPONENT if_mdg_bs_mat_gen_c=>gc_attr_material OF STRUCTURE <ls_mod> TO <lv_matnr>.
110 INSERT <lv_matnr> INTO TABLE lt_matnr.
111 ENDLOOP.
112 " Derive description for all changed materials
113 LOOP AT lt_matnr ASSIGNING <lv_matnr>.
114 CLEAR: lv_value1, lv_value2, lv_found1, lv_found2.
115 " Get the changed classification values
116 " if the two characteristics have been changed for the current material
117 LOOP AT <lt_mod> ASSIGNING <ls_mod>.
118 MOVE-CORRESPONDING <ls_mod> TO ls_valuation.
119 CHECK ls_valuation-material = <lv_matnr>.
120 IF ls_valuation-charid = gv_charid1.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- Which interface and method are used for
USMD_RULE_SERVICE_CROSS_ET? - What is the correct BAdI implementation pattern for cross-entity derivation in MDG?
- How do I write supplier/customer cross-entity derivation logic in
USMD_RULE_SERVICE_CROSS_ET?
Possible questions
- How do I add cross-entity defaulting in MDG using
USMD_RULE_SERVICE_CROSS_ET? - How do I route derivation by change request type and process in MDG?
- How do I write delta-buffer-based derivation logic for BP-related entities?
- Which classes implement IF_EX_USMD_RULE_SERVICE2~DERIVE in the example system?
- How do I debug
USMD_RULE_SERVICE_CROSS_ETderivation?