SAP MDG · VALIDATION DERIVATION
How do I implement SAP MDG cross-entity derivation in BAdI USMD_RULE_SERVICE2 using IF_EX_USMD_RULE_SERVICE2~DERIVE?
Implement the BAdI USMD_RULE_SERVICE_CROSS_ET through IF_EX_USMD_RULE_SERVICE2~DERIVE: guard the framework references, read the change-request context with CL_USMD_APP_CONTEXT=>GET_CONTEXT( ), route by CR type/process, read changed entity data from io_changed_data, and write derived values back with io_write_data->write_data( ).
Implement the BAdI USMD_RULE_SERVICE_CROSS_ET through IF_EX_USMD_RULE_SERVICE2~DERIVE: guard the framework references, read the change-request context with CL_USMD_APP_CONTEXT=>GET_CONTEXT( ), route by CR type/process, read changed entity data from io_changed_data, and write derived values back with io_write_data->write_data( ).
SAP MDG cross-entity derivation is implemented in BAdI USMD_RULE_SERVICE_CROSS_ET via interface IF_EX_USMD_RULE_SERVICE2 and method DERIVE. The documented pattern is to guard all framework references, read the application context from CL_USMD_APP_CONTEXT=>GET_CONTEXT( ), branch by change-request type and process, then read changed entity data and write derived records back to the delta buffer.
Process flow
- Open the MDG BAdI implementation for
USMD_RULE_SERVICE_CROSS_ET. - Implement IF_EX_USMD_RULE_SERVICE2~DERIVE in the class.
- Add an initial guard for io_model, io_changed_data, and io_write_data.
- Read the application context with CL_USMD_APP_CONTEXT=>GET_CONTEXT( ).
- Extract the change-request id, type, step, and process.
- Branch by CR type and process before performing derivation.
- Read changed entity data from io_changed_data using the entity name and structure.
- Map source rows into the derived target structure and fill default or copied values only when required by the business rule. Write the target entity rows through io_write_data->write_data( ). Catch CX_USMD_WRITE_ERROR for write failures. If
Referenced tables
| Object | Purpose |
|---|---|
USMD120C | Referenced in the retrieved source as a CR-related table checked before derivation logic proceeds. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1REPORT z_non_modular_zcl_mdg_bp_cross_deriv.
2
3" Training artifact generated from ZCL_MDGBP_BP_CROSS_DERIVATION.
4" First-level submethod calls in IF_EX_USMD_RULE_SERVICE2~DERIVE are expanded inline.
5" This is for AI learning/reference and is not guaranteed to be activation-ready.
6
7CLASS lcl_cross_entity DEFINITION.
8 PUBLIC SECTION.
9 INTERFACES if_ex_usmd_rule_service2.
10ENDCLASS.
11
12CLASS lcl_cross_entity IMPLEMENTATION.
13 METHOD if_ex_usmd_rule_service2~derive.
14*&H ------------------------------------------------------------------*
15*&H HEADER INFORMATION
16*&H-------------------------------------------------------------------*
17*&H AUTHOR: | Mohammad Aziz
18*&H Team : | SAP MDG
19*&H Date: | 26.02.2024
20*&H Date: | DD1K900026
21*$*$------------------------------------------------------------------*
22*&D Cross Derivation
23*$*$------------------------------------------------------------------*
24*&A Start CHANGE HISTORY
25*$*$------------------------------------------------------------------*
26*&A Program changes:
27*$*$------------------------------------------------------------------*
28*&A Date |TA-No. | Programmer (Initials)
29*$*$------------------------------------------------------------------*
30*&A | |
31*$*$------------------------------------------------------------------*
32**Data Declaration
33
34 DATA: lo_context TYPE REF TO if_usmd_app_context,
35 lv_crequest_id TYPE usmd_crequest,
36 lv_bu_group TYPE bu_group,
37 lv_acc_grp TYPE ktokk,
38 lv_crequest_type TYPE usmd_crequest_type,
39 ls_nwbc_context TYPE cl_nwbc=>t_context.
40 IF io_model IS NOT BOUND
41 OR io_changed_data IS NOT BOUND
42 OR io_write_data IS NOT BOUND.
43 RETURN.
44 ENDIF.
45**Get Application Context
46 lo_context = cl_usmd_app_context=>get_context( ).
47 CHECK lo_context IS BOUND.
48
49 lo_context->get_attributes( IMPORTING ev_crequest_id = lv_crequest_id
50 ev_crequest_step = DATA(lv_crequest_step)
51 ev_crequest_type = lv_crequest_type ).
52 IF lo_context->mv_crequest_type = 'ZCUST2P3'.
53 zcl_mdg_bp_util=>update_customer_account_group(
54 io_write = io_write_data " Write Interface to Data Buffer
55 iv_cr_number = lv_crequest_id " Change Request
56 io_changed_data = io_changed_data
57 ).
58 ELSEIF lo_context->mv_crequest_type = 'ZSUPL2P2'.
59
60 zcl_mdg_bp_util=>update_vendor_account_group(
61 io_write = io_write_data " Write Interface to Data Buffer
62 iv_cr_number = lv_crequest_id " Change Request
63 io_changed_data = io_changed_data
64 ).
65
66 "-- Inlined from DERIVE_SUPPL_BUDET --`r`n
67 CONSTANTS:
68 lc_budet TYPE usmd_entity VALUE 'ZBP_BUDET', " Entity Name
69 lc_venval TYPE usmd_entity VALUE 'BP_VENVAL'.
70
71 DATA:
72* lt_budet TYPE STANDARD TABLE OF zbp_budet, " Table for entity
73* ls_budet TYPE zbp_budet, " Structure for entity
74 lo_att_data TYPE REF TO data,
75 lo_att TYPE REF TO cl_abap_structdescr,
76 lt_attribute TYPE usmd_ts_fieldname,
77 lo_app_context TYPE REF TO if_usmd_app_context,
78 lt_ztecustom TYPE STANDARD TABLE OF zmdgbp_s_bp_pp_zbp_budet,
79 lt_ztecustom_ch TYPE STANDARD TABLE OF zmdgbp_s_bp_pp_zbp_budet,
80 ls_ztecustom TYPE zmdgbp_s_bp_pp_zbp_budet,
81 ls_ztecustom_ch TYPE zmdgbp_s_bp_pp_zbp_budet,
82 lt_filter TYPE usmd_t_entity,
83 ls_filter LIKE LINE OF lt_filter,
84 lt_bpvenval TYPE STANDARD TABLE OF /mdgbpx/_s_bp_es_bp_venval,
85 ls_bpvenval TYPE /mdgbpx/_s_bp_es_bp_venval,
86 lo_data_r TYPE REF TO data,
87***************
88 lt_key TYPE usmd_ts_value,
89 ls_key TYPE usmd_s_value.
90***************
91
92 FIELD-SYMBOLS: <fs_component> TYPE abap_compdescr,
93 <fs_lt_data> TYPE SORTED TABLE,
94 <fs_ls_data> TYPE any.
95
96 IF iv_crequest_id IS NOT INITIAL.
97 SELECT COUNT(*) FROM usmd120c WHERE usmd_crequest = iv_crequest_id.
98 IF sy-subrc EQ 0.
99 RETURN.
100 ENDIF.
101 ENDIF.
102
103 IF ( iv_crequest_type = 'ZSUPL2P1'
104 OR iv_crequest_type = 'ZSUPINT2'
105 OR iv_crequest_type = 'ZSUPL4P2'
106 OR iv_crequest_type = 'ZSUPL5P3'
107 OR iv_crequest_type = 'ZSUPL6P1' )
108 AND zcl_mdgbp_bp_validation=>cleared_fields NE 'X'.
109 " Get application context
110 lo_app_context = cl_usmd_app_context=>get_context( ).
111** Begin of insert.
112*** SELECT SINGLE atinn FROM cabn INTO @DATA(lv_mat_group) WHERE atnam = 'VENDOR_MATERIAL_GROUP'.
113*** SELECT SINGLE atinn FROM cabn INTO @DATA(lv_capability) WHERE atnam = 'VENDOR_CAPABILITY'.
114*** io_changed_data->read_data( EXPORTING i_entity = lc_venval
115*** i_struct = 'KATTR'
116*** IMPORTING er_t_data_upd = lo_data_r ).
117*** IF lo_data_r IS BOUND. .
118*** ASSIGN lo_data_r->* TO <fs_lt_data>.
119*** LOOP AT <fs_lt_data> ASSIGNING <fs_ls_data>.
120*** MOVE-CORRESPONDING <fs_ls_data> TO ls_bpvenval.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How do I write cross-entity derivation logic for SAP MDG BP?
- What is the sample implementation pattern for USMD_RULE_SERVICE2~DERIVE?
- How do I populate derived entities from the delta buffer in MDG?
Possible questions
- How do I implement SAP MDG cross-entity derivation in BAdI USMD_RULE_SERVICE2 using IF_EX_USMD_RULE_SERVICE2~DERIVE?
- How do I create an MDG derivation implementation for BP-related entities?
- How do I read changed data and write derived data back in USMD_RULE_SERVICE2~DERIVE?
- What is the correct ABAP pattern for io_changed_data and io_write_data?
- How do I debug cross-entity derivation in MDG change requests?