SAP MDG · VALIDATION DERIVATION

How do I auto-derive business partner company-code defaults in SAP MDG during rule-service derivation?

Implement the derivation in IF_EX_USMD_RULE_SERVICE2~DERIVE, read the BP governance context and changed entity data, build the BP company-code row only when the business process matches, and write it back with IO_WRITE_DATA. The provided pattern derives company, reconciliation account, payment terms, sort key, tolerance group, and related fields from BP_HEADER, AD_POSTAL, ZBP_BUDET, and ZBP_SUPPL.

Implement the derivation in IF_EX_USMD_RULE_SERVICE2~DERIVE, read the BP governance context and changed entity data, build the BP company-code row only when the business process matches, and write it back with IO_WRITE_DATA. The provided pattern derives company, reconciliation account, payment terms, sort key, tolerance group, and related fields from BP_HEADER, AD_POSTAL, ZBP_BUDET, and ZBP_SUPPL.

Implement company-code defaulting in the MDG rule-service derivation method, not as a hard-coded update. The source pattern first resolves the current change request and process from CL_USMD_APP_CONTEXT, reads BP_HEADER and related child entities from the governance buffer, then fills BP_COMPNY fields such as company, reconciliation account, payment terms, sort key, tolerance group, and double-invoice flag before writing the result back through the MDG write API.

Process flow

  1. Open the MDG rule-service BAdI in SE18 and SE19.
  2. Implement IF_EX_USMD_RULE_SERVICE2~DERIVE in the BAdI class.
  3. Read CL_USMD_APP_CONTEXT to get CR, step, and process.
  4. Read BP_HEADER and related entity buffers from the MDG model.
  5. Derive BP_COMPNY fields only when the business rule applies.
  6. Write the result back with IO_WRITE_DATA.
  7. Catch CX_USMD_WRITE_ERROR and prevent duplicate row generation.
  8. Retest all impacted CR types and supplier scenarios.

Referenced tables

ObjectPurpose
T001Used to read the company-code country (LAND1) for foreign/domestic comparison.
ZMDG_SUP_CC_DERVCustom company-code derivation customizing used to derive reconciliation account and payment-method defaults.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example

Exact relevant implementation excerpt from the knowledge document.

