SAP MDG · VALIDATION DERIVATION
How do I implement SAP MDG-F cross-entity derivation for a custom field in data model 0G?
Use BAdI USMD_RULE_SERVICE_CROSS_ET in enhancement spot USMD_RULE_SERVICE with filter Data model 0G, inherit from CL_USMDZ7_RS_CROSS_ENTITY, call the SUPER derivation first, then derive only for newly created cost centres and write back only the changed attribute with the full object key and current edition.
Use BAdI USMD_RULE_SERVICE_CROSS_ET in enhancement spot USMD_RULE_SERVICE with filter Data model 0G, inherit from CL_USMDZ7_RS_CROSS_ENTITY, call the SUPER derivation first, then derive only for newly created cost centres and write back only the changed attribute with the full object key and current edition.
Implement the MDG-F cross-entity derivation in BAdI USMD_RULE_SERVICE_CROSS_ET under enhancement spot USMD_RULE_SERVICE, filtered for data model 0G. The documented custom class inherits from CL_USMDZ7_RS_CROSS_ENTITY, calls the inherited implementation first, checks only newly inserted cost-centre records, and derives the responsible-person field when it is still initial.
Process flow
- Create implementation in SE19 for BAdI
USMD_RULE_SERVICE_CROSS_ET. - Set the enhancement spot to
USMD_RULE_SERVICEand filter it for data model 0G. - Assign the implementing class and inherit from CL_USMDZ7_RS_CROSS_ENTITY.
- Redefine IF_EX_USMD_RULE_SERVICE2~DERIVE.
- Call the inherited derive method first to preserve standard logic.
- Read changed entity types from IO_CHANGED_DATA and exit if the target entity is not relevant.
- Read only inserted records for the entity.
- Create the write runtime structure with IO_WRITE_DATA->CREATE_DATA_REFERENCE and obtain the current edition from CL_USMD_APP_CONTEXT. Write only the derived field for records where the target value is initial, using the full object key and
Enhancement spot USMD_RULE_SERVICE with filter Data model 0G
Cross-entity derivation implementation point for MDG-F model 0G.
Referenced tables
| Object | Purpose |
|---|---|
USMD_RULE_SERVICE_CROSS_ET | BAdI used for MDG-F cross-entity derivation. |
USMD_RULE_SERVICE | Enhancement spot for the derivation BAdI. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1"! <p class="shorttext"><strong>MDG-F Cross-Entity Derivation</strong><br/>Custom cost-centre derivation example</p>
2"!
3"! <p>This class implements a custom cross-entity derivation for SAP MDG-F data model 0G.</p>
4"!
5"! <h2>Purpose</h2>
6"! <ul>
7"! <li>Preserve all SAP standard MDG-F derivations by calling the inherited implementation first.</li>
8"! <li>Process newly created cost centres only.</li>
9"! <li>Set field CCTRRESPP to "Mr. X" when no responsible person was supplied.</li>
10"! <li>Write only the derived attribute using the complete object key and current edition.</li>
11"! </ul>
12"!
13"! <h2>Configuration</h2>
14"! <ul>
15"! <li>BAdI: USMD_RULE_SERVICE_CROSS_ET</li>
16"! <li>Enhancement spot: USMD_RULE_SERVICE</li>
17"! <li>Filter: Data model 0G</li>
18"! <li>Superclass: CL_USMDZ7_RS_CROSS_ENTITY</li>
19"! </ul>
20"!
21"! <h2>Important</h2>
22"! <ul>
23"! <li>Replace the fixed example value "Mr. X" with productive responsibility logic.</li>
24"! <li>Do not remove the SUPER call.</li>
25"! <li>The current edition and exact changed-attribute list are mandatory for safe writes.</li>
26"! </ul>
27CLASS zcl_mdgf_rs_cross_et DEFINITION
28 PUBLIC
29 INHERITING FROM cl_usmdz7_rs_cross_entity
30 FINAL
31 CREATE PUBLIC.
32
33 PUBLIC SECTION.
34 METHODS if_ex_usmd_rule_service2~derive REDEFINITION.
35
36 PROTECTED SECTION.
37 PRIVATE SECTION.
38 CONSTANTS gc_person TYPE usmd_fieldname VALUE 'CCTRRESPP'.
39ENDCLASS.
40
41
42
43CLASS zcl_mdgf_rs_cross_et IMPLEMENTATION.
44
45 METHOD if_ex_usmd_rule_service2~derive.
46
47 DATA:
48 lo_context TYPE REF TO if_usmd_app_context,
49 lr_derived_data_struc TYPE REF TO data,
50 lr_derived_data_table TYPE REF TO data,
51 lr_new_data TYPE REF TO data,
52 ls_key TYPE usmd_s_value,
53 lt_attribute TYPE usmd_ts_fieldname,
54 lt_key TYPE usmd_ts_value,
55 lt_changed_entities TYPE usmd_t_entity,
56 lv_edition TYPE usmd_edition.
57
58 FIELD-SYMBOLS:
59 <ls_derived_data> TYPE any,
60 <ls_new_data> TYPE any,
61 <lt_derived_data> TYPE ANY TABLE,
62 <lt_new_data> TYPE ANY TABLE,
63 <lv_value> TYPE any.
64
65 "Execute SAP standard MDG-F derivations first.
66 super->if_ex_usmd_rule_service2~derive(
67 EXPORTING
68 io_model = io_model
69 io_changed_data = io_changed_data
70 io_write_data = io_write_data
71 IMPORTING
72 et_message_info = et_message_info ).
73
74 "Determine which entity types changed.
75 io_changed_data->get_entity_types(
76 IMPORTING
77 et_entity = lt_changed_entities ).
78
79 "The custom rule is relevant only for cost centres.
80 READ TABLE lt_changed_entities TRANSPORTING NO FIELDS
81 WITH KEY table_line = if_usmdz_cons_entitytypes=>gc_entity_cctr.
82
83 IF sy-subrc <> 0.
84 RETURN.
85 ENDIF.
86
87 "Read newly inserted cost-centre records only.
88 io_changed_data->read_data(
89 EXPORTING
90 i_entity = if_usmdz_cons_entitytypes=>gc_entity_cctr
91 IMPORTING
92 er_t_data_ins = lr_new_data ).
93
94 IF lr_new_data IS NOT BOUND.
95 RETURN.
96 ENDIF.
97
98 ASSIGN lr_new_data->* TO <lt_new_data>.
99 IF sy-subrc <> 0 OR <lt_new_data> IS INITIAL.
100 RETURN.
101 ENDIF.
102
103 "Create the correct runtime structure for writing derived data.
104 TRY.
105 lr_derived_data_table = io_write_data->create_data_reference(
106 i_entity = if_usmdz_cons_entitytypes=>gc_entity_cctr
107 i_struct = io_model->gc_struct_key_attr ).
108
109 ASSIGN lr_derived_data_table->* TO <lt_derived_data>.
110 IF sy-subrc <> 0.
111 RETURN.
112 ENDIF.
113
114 CREATE DATA lr_derived_data_struc LIKE LINE OF <lt_derived_data>.
115 ASSIGN lr_derived_data_struc->* TO <ls_derived_data>.
116 IF sy-subrc <> 0.
117 RETURN.
118 ENDIF.
119
120 CATCH cx_usmd_write_error.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- Which BAdI is used for MDG-F cross-entity derivation in model 0G?
- How do I preserve standard derivation and add a custom derivation in MDG-F?
- How do I write derived data safely in
USMD_RULE_SERVICE_CROSS_ET?
Possible questions
- How do I implement SAP MDG-F cross-entity derivation for a custom field in data model 0G?
- Which BAdI is used for MDG-F cross-entity derivation in model 0G?
- How do I preserve standard derivation and add a custom derivation in MDG-F?
- How do I write derived data safely in
USMD_RULE_SERVICE_CROSS_ET? - How do I derive a cost centre responsible person only for newly created records?