SAP MDG · VALIDATION DERIVATION

How do I implement SAP MDG BP company-code derivation in a BAdI or derivation hook?

Use the MDG derivation hook for BP company-code data to read the current change request context, inspect BP header and postal/address data, and then default company-code fields only when they are initial. The documented pattern derives reconciliation account, payment terms, sort key, tolerance group, check flag for double invoices, and MINDK based on account group, company code, and country context.

Use the MDG derivation hook for BP company-code data to read the current change request context, inspect BP header and postal/address data, and then default company-code fields only when they are initial. The documented pattern derives reconciliation account, payment terms, sort key, tolerance group, check flag for double invoices, and MINDK based on account group, company code, and country context.

The documented MDG BP company-code derivation pattern reads the current change request, loads BP header and address/postal context, and then populates only missing company-code fields in `CT_DATA`. It uses account-group and country logic to default reconciliation account, payment terms, sort key, tolerance group, double-invoice flag, and supplier code-related fields.

Process flow

  1. Open the MDG derivation or BAdI implementation for BP company-code processing.
  2. Read the current change request from `CL_USMD_APP_CONTEXT`.
  3. Load `BP_HEADER` and `AD_POSTAL` context data from the model.
  4. Determine company-code country from `T001-LAND1` and compare it with postal country.
  5. Read any customizing rows used for company-code defaults.
  6. Loop through `CT_DATA` and assign defaults only to initial fields.
  7. Activate the class and implementation, then test the CR scenario in MDG.

Referenced tables

ObjectPurpose
T001Provides company-code country (`LAND1`) for domestic versus foreign derivation logic.
ZMDG_SUP_CC_DERVCustomizing table used for company-code derivation rules such as reconciliation account and payment-related defaults.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example

Exact relevant implementation excerpt from the knowledge document.