1* Purpose: Auto-derive company code defaults from BP change data and MDG governance context. 2 3METHOD auto_derive_company_code. 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_zbpsuppl TYPE usmd_entity VALUE 'ZBP_SUPPL', 14 lc_venval TYPE usmd_entity VALUE 'BP_VENVAL', 15 lc_vencla TYPE usmd_entity VALUE 'BP_VENCLA', 16 lc_address TYPE usmd_entity VALUE 'ADDRESS', 17 lc_togru TYPE char40 VALUE 'TOGRU'. 18 19 DATA: 20 lo_app_context TYPE REF TO if_usmd_app_context, 21 lo_data_r TYPE REF TO data, 22 lv_crequest TYPE usmd_crequest, 23 lt_data_entity TYPE usmd_ts_data_entity, 24 ls_data_entity TYPE usmd_sx_data_entity, 25 ls_bpheader TYPE /mdgbp/_s_bp_es_bp_header, 26 lt_bpcompny TYPE STANDARD TABLE OF /mdgbpx/_s_bp_es_bp_compny, 27 ls_bpcompny TYPE /mdgbpx/_s_bp_es_bp_compny, 28 lt_bpporg TYPE STANDARD TABLE OF /mdgbpx/_s_bp_es_bp_porg, 29 lt_bpporg1 TYPE STANDARD TABLE OF /mdgbpx/_s_bp_es_bp_porg, 30 lt_centrl TYPE STANDARD TABLE OF /mdgbpx/_s_bp_es_bp_centrl, 31 ls_centrl TYPE /mdgbpx/_s_bp_es_bp_centrl, 32 ls_bpporg TYPE /mdgbpx/_s_bp_es_bp_porg, 33 ls_bpporg1 TYPE /mdgbpx/_s_bp_es_bp_porg, 34 ls_bpporg2 TYPE /mdgbpx/_s_bp_es_bp_porg, 35 lt_adpostal TYPE STANDARD TABLE OF /mdgbp/_s_bp_pp_ad_postal, 36 ls_adpostal TYPE /mdgbp/_s_bp_pp_ad_postal, 37 lt_identity TYPE STANDARD TABLE OF /mdgbp/_s_bp_es_bp_idnum, 38 ls_identity TYPE /mdgbp/_s_bp_es_bp_idnum, 39 ls_bp_centrl TYPE /mdgbp/_s_bp_pp_bp_centrl, 40 lt_bp_centrl LIKE TABLE OF ls_bp_centrl, 41 ls_bp_vengen TYPE /mdgbpx/_s_bp_pp_bp_vengen, 42 lt_bp_vengen LIKE TABLE OF ls_bp_vengen, 43 ls_bp_porg TYPE /mdgbpx/_s_bp_pp_bp_porg, 44 lt_bp_porg LIKE TABLE OF ls_bp_porg, 45 lt_ztecustom TYPE STANDARD TABLE OF zmdgbp_s_bp_pp_zbp_budet, 46 ls_ztecustom TYPE zmdgbp_s_bp_pp_zbp_budet, 47 lt_zbp_suppl TYPE STANDARD TABLE OF zmdgbp_s_bp_pp_zbp_suppl, 48 ls_zbp_suppl TYPE zmdgbp_s_bp_pp_zbp_suppl, 49 lt_bpvenval TYPE STANDARD TABLE OF /mdgbpx/_s_bp_es_bp_venval, 50 ls_bpvenval TYPE /mdgbpx/_s_bp_es_bp_venval, 51 lt_bpvencla TYPE STANDARD TABLE OF /mdgbpx/_s_bp_es_bp_vencla, 52 ls_bpvencla TYPE /mdgbpx/_s_bp_es_bp_vencla, 53 lt_address TYPE STANDARD TABLE OF /mdgbp/_s_bp_es_address, 54 ls_address TYPE /mdgbp/_s_bp_es_address, 55 lo_att_data TYPE REF TO data, 56 lo_singleton TYPE REF TO zcl_mdg_singleton, 57 lo_att TYPE REF TO cl_abap_structdescr, 58* lo_data_ca_map TYPE REF TO zcl_fi_global_utility, 59 ls_ca_map TYPE zca_map, 60 lt_ca_map TYPE zca_map_tt, 61 lr_write_error TYPE REF TO cx_usmd_write_error, 62 lt_attribute TYPE usmd_ts_fieldname, 63 lv_ekorg TYPE ekorg, 64 lv_atinn_char TYPE string, 65 lv_togru TYPE togru. 66 67 FIELD-SYMBOLS: <fs_lt_data> TYPE SORTED TABLE, 68 <fs_ls_data> TYPE any, 69 <fs_component> TYPE abap_compdescr. 70*================================================* 71 lo_app_context = cl_usmd_app_context=>get_context( ). 72 CHECK lo_app_context IS BOUND. 73 lv_crequest = lo_app_context->mv_crequest_id. 74 DATA(lv_crtype) = lo_app_context->mv_crequest_type. 75 DATA(lv_step) = lo_app_context->mv_crequest_step. 76 DATA(lv_busact) = lo_app_context->mv_process. 77 78 CHECK lv_busact = 'SUP1'. 79 CALL METHOD zcl_mdg_suppl_utility=>get_single_attribute 80 EXPORTING 81 im_crnumber = i_io_crnumber 82 im_field = 'COMPANY' 83 IMPORTING 84* ex_value = 85 ct_value = DATA(lt_bukrs). 86 87 i_io_model->read_entity_data_all( EXPORTING i_fieldname = 'BP_HEADER' 88 if_active = abap_false 89 i_crequest = lv_crequest 90 IMPORTING et_data_entity = lt_data_entity ). 91 CHECK lt_data_entity IS NOT INITIAL. 92 READ TABLE lt_data_entity INTO ls_data_entity WITH KEY usmd_entity = lc_headr 93 usmd_entity_cont = space 94 struct = 'KATTR'. 95 IF sy-subrc = 0. 96 CLEAR lo_data_r. 97 lo_data_r = ls_data_entity-r_t_data. 98 ASSIGN lo_data_r->* TO <fs_lt_data>. 99 LOOP AT <fs_lt_data> ASSIGNING <fs_ls_data>. 100 ASSIGN COMPONENT 'BU_GROUP' OF STRUCTURE <fs_ls_data> TO FIELD-SYMBOL(<fs_bu_group>). 101 IF <fs_bu_group> IS ASSIGNED AND <fs_bu_group> IS NOT INITIAL. 102 ASSIGN COMPONENT 'BU_TYPE' OF STRUCTURE <fs_ls_data> TO FIELD-SYMBOL(<fs_bu_type>). 103* IF <fs_bu_type> IS ASSIGNED. 104 IF sy-subrc IS INITIAL AND <fs_bu_type> IS ASSIGNED AND <fs_bu_type> = '2'. 105 MOVE-CORRESPONDING <fs_ls_data> TO ls_bpheader. 106 ENDIF. 107 ENDIF. 108 ENDLOOP. 109 ENDIF. 110* IF ls_bpheader-bu_group IS NOT INITIAL. 111*Read Centrl Data 112 READ TABLE lt_data_entity INTO ls_data_entity WITH KEY usmd_entity = lc_headr 113 usmd_entity_cont = lc_centrl. 114 115 IF sy-subrc = 0. 116 CLEAR lo_data_r. 117 lo_data_r = ls_data_entity-r_t_data. 118 ASSIGN lo_data_r->* TO <fs_lt_data>. 119 LOOP AT <fs_lt_data> ASSIGNING <fs_ls_data>. 120 MOVE-CORRESPONDING <fs_ls_data> TO ls_bp_centrl.

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

Related questions and keywords

Alternative questions

  • How can I implement company-code defaulting for BP company data in MDG?
  • How do I derive BP_COMPNY values automatically from BP change data?
  • What is the ABAP pattern for defaulting company code in USMD_RULE_SERVICE2~DERIVE?

Possible questions

  • How do I auto-derive BP company-code defaults in SAP MDG?
  • What is the implementation pattern for deriving BP company data from BP_HEADER and related entities?
  • How do I write an MDG derivation exit for BP company-code default values?
  • Which BAdI method should I use for MDG derivation of company-code fields?
  • How do I debug automatic derivation of BP_COMPNY in MDG?

Keywords

SAP MDGABAPUSMD_RULE_SERVICE2DERIVEBP_COMPNYBP_HEADERcompany codedefaultingcross-entity derivationMDG Business Partner