SAP MDG · VALIDATION DERIVATION
How do I implement vendor address default derivation in SAP MDG using `IF_EX_USMD_RULE_SERVICE2~DERIVE`?
Use `IF_EX_USMD_RULE_SERVICE2~DERIVE` to read the current change request context, inspect `BP_HEADER`, generate a new address number, fill `AD_POSTAL`, and write it back through the MDG write API. The source pattern also sets a singleton address flag after a successful write.
Use `IF_EX_USMD_RULE_SERVICE2~DERIVE` to read the current change request context, inspect `BP_HEADER`, generate a new address number, fill `AD_POSTAL`, and write it back through the MDG write API. The source pattern also sets a singleton address flag after a successful write.
Use the MDG rule-service derivation hook to default vendor address data from the current BP change request context. The provided pattern reads `BP_HEADER`, creates a new address number, fills `AD_POSTAL` with `addrno`, `bp_header`, and language, then writes the governed data back to the `AD_POSTAL` entity.
Process flow
- Get the MDG application context with `cl_usmd_app_context=>get_context( )`.
- Read `BP_HEADER` from the current change request using `i_io_model->read_entity_data_all`.
- Map the generic data to `/mdgbp/_s_bp_es_bp_header` and verify it is not initial.
- Call `NUMBER_GET_NEXT` for object `ADRNR` and interval `01`.
- Populate `AD_POSTAL` fields such as `addrno`, `bp_header`, and `langu_com`.
- Write the data back using `i_io_write_data->write_data` for entity `AD_POSTAL`.
- Set `zcl_mdg_singleton=>create_instance( )->gc_addr_flag = abap_true` after a successful write.
Referenced tables
| Object | Purpose |
|---|---|
USMD_ENTITY | Entity identifier values used in the derivation flow such as `BP_HEADER` and `AD_POSTAL`. |
USMD_TS_DATA_ENTITY | Container structure returned by `read_entity_data_all` for entity-level data reads. |
USMD_SX_DATA_ENTITY | Single entity data wrapper used to access the returned generic data reference. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1* Purpose: Derive vendor address defaults and apply governed field updates.
2
3 METHOD derive_vendor_address.
4 CONSTANTS:
5 lc_headr TYPE usmd_entity VALUE 'BP_HEADER',
6 lc_centrl TYPE usmd_entity VALUE 'BP_CENTRL',
7 lc_compny TYPE usmd_entity VALUE 'BP_COMPNY',
8 lc_bpporg TYPE usmd_entity VALUE 'BP_PORG',
9 lc_postal TYPE usmd_entity VALUE 'AD_POSTAL',
10 lc_vengen TYPE usmd_entity VALUE 'BP_VENGEN',
11 lc_identity TYPE usmd_entity VALUE 'BP_IDNUM',
12 lc_ztecus TYPE usmd_entity VALUE 'ZBP_BUDET',
13 lc_venval TYPE usmd_entity VALUE 'BP_VENVAL',
14 lc_vencla TYPE usmd_entity VALUE 'BP_VENCLA',
15 lc_address TYPE usmd_entity VALUE 'ADDRESS',
16 lc_togru TYPE char40 VALUE 'TOGRU'.
17
18 DATA:
19 lo_app_context TYPE REF TO if_usmd_app_context,
20 lo_data_r TYPE REF TO data,
21 lv_crequest TYPE usmd_crequest,
22 lt_data_entity TYPE usmd_ts_data_entity,
23 ls_data_entity TYPE usmd_sx_data_entity,
24 ls_bpheader TYPE /mdgbp/_s_bp_es_bp_header,
25 lt_bpcompny TYPE STANDARD TABLE OF /mdgbpx/_s_bp_es_bp_compny,
26 ls_bpcompny TYPE /mdgbpx/_s_bp_es_bp_compny,
27 lt_bpporg TYPE STANDARD TABLE OF /mdgbpx/_s_bp_es_bp_porg,
28 lt_bpporg1 TYPE STANDARD TABLE OF /mdgbpx/_s_bp_es_bp_porg,
29 lt_centrl TYPE STANDARD TABLE OF /mdgbpx/_s_bp_es_bp_centrl,
30 ls_centrl TYPE /mdgbpx/_s_bp_es_bp_centrl,
31 ls_bpporg TYPE /mdgbpx/_s_bp_es_bp_porg,
32 ls_bpporg1 TYPE /mdgbpx/_s_bp_es_bp_porg,
33 ls_bpporg2 TYPE /mdgbpx/_s_bp_es_bp_porg,
34 lt_adpostal TYPE STANDARD TABLE OF /mdgbp/_s_bp_pp_ad_postal,
35 ls_adpostal TYPE /mdgbp/_s_bp_pp_ad_postal,
36 lt_identity TYPE STANDARD TABLE OF /mdgbp/_s_bp_es_bp_idnum,
37 ls_identity TYPE /mdgbp/_s_bp_es_bp_idnum,
38 ls_bp_centrl TYPE /mdgbp/_s_bp_pp_bp_centrl,
39 lt_bp_centrl LIKE TABLE OF ls_bp_centrl,
40 ls_bp_vengen TYPE /mdgbpx/_s_bp_pp_bp_vengen,
41 lt_bp_vengen LIKE TABLE OF ls_bp_vengen,
42 ls_bp_porg TYPE /mdgbpx/_s_bp_pp_bp_porg,
43 lt_bp_porg LIKE TABLE OF ls_bp_porg,
44 lt_ztecustom TYPE STANDARD TABLE OF zmdgbp_s_bp_pp_zbp_budet,
45 ls_ztecustom TYPE zmdgbp_s_bp_pp_zbp_budet,
46 lt_bpvenval TYPE STANDARD TABLE OF /mdgbpx/_s_bp_es_bp_venval,
47 ls_bpvenval TYPE /mdgbpx/_s_bp_es_bp_venval,
48 lt_bpvencla TYPE STANDARD TABLE OF /mdgbpx/_s_bp_es_bp_vencla,
49 ls_bpvencla TYPE /mdgbpx/_s_bp_es_bp_vencla,
50 lt_address TYPE STANDARD TABLE OF /mdgbp/_s_bp_es_address,
51 ls_address TYPE /mdgbp/_s_bp_es_address,
52 lo_att_data TYPE REF TO data,
53 lo_att TYPE REF TO cl_abap_structdescr,
54 lo_singleton TYPE REF TO zcl_mdg_singleton,
55* lo_data_ca_map TYPE REF TO zcl_fi_global_utility,
56 ls_ca_map TYPE zca_map,
57 lt_ca_map TYPE zca_map_tt,
58 lr_write_error TYPE REF TO cx_usmd_write_error,
59 lt_attribute TYPE usmd_ts_fieldname,
60 lv_ekorg TYPE ekorg,
61 lv_atinn_char TYPE string,
62 lv_number TYPE ad_addrnum,
63 lv_togru TYPE togru.
64
65 FIELD-SYMBOLS: <fs_lt_data> TYPE SORTED TABLE,
66 <fs_ls_data> TYPE any,
67 <fs_component> TYPE abap_compdescr.
68*================================================*
69 lo_app_context = cl_usmd_app_context=>get_context( ).
70 CHECK lo_app_context IS BOUND.
71 lv_crequest = lo_app_context->mv_crequest_id.
72 DATA(lv_crtype) = lo_app_context->mv_crequest_type.
73 DATA(lv_step) = lo_app_context->mv_crequest_step.
74
75 i_io_model->read_entity_data_all( EXPORTING i_fieldname = 'BP_HEADER'
76 if_active = abap_false
77 i_crequest = lv_crequest
78 IMPORTING et_data_entity = lt_data_entity ).
79 CHECK lt_data_entity IS NOT INITIAL.
80 READ TABLE lt_data_entity INTO ls_data_entity WITH KEY usmd_entity = lc_headr
81 usmd_entity_cont = space
82 struct = 'KATTR'.
83 IF sy-subrc = 0.
84 CLEAR lo_data_r.
85 lo_data_r = ls_data_entity-r_t_data.
86 ASSIGN lo_data_r->* TO <fs_lt_data>.
87 LOOP AT <fs_lt_data> ASSIGNING <fs_ls_data>.
88 ASSIGN COMPONENT 'BU_TYPE' OF STRUCTURE <fs_ls_data> TO FIELD-SYMBOL(<fs_bu_type>).
89 IF <fs_bu_type> IS ASSIGNED.
90 MOVE-CORRESPONDING <fs_ls_data> TO ls_bpheader.
91 ENDIF.
92 ENDLOOP.
93 ENDIF.
94 IF ls_bpheader IS NOT INITIAL.
95*Read Centrl Data
96* READ TABLE lt_data_entity INTO ls_data_entity WITH KEY usmd_entity = lc_headr
97* usmd_entity_cont = lc_centrl.
98*
99* IF sy-subrc = 0.
100* CLEAR lo_data_r.
101* lo_data_r = ls_data_entity-r_t_data.
102* ASSIGN lo_data_r->* TO <fs_lt_data>.
103* LOOP AT <fs_lt_data> ASSIGNING <fs_ls_data>.
104* MOVE-CORRESPONDING <fs_ls_data> TO ls_bp_centrl.
105* APPEND ls_bp_centrl TO lt_bp_centrl.
106* ENDLOOP.
107* ENDIF.
108
109* READ TABLE lt_data_entity INTO ls_data_entity WITH KEY usmd_entity = lc_headr
110* usmd_entity_cont = lc_vengen.
111* IF sy-subrc = 0.
112* CLEAR lo_data_r.
113* lo_data_r = ls_data_entity-r_t_data.
114* ASSIGN lo_data_r->* TO <fs_lt_data>.
115* LOOP AT <fs_lt_data> ASSIGNING <fs_ls_data>.
116* MOVE-CORRESPONDING <fs_ls_data> TO ls_bp_vengen.
117* APPEND ls_bp_vengen TO lt_bp_vengen.
118* CLEAR: ls_bp_vengen.
119* ENDLOOP.
120* ENDIF.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How can I default vendor address data in SAP MDG Business Partner processing?
- How do I write governed vendor address derivation logic for MDG BP?
- What is the ABAP pattern for deriving `AD_POSTAL` data from BP context in MDG?
Possible questions
- How do I configure and implement vendor address derivation in SAP MDG?
- Which BAdI method should I use for MDG vendor address defaulting?
- How do I read BP header data and write address defaults in MDG?
- How do I populate `AD_POSTAL` during vendor master derivation?
- What is the sample ABAP pattern for `DERIVE_VENDOR_ADDRESS`?