SAP MDG · VALIDATION DERIVATION
How do I implement USMD cross-entity derivation in SAP MDG using IF_EX_USMD_RULE_SERVICE2~DERIVE?
Implement the cross-entity derivation in IF_EX_USMD_RULE_SERVICE2~DERIVE, use a guard clause for unbound framework objects, read CR context from CL_USMD_APP_CONTEXT, route by process/type, and write all derived values only through IO_WRITE_DATA. In the retrieved system pattern, the custom implementations are ZCL_MDGBP_BP_CROSS_DERIVATION and ZCL_SUPP_DERIVATION_CROSS_BADI.
Implement the cross-entity derivation in IF_EX_USMD_RULE_SERVICE2~DERIVE, use a guard clause for unbound framework objects, read CR context from CL_USMD_APP_CONTEXT, route by process/type, and write all derived values only through IO_WRITE_DATA. In the retrieved system pattern, the custom implementations are ZCL_MDGBP_BP_CROSS_DERIVATION and ZCL_SUPP_DERIVATION_CROSS_BADI.
Implement USMD cross-entity derivation in BAdI USMD_RULE_SERVICE_CROSS_ET via IF_EX_USMD_RULE_SERVICE2~DERIVE. The retrieved system pattern uses a router-style class that first checks the framework references, then reads the change-request context, branches by process and CR type, and delegates to focused helper methods for supplier and customer derivation. All output is written back through the delta write buffer, not by direct table update.
Process flow
- Open SE18 and confirm the BAdI definition
USMD_RULE_SERVICE_CROSS_ETand interface IF_EX_USMD_RULE_SERVICE2. - Create or open the implementation in SE19 and assign a Z* implementing 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 application context with CL_USMD_APP_CONTEXT=>GET_CONTEXT( ).
- Branch by process, CR type, and CR step.
- Call focused helper methods for supplier and customer derivation.
- Write all derived data only through IO_WRITE_DATA->WRITE_DATA( ).
Referenced tables
| Object | Purpose |
|---|---|
usmd_t_message | Message table returned from DERIVE in ET_MESSAGE_INFO. |
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
- How do I build a cross-entity derivation BAdI for SAP MDG BP scenarios?
- What is the implementation pattern for
USMD_RULE_SERVICE_CROSS_ET? - Which class and method are used for MDG cross-entity derivation?
Possible questions
- How do I implement USMD cross-entity derivation in SAP MDG using IF_EX_USMD_RULE_SERVICE2~DERIVE?
- What are the main methods in a custom MDG cross-derivation class?
- How do I route supplier and customer derivation logic in MDG?
- How should IO_CHANGED_DATA and IO_WRITE_DATA be used in cross-entity derivation?
- How do I debug a
USMD_RULE_SERVICE_CROSS_ETimplementation?