SAP MDG · VALIDATION DERIVATION
How do I implement SAP MDG cross-entity derivation in BAdI USMD_RULE_SERVICE_CROSS_ET for BP supplier and customer flows?
Implement USMD_RULE_SERVICE_CROSS_ET in IF_EX_USMD_RULE_SERVICE2~DERIVE as a small router: guard the framework objects, read the MDG application context, branch by process (SUP1, SUP2, CUP1, CUP2), and delegate supplier/customer defaulting and role logic to focused helper methods that write only through io_write_data.
Implement USMD_RULE_SERVICE_CROSS_ET in IF_EX_USMD_RULE_SERVICE2~DERIVE as a small router: guard the framework objects, read the MDG application context, branch by process (SUP1, SUP2, CUP1, CUP2), and delegate supplier/customer defaulting and role logic to focused helper methods that write only through io_write_data.
Implement the cross-entity derivation in IF_EX_USMD_RULE_SERVICE2~DERIVE as an orchestration method, not as a monolith. The observed pattern in ZCL_MDGBP_BP_CROSS_DERIVATION is to validate that io_model, io_changed_data, and io_write_data are bound, read the application context via CL_USMD_APP_CONTEXT, determine the current CR type, step, and process, and then call dedicated supplier or customer submethods that write buffered updates and collect messages.
Process flow
- Implement BAdI
USMD_RULE_SERVICE_CROSS_ETusing interface IF_EX_USMD_RULE_SERVICE2. - Keep IF_EX_USMD_RULE_SERVICE2~DERIVE as the router and validate io_model, io_changed_data, and io_write_data are bound.
- Read the application context with CL_USMD_APP_CONTEXT=>GET_CONTEXT( ) and get CR attributes.
- Route by mv_process: SUP1/SUP2 for supplier logic, CUP1/CUP2 for customer logic.
- Read BU_GROUP and KTOKK with GET_SINGLE_ATTRIBUTE from BP_HEADER when needed.
- Call focused helper methods for each derivation branch.
- Write derived values only through io_write_data and collect messages in ET_MESSAGE_INFO.
- Preserve derivation order and make the logic idempotent to avoid duplicate rows.
Referenced tables
| Object | Purpose |
|---|---|
USMD1213 | Read change-request field values for BP_HEADER in the helper method GET_SINGLE_ATTRIBUTE. |
ILLUSTRATIVE ABAP SAMPLE
Source-supported cross-entity derivation router pattern
Adapt this pattern in your Z* implementation. It shows the orchestration structure used by the retrieved class: guards, context routing, helper calls, and message collection. Add your real buffer reads and write_data calls inside the helper methods.
1METHOD if_ex_usmd_rule_service2~derive.
2 DATA: lo_context TYPE REF TO if_usmd_app_context,
3 lv_crequest_id TYPE usmd_crequest,
4 lv_crequest_type TYPE usmd_crequest_type,
5 lv_crequest_step TYPE usmd_crequest_wfs,
6 lv_bu_group TYPE bu_group,
7 lv_acc_grp TYPE ktokk,
8 lt_msg TYPE usmd_t_message.
9
10 CLEAR et_message_info.
11
12 IF io_model IS NOT BOUND OR io_changed_data IS NOT BOUND OR io_write_data IS NOT BOUND.
13 RETURN.
14 ENDIF.
15
16 lo_context = cl_usmd_app_context=>get_context( ).
17 CHECK lo_context IS BOUND.
18
19 lo_context->get_attributes(
20 IMPORTING
21 ev_crequest_id = lv_crequest_id
22 ev_crequest_type = lv_crequest_type
23 ev_crequest_step = lv_crequest_step ).
24
25 IF lo_context->mv_process = 'SUP1' OR lo_context->mv_process = 'SUP2'.
26 lv_bu_group = get_single_attribute( iv_crequest_id = lv_crequest_id iv_field = 'BU_GROUP' ).
27 lv_acc_grp = get_single_attribute( iv_crequest_id = lv_crequest_id iv_field = 'KTOKK' ).
28
29 me->derive_suppl_budet(
30 EXPORTING
31 io_model = io_model
32 io_changed_data = io_changed_data
33 io_write_data = io_write_data
34 iv_crequest_type = lv_crequest_type
35 iv_crequest_id = lv_crequest_id
36 IMPORTING
37 et_message_info = lt_msg ).
38 INSERT LINES OF lt_msg INTO TABLE et_message_info.
39
40 me->derive_sup_defaults(
41 EXPORTING
42 io_model = io_model
43 io_changed_data = io_changed_data
44 io_write_data = io_write_data
45 iv_crequest_type = lv_crequest_type
46 iv_crequest_id = lv_crequest_id
47 iv_crequest_step = lv_crequest_step
48 iv_bu_group = lv_bu_group
49 id_acc_grp = lv_acc_grp
50 IMPORTING
51 et_message_info = lt_msg ).
52 INSERT LINES OF lt_msg INTO TABLE et_message_info.
53
54 me->derive_suppl_ad_email(
55 EXPORTING
56 io_model = io_model
57 io_changed_data = io_changed_data
58 io_write_data = io_write_data
59 iv_crequest_type = lv_crequest_type
60 iv_crequest_id = lv_crequest_id
61 iv_bu_group = lv_bu_group
62 IMPORTING
63 et_message_info = lt_msg ).
64 INSERT LINES OF lt_msg INTO TABLE et_message_info.
65
66 me->derive_suppl_zbp_msg(
67 EXPORTING
68 io_model = io_model
69 io_changed_data = io_changed_data
70 io_write_data = io_write_data
71 iv_crequest_type = lv_crequest_type
72 iv_crequest_id = lv_crequest_id
73 iv_bu_group = lv_bu_group
74 IMPORTING
75 et_message_info = lt_msg ).
76 INSERT LINES OF lt_msg INTO TABLE et_message_info.
77
78 IF lo_context->mv_process = 'SUP1'.
79 me->derive_suppl_roles(
80 EXPORTING
81 io_model = io_model
82 io_changed_data = io_changed_data
83 io_write_data = io_write_data
84 iv_crequest_type = lv_crequest_type
85 iv_crequest_id = lv_crequest_id
86 iv_bu_group = lv_bu_group
87 IMPORTING
88 et_message_info = lt_msg ).
89 INSERT LINES OF lt_msg INTO TABLE et_message_info.
90 ENDIF.
91
92 ELSEIF lo_context->mv_process = 'CUP1' OR lo_context->mv_process = 'CUP2'.
93 me->derive_cust_defaults(
94 EXPORTING
95 io_model = io_model
96 io_changed_data = io_changed_data
97 io_write_data = io_write_data
98 IMPORTING
99 et_message_info = lt_msg ).
100 INSERT LINES OF lt_msg INTO TABLE et_message_info.
101
102 me->derive_cust_roles(
103 EXPORTING
104 io_model = io_model
105 io_changed_data = io_changed_data
106 io_write_data = io_write_data
107 IMPORTING
108 et_message_info = lt_msg ).
109 INSERT LINES OF lt_msg INTO TABLE et_message_info.
110 ENDIF.
111ENDMETHOD.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How do I code IF_EX_USMD_RULE_SERVICE2~DERIVE for MDG cross-entity derivation?
- How do I derive supplier and customer child entities from BP data in SAP MDG?
- What is the implementation pattern for ZCL_MDGBP_BP_CROSS_DERIVATION?
Possible questions
- Which interface and method are used for
USMD_RULE_SERVICE_CROSS_ET? - What is the ABAP pattern for reading CR context and writing derived data in MDG?
- How do I route MDG derivation by process SUP1, SUP2, CUP1, and CUP2?
- How do I avoid duplicate rows and handle messages in cross-entity derivation?
- What helper methods are typically used in the BP cross-derivation class?