SAP MDG · VALIDATION DERIVATION
How do I implement cross-entity derivation in SAP MDG-F with USMD_RULE_SERVICE_CROSS_ET?
Use BAdI USMD_RULE_SERVICE_CROSS_ET with a class inheriting from CL_USMDZ7_RS_CROSS_ENTITY. The standard framework class already handles changed-entity detection, finds the leading type 1 entity for type 4 changes, avoids duplicate execution per roundtrip, and delegates to the entity-specific derivation class.
Use BAdI USMD_RULE_SERVICE_CROSS_ET with a class inheriting from CL_USMDZ7_RS_CROSS_ENTITY. The standard framework class already handles changed-entity detection, finds the leading type 1 entity for type 4 changes, avoids duplicate execution per roundtrip, and delegates to the entity-specific derivation class.
Implement cross-entity derivation in MDG-F by using BAdI `USMD_RULE_SERVICE_CROSS_ET` and inheriting from `CL_USMDZ7_RS_CROSS_ENTITY`. The framework class checks the MDG-F switch, reads changed entities, resolves type 4 entities to their leading type 1 entity, prevents duplicate derivations in the same roundtrip, and calls the entity-specific derivation class.
Process flow
- Create or identify the BAdI implementation for `
USMD_RULE_SERVICE_CROSS_ET` in enhancement spot `USMD_RULE_SERVICE`. - Assign a custom class inheriting from `CL_USMDZ7_RS_CROSS_ENTITY`.
- Redefine `IF_EX_USMD_RULE_SERVICE2~DERIVE` in the custom class if you need dispatcher-level changes.
- Keep the standard framework call behavior when SAP-delivered logic must continue.
- Implement the actual derivation in the entity-specific rule-service class returned by `cl_usmdz_object_factory=>get_instance_rule_services( iv_entity = lv_main_entity )`.
- Test with a changed entity set that includes both type 1 and type 4 entities and verify duplicate suppression per roundtrip.
Referenced tables
| Object | Purpose |
|---|---|
`if_usmdz_cons_entitytypes=>gc_entity_*` | Constants used by `is_custom_entity_type` to distinguish custom versus SAP entity types. |
`lo_model_ext->if_usmd_model_metadata_ext~dt_entity_prop` | Model metadata table used to identify entity usage type and determine whether the entity is type 1 or type 4. |
`lo_model_ext->if_usmd_model_metadata_ext~dt_entity_cont` | Model metadata table used to resolve a changed type 4 entity to its leading type 1 entity. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1class CL_USMDZ7_RS_CROSS_ENTITY definition
2 public
3 create public .
4
5public section.
6
7 interfaces IF_BADI_INTERFACE .
8 interfaces IF_EX_USMD_RULE_SERVICE2 .
9protected section.
10
11 methods IS_CUSTOM_ENTITY_TYPE
12 importing
13 !IV_ENTITY type USMD_ENTITY
14 returning
15 value(RV_IS_CUSTOM) type ABAP_BOOL .
16private section.
17ENDCLASS.
18
19
20
21CLASS CL_USMDZ7_RS_CROSS_ENTITY IMPLEMENTATION.
22
23
24METHOD if_ex_usmd_rule_service2~derive.
25*! This method implements the cross entity derive for all entity types
26* of data model 0G. It determines the changed entities to call their
27* individual derivation logic.
28 DATA:
29 lo_entity TYPE REF TO cl_usmdz7_rs_entity,
30 lo_exception TYPE REF TO cx_usmdz_exception,
31 lo_model_ext TYPE REF TO cl_usmd_model_ext,
32 lt_changed_entities TYPE usmd_t_entity,
33 lt_derived_entities TYPE usmd_t_entity,
34 lt_message TYPE usmd_t_message,
35 lv_entity TYPE usmd_entity,
36 lv_main_entity TYPE usmd_entity.
37
38 FIELD-SYMBOLS:
39 <ls_entity_cont> TYPE usmd_s_entity_cont,
40 <ls_entity_prop> TYPE usmd_s_entity_prop_ext,
41 <lv_changed_entity> TYPE any.
42
43 "MDG 7.0 is required
44 IF cl_mdg_bs_fin_switch_check=>mdg_sfws_financials_4( ) EQ abap_false.
45 RETURN.
46 ENDIF.
47
48 "prepare
49 IF io_model IS NOT BOUND
50 OR io_changed_data IS NOT BOUND
51 OR io_write_data IS NOT BOUND.
52 RETURN.
53 ENDIF.
54 TRY.
55 lo_model_ext ?= io_model.
56 CATCH cx_sy_move_cast_error.
57 RETURN.
58 ENDTRY.
59 CLEAR lt_derived_entities.
60
61 "get all changed entities to handle the derive
62 io_changed_data->get_entity_types( IMPORTING et_entity = lt_changed_entities ).
63
64 "now handle each entity independently
65 LOOP AT lt_changed_entities ASSIGNING <lv_changed_entity>.
66 CLEAR: lo_entity, lt_message, lv_entity, lv_main_entity.
67
68 "Derivation are implemented for type 1 entities. If a type 4 entity
69 "is changed, determine its leading type 1 entity.
70 READ TABLE lo_model_ext->if_usmd_model_metadata_ext~dt_entity_prop ASSIGNING <ls_entity_prop>
71 WITH KEY usmd_entity = <lv_changed_entity>.
72 CHECK:
73 sy-subrc EQ 0,
74 <ls_entity_prop>-usage_type EQ if_usmd_dm_const=>usage_type_1 OR
75 <ls_entity_prop>-usage_type EQ if_usmd_dm_const=>usage_type_4.
76 IF <ls_entity_prop>-usage_type EQ if_usmd_dm_const=>usage_type_1.
77 lv_main_entity = <lv_changed_entity>.
78 ELSE.
79 lv_entity = <lv_changed_entity>.
80 DO.
81 READ TABLE lo_model_ext->if_usmd_model_metadata_ext~dt_entity_cont ASSIGNING <ls_entity_cont> "#EC CI_SORTSEQ
82 WITH KEY usmd_entity_cont = lv_entity ##primkey[entity_main].
83 CHECK sy-subrc EQ 0.
84 READ TABLE lo_model_ext->if_usmd_model_metadata_ext~dt_entity_prop ASSIGNING <ls_entity_prop>
85 WITH KEY usmd_entity = <ls_entity_cont>-usmd_entity.
86 CHECK sy-subrc EQ 0.
87 IF <ls_entity_prop>-usage_type EQ if_usmd_dm_const=>usage_type_1.
88 lv_main_entity = <ls_entity_prop>-usmd_entity.
89 EXIT.
90 ELSE.
91 lv_entity = <ls_entity_prop>-usmd_entity.
92 ENDIF.
93 ENDDO.
94 ENDIF.
95 CHECK lv_main_entity IS NOT INITIAL
96 AND me->is_custom_entity_type( iv_entity = lv_main_entity ) EQ abap_false.
97
98 "Ensure that the derivation is executed only once (it is possible
99 "to change a type 1 entity and a type 4 entity at the same time).
100 READ TABLE lt_derived_entities TRANSPORTING NO FIELDS
101 WITH KEY table_line = lv_main_entity.
102 IF sy-subrc EQ 0.
103 "derivation already done
104 CONTINUE.
105 ELSE.
106 "derive will be done as next step
107 INSERT lv_main_entity INTO TABLE lt_derived_entities.
108 ENDIF.
109
110 "The cross entity derivation is implemented by the common rule service
111 "classes. This is realized by a specific class for each type 1 entity.
112 "Get an instance of the implementation.
113 TRY.
114 lo_entity = cl_usmdz_object_factory=>get_instance_rule_services( iv_entity = lv_main_entity ).
115 CATCH cx_usmdz_exception INTO lo_exception.
116 cl_usmdz_utilities=>add_message(
117 EXPORTING io_exception = lo_exception
118 CHANGING ct_message = et_message_info ).
119 CONTINUE.
120 ENDTRY.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- Which BAdI is used for cross-entity derivation in MDG-F?
- How do I write a custom cross-entity derivation class for data model 0G?
- How can I extend CL_USMDZ7_RS_CROSS_ENTITY in SAP MDG-F?
Possible questions
- How do I implement cross-entity derivation in SAP MDG-F with
USMD_RULE_SERVICE_CROSS_ET? - Which BAdI is used for cross-entity derivation in MDG-F?
- How do I write a custom cross-entity derivation class for data model 0G?
- How can I extend CL_USMDZ7_RS_CROSS_ENTITY in SAP MDG-F?
- What is the standard SAP pattern for cross-entity derivation in MDG-F?