SAP MDG · VALIDATION DERIVATION
How do I implement cross-entity derivation for MDG for Material characteristic valuations using IF_EX_USMD_RULE_SERVICE2?
Implement the derivation in `IF_EX_USMD_RULE_SERVICE2~DERIVE` and guard it by model, change-request type, Lean Classification, new class assignment, and missing prior valuation. Read changed data from the delta buffer, read existing valuations from `IO_MODEL`, fetch class metadata via the Lean Classification API, and write only newly derived default fix values back to the delta buffer.
Implement the derivation in `IF_EX_USMD_RULE_SERVICE2~DERIVE` and guard it by model, change-request type, Lean Classification, new class assignment, and missing prior valuation. Read changed data from the delta buffer, read existing valuations from `IO_MODEL`, fetch class metadata via the Lean Classification API, and write only newly derived default fix values back to the delta buffer.
Use `CL_MDG_MAT_VALUATION_CROSS_ET` in `IF_EX_USMD_RULE_SERVICE2~DERIVE` for MDG-M cross-entity derivation of characteristic valuations. The example derives only when the change request is for single objects, Lean Classification is active, at least one new class was assigned, and the newly assigned class has fixed characteristic values that were not yet valuated.
Process flow
- Open SE18 and verify the BAdI definition and interface for the rule-service enhancement.
- Create or open the implementation in SE19 and assign the implementing class.
- Implement IF_EX_USMD_RULE_SERVICE2~DERIVE in CL_MDG_MAT_VALUATION_CROSS_ET.
- Check IO_MODEL for the MM data model and read the CR type from CL_USMD_APP_CONTEXT.
- Use CL_USMD2_CUST_ACCESS_SERVICE=>GET_CREQUEST_TYPE to enforce single-object and Lean Classification prerequisites.
- Read changed class assignments and valuation rows from IO_CHANGED_DATA.
- Use IO_MODEL->READ_CHAR_VALUE with IF_NO_FLUSH = ABAP_TRUE to fetch existing values.
- Call CL_MDM_CLF_LEAN_FACTORY=>GET_LEAN_CLF_API and GET_CHARC_META to obtain characteristic metadata and fixed values.
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1class CL_MDG_MAT_VALUATION_CROSS_ET definition
2 public
3 final
4 create public .
5
6public section.
7
8 interfaces IF_BADI_INTERFACE .
9 interfaces IF_EX_USMD_RULE_SERVICE2 .
10protected section.
11private section.
12ENDCLASS.
13
14
15
16CLASS CL_MDG_MAT_VALUATION_CROSS_ET IMPLEMENTATION.
17
18
19METHOD if_ex_usmd_rule_service2~derive.
20*! Example implementation for cross entity derivations for MDG for Material with Characteristic Valuations.
21*
22* The derivation shall only take place
23* - if change request type is used for single objects
24* - if change request type is using Lean Classification
25* - if at least one new class was assigned
26* - if the new class has characteristics with default fix values and these characteristics were not valuated before.
27*
28* The change request information is taken from the application context. The material number and classification dasta is read
29* via the delta buffer. Existing characteristic values are determined via data model and delta buffer.
30*
31* The BAdI is called at least once at every roundtrip (Technical note: the BAdI is triggered in the Flush Method of the Governance API).
32* - Valid for Single Item Maintenance UI and Data import
33* - Messages from Derives are always converted into info messages.
34* - The BAdI gets only the attributes that are changed since the last BAdI call. Unchanged attributes are not transferred by the
35* interface of this BAdI. You need to use the IO_MODEL parameter (method READ_CHAR_VALUE or RETRIEVE_CHAR_VALUE) to determine
36* their values. For more information, see the documentation of the interface IF_USMD_MODEL_EXT.
37*
38* Hint: Set parameter IF_NO_FLUSH to ABAP_TRUE to avoid additional call of the Flush Method
39
40 TYPES:
41 BEGIN OF ty_s_charid,
42 classtype TYPE klassenart,
43 charid TYPE atinn,
44 END OF ty_s_charid.
45
46 CONSTANTS:
47 lc_otc TYPE mdg_object_type_code_bs VALUE if_mdg_otc_const=>material.
48
49 DATA:
50 lo_clf_lean_api TYPE REF TO if_mdm_clf_lean_api,
51 ls_crequest_type TYPE usmd_s_crequest_type,
52 lv_crequest_type TYPE usmd_crequest_type,
53 lo_usmd_app_context TYPE REF TO if_usmd_app_context,
54 lt_charc_meta TYPE if_mdm_clf_lean_api=>ty_ts_charc_meta,
55 lt_charid TYPE STANDARD TABLE OF ty_s_charid,
56 ls_charid LIKE LINE OF lt_charid,
57 ls_valuation TYPE /mdgmm/_s_mm_pp_valuation,
58 lt_valuation TYPE STANDARD TABLE OF /mdgmm/_s_mm_pp_valuation,
59 lt_sel TYPE usmd_ts_sel,
60 ls_sel LIKE LINE OF lt_sel,
61 lrt_classasgn TYPE REF TO data,
62 lrt_valuation TYPE REF TO data,
63 lrs_valuation TYPE REF TO data,
64 lt_attribute TYPE usmd_ts_fieldname,
65 lo_structdescr TYPE REF TO cl_abap_structdescr,
66 lt_message TYPE usmd_t_message,
67 ls_message LIKE LINE OF lt_message,
68 lv_message TYPE string. "#EC NEEDED
69
70 FIELD-SYMBOLS:
71 <lt_classasgn> TYPE SORTED TABLE,
72 <ls_classasgn> TYPE any,
73 <lt_valuation> TYPE SORTED TABLE,
74 <ls_valuation> TYPE any,
75 <ls_fixval> TYPE if_mdm_clf_lean_api=>ty_s_fixval,
76 <lv_material> TYPE matnr,
77 <ls_charc_meta> LIKE LINE OF lt_charc_meta,
78 <lv_class> TYPE klasse_d,
79 <lv_classtype> TYPE klassenart,
80 <lv_charid> TYPE any,
81 <lv_component> TYPE abap_compdescr.
82
83 CLEAR et_message_info.
84
85 "Check if the data model is correct. Should not happen if the BAdI filter value is set correctly.
86 IF io_model IS INITIAL
87 OR io_model->d_usmd_model <> if_mdg_bs_mat_gen_c=>gc_model_mm.
88 RETURN.
89 ENDIF.
90
91 "Retrieve change request information via application context
92 lo_usmd_app_context = cl_usmd_app_context=>get_context( ).
93 IF lo_usmd_app_context IS INITIAL.
94 RETURN.
95 ENDIF.
96
97 "Do the derivation only for single object change request types that support lean classification
98 lo_usmd_app_context->get_attributes( IMPORTING ev_crequest_type = lv_crequest_type ).
99 IF lv_crequest_type IS INITIAL.
100 RETURN.
101 ENDIF.
102
103 cl_usmd2_cust_access_service=>get_crequest_type(
104 EXPORTING
105 iv_usmd_crequest_type = lv_crequest_type
106 IMPORTING
107 es_usmd_crequest_type = ls_crequest_type ).
108
109 IF ls_crequest_type-usmd_single_obj = abap_false
110 OR ls_crequest_type-usmd_clf_lean = abap_false.
111 RETURN.
112 ENDIF.
113
114 "Determine the current entity data, this means the material number and classification assignments.
115 "It is needed to read the correct characteristic information.
116 io_changed_data->read_data(
117 EXPORTING
118 i_entity = if_mdg_bs_mat_gen_c=>gc_entity_classasgn
119 IMPORTING
120 er_t_data_mod = lrt_classasgn ).The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How do I derive default characteristic values in MDG for Material when a new class is assigned?
- How can I implement USMD_RULE_SERVICE2 derivation for Lean Classification in MDG-M?
- How do I write cross-entity derivation logic for material classification valuations in MDG?
Possible questions
- What is the BAdI implementation pattern for cross-entity derivation in MDG-M?
- Which checks should I use before deriving characteristic values in Lean Classification?
- How do I read changed and existing characteristic valuations in a cross-entity derivation?
- How do I prevent unwanted extra flush calls during MDG derivation?
- How do I derive default fix values only for newly assigned classes?