SAP MDG · VALIDATION DERIVATION
How do I implement SAP MDG derivation for BP company-code data in DERIVE_ENTITY or a BAdI method?
Use the MDG rule-service derivation pattern: resolve the change request context once, assign and loop CT_DATA safely, read BP_HEADER and AD_POSTAL context, and populate only initial company-code fields such as REF_BPCMP, ZTERM, ZUAWA, REPRF, and MINDK.
Use the MDG rule-service derivation pattern: resolve the change request context once, assign and loop CT_DATA safely, read BP_HEADER and AD_POSTAL context, and populate only initial company-code fields such as REF_BPCMP, ZTERM, ZUAWA, REPRF, and MINDK.
Use the MDG derivation pattern, not hard validation: resolve the CR context once, bind `CT_DATA`, then derive BP company-code defaults only when target fields are initial. In the documented company-code pattern, the logic reads BP_HEADER and AD_POSTAL context and then populates fields such as `REF_BPCMP`, `ZTERM`, `ZUAWA`, `ZWELS`, `REPRF`, and `MINDK` with context-driven defaults.
Process flow
- Open `SE18` and display the BAdI definition `
USMD_RULE_SERVICE` to confirm the interface and method intent. - Create the implementation in `SE19`, assign the package and transport, and maintain any required filters.
- Assign or create the implementing class and ensure `IF_EX_USMD_RULE_SERVICE` is implemented.
- Implement `DERIVE_ENTITY` for defaulting and enrichment; keep blocking checks in `CHECK_ENTITY`.
- Read `CL_USMD_APP_CONTEXT` once, get the current change request, and assign `CT_DATA` to a field symbol.
- If needed, read BP_HEADER and AD_POSTAL context using the MDG model API so the derivation can use grouping and country data.
- Loop through `CT_DATA`, dynamically assign the target fields, and set only fields that are initial.
- For `MINDK`, read the CR-level supplier code `ZSUPDCODE`, convert it to upper case, and assign it when initial.
Referenced tables
| Object | Purpose |
|---|---|
ZMDG_SUP_CC_DERV | Customizing table referenced in the derivation knowledge for company-code defaults by business conditions such as company, grouping, and domestic/foreign context. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1" Annotated pattern from ZCL_MDGBP_BP_DEFAULTS=>D_BP_COMPNY
2METHOD zif_te_derivation~d_bp_compny.
3 " 1) Resolve context and bind CT_DATA
4 DATA(lo_context) = cl_usmd_app_context=>get_context( ).
5 CHECK lo_context IS BOUND.
6
7 lo_context->get_attributes( IMPORTING ev_crequest_id = DATA(lv_crequest_id) ).
8 ASSIGN ct_data TO FIELD-SYMBOL(<fs_t_data>).
9 CHECK <fs_t_data> IS ASSIGNED AND <fs_t_data> IS NOT INITIAL.
10
11 " 2) Read BP_HEADER and AD_POSTAL for grouping/country context
12 " This context drives account/payment derivation decisions.
13 " (Read_entity_data_all calls omitted here for brevity.)
14
15 " 3) Loop rows and derive defaults
16 LOOP AT <fs_t_data> ASSIGNING FIELD-SYMBOL(<fs_data>).
17 ASSIGN COMPONENT 'COMPANY' OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_comp>).
18 ASSIGN COMPONENT 'REF_BPCMP' OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_recon>).
19 ASSIGN COMPONENT 'ZTERM' OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_zterm>).
20 ASSIGN COMPONENT 'ZUAWA' OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_sort_key>).
21 ASSIGN COMPONENT 'ZWELS' OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_zwels>).
22 ASSIGN COMPONENT 'REPRF' OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_reprf>).
23 ASSIGN COMPONENT 'MINDK' OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_mindk>).
24
25 " 3a) Reconciliation account by account group and company context
26 IF <fs_recon> IS ASSIGNED AND <fs_recon> IS INITIAL.
27 <fs_recon> = 'DERIVED_FROM_CUSTOMIZING_OR_RULE'.
28 ENDIF.
29
30 " 3b) Terms/sort key defaults
31 IF <fs_zterm> IS ASSIGNED AND <fs_zterm> IS INITIAL.
32 <fs_zterm> = 'J002'.
33 ENDIF.
34 IF <fs_sort_key> IS ASSIGNED AND <fs_sort_key> IS INITIAL.
35 <fs_sort_key> = '009'.
36 ENDIF.
37
38 " 3c) Boolean and code defaults
39 IF <fs_reprf> IS ASSIGNED AND <fs_reprf> IS INITIAL.
40 <fs_reprf> = abap_true.
41 ENDIF.
42
43 " 3d) Derive MINDK from CR-level supplier code
44 IF <fs_mindk> IS ASSIGNED AND <fs_mindk> IS INITIAL.
45 zcl_mdg_suppl_utility=>get_single_attribute(
46 EXPORTING im_crnumber = lv_crequest_id im_field = 'ZSUPDCODE'
47 IMPORTING ex_value = DATA(lv_supdcode) ).
48 IF lv_supdcode IS NOT INITIAL.
49 TRANSLATE lv_supdcode TO UPPER CASE.
50 <fs_mindk> = lv_supdcode.
51 ENDIF.
52 ENDIF.
53 ENDLOOP.
54ENDMETHOD.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How do I default BP company-code fields in SAP MDG?
- How do I implement
USMD_RULE_SERVICEfor BP company-code derivation? - How do I derive REF_BPCMP, ZTERM, ZUAWA, REPRF, and MINDK in MDG BP company data?
Possible questions
- How do I implement SAP MDG derivation for BP company-code data in DERIVE_ENTITY or a BAdI method?
- How do I default BP company-code fields in SAP MDG?
- How do I implement
USMD_RULE_SERVICEfor BP company-code derivation? - How do I derive REF_BPCMP, ZTERM, ZUAWA, REPRF, and MINDK in MDG BP company data?
- What is the recommended pattern for BP company derivation in MDG?