SAP MDG · VALIDATION DERIVATION
How do I implement BP purchasing-org derivation in SAP MDG using the rule-service BAdI?
Implement the rule-service BAdI for BP purchasing-org derivation by reading the current change request context, loading BP header and company-code data, mapping company ZTERM to purchasing org via T024E, and defaulting BSTAE to 0001 for selected account groups when initial.
Implement the rule-service BAdI for BP purchasing-org derivation by reading the current change request context, loading BP header and company-code data, mapping company ZTERM to purchasing org via T024E, and defaulting BSTAE to 0001 for selected account groups when initial.
Use the MDG rule-service BAdI for the BP purchasing-org entity and keep the method focused on defaulting, not hard validation. The source pattern shows the method reading change-request context, pulling `BP_HEADER` and `BP_COMPNY` data, then deriving purchasing-org fields from the company-code terms and account-group rules. Below is the implementation flow, the relevant SAP objects, and a copyable ABAP pattern you can adapt.
Process flow
- Open SE18 and identify the BAdI definition and interface.
- Create or change the implementation in SE19 and assign the Z* class.
- Implement the BP purchasing-org derivation method.
- Read BP header and company-code entity data from the current change request.
- Map company-code ZTERM to purchasing-org ZTERM_M via T024E.
- Default BSTAE to 0001 for the specified account groups when initial.
- Activate the class and BAdI implementation.
- Debug with breakpoints and verify the entity data and mapping results.
Referenced tables
| Object | Purpose |
|---|---|
T024E | Maps purchasing organization (EKORG) to company code (BUKRS) for ZTERM derivation. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1* Purpose: Interface hook for BP purchasing-org derivation.
2
3 METHOD zif_te_derivation~d_bp_porg.
4*$*$------------------------------------------------------------------*
5*&D MDG BP Derivation
6*$*$------------------------------------------------------------------*
7*&A Start CHANGE HISTORY
8*$*$------------------------------------------------------------------*
9*&A Date |TA-No. | Programmer (Initials)
10*$*$------------------------------------------------------------------*
11*&A 11.08.2026| RITM1885029 | Confirmation Control Key as default set to 0001
12*$*$------------------------------------------------------------------*
13
14 DATA:lt_filter TYPE usmd_t_entity,
15 wa_filter LIKE LINE OF lt_filter.
16
17 CONSTANTS: lc_header TYPE usmd_fieldname VALUE 'BP_HEADER'.
18
19 FIELD-SYMBOLS: <fs_t_data_bp_header> TYPE ANY TABLE,
20 <fs_t_data_bp_compny> TYPE ANY TABLE,
21 <fs_t_data> TYPE ANY TABLE,
22 <fs_data> TYPE any.
23
24 DATA(lo_context) = cl_usmd_app_context=>get_context( ).
25 CHECK lo_context IS BOUND.
26
27 lo_context->get_attributes( IMPORTING ev_crequest_id = DATA(lv_crequest_id) ).
28
29 cl_usmd_crequest_api=>get_instance(
30 EXPORTING
31 iv_crequest = lv_crequest_id
32 iv_model_name = zif_bp_constants=>data_model-bp " Data Model
33 IMPORTING
34 et_message = et_message " Messages
35 re_inst_crequest_api = DATA(lo_crequest) " Change Request API Interface
36 ).
37 lo_crequest->read_crequest(
38 IMPORTING
39 es_crequest = DATA(ls_crequest) " Change Request
40 ).
41
42 ASSIGN ct_data TO <fs_t_data>.
43
44* Get Header Details
45 wa_filter = zif_bp_constants=>entity_type-bp_header.
46 INSERT wa_filter INTO TABLE lt_filter.
47 io_model->read_entity_data_all(
48 EXPORTING
49 i_fieldname = lc_header
50 if_active = abap_false
51 i_crequest = ls_crequest-usmd_crequest
52 it_entity_filter = lt_filter
53 IMPORTING
54 et_message = DATA(lt_et_message) " Messages
55 et_data_entity = DATA(lt_data_bp_header) " Data for Entity Types
56 ).
57 DATA wa_data_bp_header LIKE LINE OF lt_data_bp_header.
58 IF lt_data_bp_header IS NOT INITIAL.
59 READ TABLE lt_data_bp_header INTO wa_data_bp_header WITH KEY usmd_entity = zif_bp_constants=>bp_header-bp_header.
60 IF sy-subrc EQ 0.
61 ASSIGN wa_data_bp_header-r_t_data->* TO <fs_t_data_bp_header>.
62 ENDIF.
63 ENDIF.
64 IF <fs_t_data_bp_header> IS ASSIGNED.
65 LOOP AT <fs_t_data_bp_header> ASSIGNING FIELD-SYMBOL(<fs_bp_header>).
66 ASSIGN COMPONENT zif_bp_constants=>bp_header-bu_group OF STRUCTURE <fs_bp_header> TO FIELD-SYMBOL(<fs_ktokk>).
67 ENDLOOP.
68 ENDIF.
69
70* Get Company Code Details
71 CLEAR: wa_filter, lt_filter.
72 wa_filter = zif_bp_constants=>entity_type-bp_compny.
73 INSERT wa_filter INTO TABLE lt_filter.
74 io_model->read_entity_data_all(
75 EXPORTING
76 i_fieldname = lc_header
77 if_active = abap_false
78 i_crequest = ls_crequest-usmd_crequest
79 it_entity_filter = lt_filter
80 IMPORTING
81 et_message = lt_et_message " Messages
82et_data_entity = DATA(lt_data_bp_compny) " Data for Entity Types
83 ).
84 DATA wa_data_bp_compny LIKE LINE OF lt_data_bp_compny.
85 IF lt_data_bp_compny IS NOT INITIAL.
86 READ TABLE lt_data_bp_compny INTO wa_data_bp_compny WITH KEY usmd_entity = zif_bp_constants=>bp_centrl-bp_header.
87 IF sy-subrc EQ 0.
88 ASSIGN wa_data_bp_compny-r_t_data->* TO <fs_t_data_bp_compny>.
89 ENDIF.
90 ENDIF.
91
92 "new code######
93 TYPES: BEGIN OF ty_cc_zterm,
94 bukrs TYPE bukrs,
95 zterm TYPE dzterm,
96 END OF ty_cc_zterm.
97
98 DATA: lt_cc_zterm TYPE TABLE OF ty_cc_zterm,
99 ls_cc_zterm LIKE LINE OF lt_cc_zterm.
100 "#############
101
102 IF <fs_t_data_bp_compny> IS ASSIGNED.
103 LOOP AT <fs_t_data_bp_compny> ASSIGNING FIELD-SYMBOL(<fs_bp_compny>).
104 CLEAR ls_cc_zterm.
105 ASSIGN COMPONENT zif_bp_constants=>bp_compny-zterm OF STRUCTURE <fs_bp_compny> TO FIELD-SYMBOL(<fs_zterm>).
106 "newcode########
107 ASSIGN COMPONENT zif_bp_constants=>bp_compny-company OF STRUCTURE <fs_bp_compny> TO FIELD-SYMBOL(<fs_company>).
108 ls_cc_zterm-bukrs = <fs_company>.
109 ls_cc_zterm-zterm = <fs_zterm>.
110 APPEND ls_cc_zterm TO lt_cc_zterm.
111 "###############
112 ENDLOOP.
113 ENDIF.
114 "newcode##########
115 DATA: lv_porg TYPE ekorg.
116 "#################
117 LOOP AT <fs_t_data> ASSIGNING <fs_data>.
118 ASSIGN COMPONENT zif_bp_constants=>bp_porg-prch_org OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_porg>).
119 IF <fs_porg> IS ASSIGNED AND <fs_ktokk> IS ASSIGNED.
120 CASE <fs_ktokk>.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How do I default purchasing organization fields during BP derivation?
- How can I derive ZTERM_M and BSTAE for BP purchasing-org data in MDG?
- What is the implementation pattern for purchasing-org derivation in IF_EX_USMD_RULE_SERVICE?
Possible questions
- How do I default purchasing terms from company code during BP purchasing-org derivation?
- How do I set confirmation control key BSTAE = '0001' for selected BP account groups?
- How do I read BP_HEADER and BP_COMPNY data inside a derivation method?
- Which fields are typically derived in BP purchasing-org derivation?
- How do I create the BAdI implementation from SE18/SE19?