SAP MDG · VALIDATION DERIVATION
How do I implement SAP MDG cross-entity derivation in USMD_RULE_SERVICE_CROSS_ET?
Implement the cross-entity MDG derivation in IF_EX_USMD_RULE_SERVICE2~DERIVE, keep the method as a router, and delegate customer/supplier logic to focused submethods such as DERIVE_CUST_DEFAULTS, DERIVE_CUST_ROLES, DERIVE_SUP_DEFAULTS, DERIVE_SUPPL_ROLES, DERIVE_SUPPL_AD_EMAIL, DERIVE_SUPPL_ZBP_MSG, DERIVE_SUPPL_BUDET, DERIVE_CUST_LICENSE, and GET_ROLES_DATA.
Implement the cross-entity MDG derivation in IF_EX_USMD_RULE_SERVICE2~DERIVE, keep the method as a router, and delegate customer/supplier logic to focused submethods such as DERIVE_CUST_DEFAULTS, DERIVE_CUST_ROLES, DERIVE_SUP_DEFAULTS, DERIVE_SUPPL_ROLES, DERIVE_SUPPL_AD_EMAIL, DERIVE_SUPPL_ZBP_MSG, DERIVE_SUPPL_BUDET, DERIVE_CUST_LICENSE, and GET_ROLES_DATA.
Implement USMD_RULE_SERVICE_CROSS_ET in IF_EX_USMD_RULE_SERVICE2~DERIVE and keep it as a dispatcher. The retrieved skill catalog shows customer derivation methods for BP-driven defaults, roles, and license data, plus supplier derivation methods for defaults, roles, address email, message-driven values, and business-details values.
Process flow
- Implement IF_EX_USMD_RULE_SERVICE2~DERIVE in the Z* class assigned to
USMD_RULE_SERVICE_CROSS_ET. - Add guard clauses for io_model, io_changed_data, and io_write_data.
- Read the application context using CL_USMD_APP_CONTEXT=>GET_CONTEXT( ).
- Route by mv_process, mv_crequest_type, and mv_crequest_step.
- Call the customer or supplier derivation submethods in deterministic order.
- Use GET_ROLES_DATA for reusable role extraction when role-based derivation is needed.
- Write derived values only through io_write_data->write_data( ).
- Catch write exceptions and append messages to et_message_info.
Referenced tables
| Object | Purpose |
|---|---|
usmd_t_message | Message table used for returning derivation or validation messages from the rule service interface. |
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 set up the
USMD_RULE_SERVICE_CROSS_ETBAdI for BP-derived customer and supplier values? - What is the implementation pattern for IF_EX_USMD_RULE_SERVICE2~DERIVE in SAP MDG?
- How do I route customer and supplier derivation logic in an MDG BAdI?
Possible questions
- Which interface method is used for
USMD_RULE_SERVICE_CROSS_ET? - Which classes implement IF_EX_USMD_RULE_SERVICE2~DERIVE in this system?
- What are the customer derivation methods in ZCL_MDGBP_BP_CROSS_DERIVATION?
- What are the supplier derivation methods in ZCL_MDGBP_BP_CROSS_DERIVATION?
- How should I structure ABAP code for cross-entity MDG derivation?