1* Purpose: Interface hook for BP company-code derivation. 2 3 METHOD zif_te_derivation~d_bp_compny. 4 5 DATA:lt_filter TYPE usmd_t_entity, 6 wa_filter LIKE LINE OF lt_filter, 7* lo_data_ca_map TYPE REF TO zcl_fi_global_utility, 8 ls_ca_map TYPE zca_map, 9 lt_ca_map TYPE zca_map_tt, 10 lv_togru TYPE togru. 11 CONSTANTS: 12 lc_header TYPE usmd_fieldname VALUE 'BP_HEADER', 13 lc_togru TYPE char40 VALUE 'TOGRU'. 14 FIELD-SYMBOLS: <fs_t_data_ad_postal> TYPE ANY TABLE, 15 <fs_t_data_bp_header> TYPE ANY TABLE, 16 <fs_t_data> TYPE ANY TABLE, 17 <fs_data> TYPE any, 18 <fs_company> TYPE any, 19 <fs_authgrp> TYPE any, 20 <fs_sortkey> TYPE any, 21 <fs_tol_grp> TYPE any, 22 <fs_uzawe> TYPE any, 23 <fs_zahls> TYPE any, 24 <fs_val_adj> TYPE any. 25 26 27 DATA : 28 lv_partner TYPE bu_partner. 29 30 DATA(lo_context) = cl_usmd_app_context=>get_context( ). 31 CHECK lo_context IS BOUND. 32 33 lo_context->get_attributes( IMPORTING ev_crequest_id = DATA(lv_crequest_id) ). 34 35 cl_usmd_crequest_api=>get_instance( 36 EXPORTING 37 iv_crequest = lv_crequest_id 38 iv_model_name = zif_bp_constants=>data_model-bp " Data Model 39 IMPORTING 40 et_message = et_message " Messages 41 re_inst_crequest_api = DATA(lo_crequest) " Change Request API Interface 42 ). 43 lo_crequest->read_crequest( 44 IMPORTING 45 es_crequest = DATA(ls_crequest) " Change Request 46 ). 47 48 ASSIGN ct_data TO <fs_t_data>. 49 50* Get Header Details 51 wa_filter = zif_bp_constants=>entity_type-bp_header. 52 INSERT wa_filter INTO TABLE lt_filter. 53 io_model->read_entity_data_all( 54 EXPORTING 55 i_fieldname = lc_header 56 if_active = abap_false 57 i_crequest = ls_crequest-usmd_crequest 58 it_entity_filter = lt_filter 59 IMPORTING 60 et_message = DATA(lt_et_message) " Messages 61 et_data_entity = DATA(lt_data_bp_header) " Data for Entity Types 62 ). 63 DATA wa_data_bp_header LIKE LINE OF lt_data_bp_header. 64 IF lt_data_bp_header IS NOT INITIAL. 65 READ TABLE lt_data_bp_header INTO wa_data_bp_header WITH KEY usmd_entity = zif_bp_constants=>bp_header-bp_header. 66 IF sy-subrc EQ 0. 67 ASSIGN wa_data_bp_header-r_t_data->* TO <fs_t_data_bp_header>. 68 ENDIF. 69 ENDIF. 70 LOOP AT <fs_t_data_bp_header> ASSIGNING FIELD-SYMBOL(<fs_bp_header>). 71 ASSIGN COMPONENT zif_bp_constants=>bp_header-bu_group OF STRUCTURE <fs_bp_header> TO FIELD-SYMBOL(<fs_ktokk>). 72 ASSIGN COMPONENT zif_bp_constants=>bp_header-bp_header OF STRUCTURE <fs_bp_header> TO FIELD-SYMBOL(<fs_supplier>). 73 ENDLOOP. 74 75* Get Address Details 76 CLEAR: wa_filter, lt_filter. 77 wa_filter = zif_bp_constants=>entity_type-ad_postal. 78 INSERT wa_filter INTO TABLE lt_filter. 79 io_model->read_entity_data_all( 80 EXPORTING 81 i_fieldname = lc_header 82 if_active = abap_false 83 i_crequest = ls_crequest-usmd_crequest 84 it_entity_filter = lt_filter 85 IMPORTING 86 et_message = lt_et_message " Messages 87 et_data_entity = DATA(lt_data_ad_postal) " Data for Entity Types 88 ). 89 DATA wa_data_ad_postal LIKE LINE OF lt_data_ad_postal. 90 IF lt_data_ad_postal IS NOT INITIAL. 91 READ TABLE lt_data_ad_postal INTO wa_data_ad_postal WITH KEY usmd_entity = zif_bp_constants=>bp_centrl-bp_header. 92 IF sy-subrc EQ 0. 93 ASSIGN wa_data_ad_postal-r_t_data->* TO <fs_t_data_ad_postal>. 94 ENDIF. 95 ENDIF. 96 IF <fs_t_data_ad_postal> IS ASSIGNED AND <fs_t_data_ad_postal> IS NOT INITIAL."Kabil - To Fix the dump issue added not intial statement. 97 LOOP AT <fs_t_data_ad_postal> ASSIGNING FIELD-SYMBOL(<fs_ad_postal>). 98 ASSIGN COMPONENT zif_bp_constants=>ad_postal-ref_posta OF STRUCTURE <fs_ad_postal> TO FIELD-SYMBOL(<fs_ref_posta>). 99 ENDLOOP. 100 ENDIF. 101 102 CHECK <fs_t_data> IS NOT INITIAL." Kabil - To avoid the dump issue added not intial statement. 103 LOOP AT <fs_t_data> ASSIGNING <fs_data>. 104 ASSIGN COMPONENT zif_bp_constants=>bp_compny-company OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_comp>). 105 IF <fs_comp> IS ASSIGNED. 106 SELECT SINGLE land1 FROM t001 INTO @DATA(lv_comp_land1) WHERE bukrs = @<fs_comp>."#EC CI_SUBRC 107 IF lv_comp_land1 IS NOT INITIAL AND <fs_ref_posta> IS ASSIGNED AND lv_comp_land1 <> <fs_ref_posta>. 108 DATA(lv_foreign_vend) = 'F'. 109 ELSE. 110 lv_foreign_vend = 'D'. 111 ENDIF. 112 ASSIGN COMPONENT zif_bp_constants=>bp_compny-ref_bpcmp OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_recon>). 113 114 IF <fs_ktokk> IS ASSIGNED. 115 116 IF <fs_comp> IS ASSIGNED AND <fs_comp> IS NOT INITIAL AND <fs_ktokk> IS NOT INITIAL. 117 SELECT * INTO TABLE @DATA(lt_comp_derive) 118 FROM zmdg_sup_cc_derv 119 WHERE 120 ( foreign_vend = @lv_foreign_vend OR foreign_vend = 'A' ) AND

The remaining configuration, implementation details, and testing guidance continue from this answer more…

Related questions and keywords

Alternative questions

  • How is BP company-code defaulting implemented in SAP MDG?
  • How do I derive reconciliation account, payment terms, sort key, and tolerance group in MDG BP company data?
  • What is the ABAP pattern for BP company-code derivation in MDG?

Possible questions

  • Which fields are derived in BP company-code derivation?
  • Which context data is read before company-code derivation?
  • How do I avoid dumps in dynamic field assignment during MDG derivation?
  • Which SAP MDG hook is used for BP company-code defaulting?
  • How do I implement the rule-service BAdI for MDG derivation?

Keywords

SAP MDGBusiness PartnerBP company-codederivationdefaultingUSMD_RULE_SERVICEIF_EX_USMD_RULE_SERVICEZIF_TE_DERIVATIOND_BP_COMPNYCL_USMD_APP_CONTEXTCL_USMD_CREQUEST_APICT_DATAreconciliation accountpayment termssort keytolerance group