SAP MDG · VALIDATION DERIVATION

How do I auto-derive purchasing organization fields from the BP change buffer in SAP MDG?

Use the BP change buffer and MDG app context to read BP_HEADER, BP_CENTRL, BP_VENGEN, and ZBP_BUDET, then build BP_PORG defaults only when the target rows are initial and write them back through the MDG write API. The sample implementation also shows CR-type and account-group dependent rules for payment terms, incoterms, and shipping-point logic.

Use the BP change buffer and MDG app context to read BP_HEADER, BP_CENTRL, BP_VENGEN, and ZBP_BUDET, then build BP_PORG defaults only when the target rows are initial and write them back through the MDG write API. The sample implementation also shows CR-type and account-group dependent rules for payment terms, incoterms, and shipping-point logic.

Auto-derive purchasing organization data in MDG BP by reading the current change request context, extracting BP_HEADER, BP_CENTRL, BP_VENGEN, and custom ZBP_BUDET data from the delta/change buffer, then filling BP_PORG only when the target values are still initial. The documented pattern uses the MDG model/read APIs to collect the source entities and the write API to persist the derived purchasing-org row back into the request.

Process flow

  1. Get the current change-request context from `CL_USMD_APP_CONTEXT`.
  2. Read `BP_HEADER` from `i_io_model->read_entity_data_all( )` for the active CR.
  3. Read `BP_PORG` from `i_io_changed_data->read_data( )` so you can merge existing changed rows.
  4. Read supporting entities such as `BP_CENTRL` and `BP_VENGEN` as needed for rule context.
  5. Read custom source entity `ZBP_BUDET` if the purchasing-org defaults come from custom BP data.
  6. Build a `BP_PORG` work area only when the target field is still initial or should be derived.
  7. Apply business rules for payment terms, incoterms, shipping-point flags, and other org defaults.
  8. Delete incomplete rows such as entries with initial `prch_org` before writing back to the buffer using `i_io_write_data->write_data( )`.

Referenced tables

ObjectPurpose
USMD_CREQUESTChange request context used to control derivation logic in MDG.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example

Exact relevant implementation excerpt from the knowledge document.

1* Purpose: Auto-derive purchasing-org fields from the BP change buffer. 2 3METHOD auto_derive_porg. 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 lo_data_porg 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 ls_bp_porg TYPE /mdgbpx/_s_bp_pp_bp_porg, 41 ls_bp_porg_der TYPE /mdgbpx/_s_bp_pp_bp_porg, 42 lt_bp_centrl LIKE TABLE OF ls_bp_centrl, 43 lt_bp_porg LIKE TABLE OF ls_bp_porg, 44 lt_bp_porg_der LIKE TABLE OF ls_bp_porg, 45 ls_bp_vengen TYPE /mdgbpx/_s_bp_pp_bp_vengen, 46 lt_bp_vengen LIKE TABLE OF ls_bp_vengen, 47 lt_ztecustom TYPE STANDARD TABLE OF zmdgbp_s_bp_pp_zbp_budet, 48 ls_ztecustom TYPE zmdgbp_s_bp_pp_zbp_budet, 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_att TYPE REF TO cl_abap_structdescr, 57 lo_singleton TYPE REF TO zcl_mdg_singleton, 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 77 i_io_model->read_entity_data_all( EXPORTING i_fieldname = 'BP_HEADER' 78 if_active = abap_false 79 i_crequest = lv_crequest 80 IMPORTING et_data_entity = lt_data_entity ). 81 CHECK lt_data_entity IS NOT INITIAL. 82 READ TABLE lt_data_entity INTO ls_data_entity WITH KEY usmd_entity = lc_headr 83 usmd_entity_cont = space 84 struct = 'KATTR'. 85 IF sy-subrc = 0. 86 CLEAR lo_data_r. 87 lo_data_r = ls_data_entity-r_t_data. 88 ASSIGN lo_data_r->* TO <fs_lt_data>. 89 LOOP AT <fs_lt_data> ASSIGNING <fs_ls_data>. 90 ASSIGN COMPONENT 'BU_GROUP' OF STRUCTURE <fs_ls_data> TO FIELD-SYMBOL(<fs_bu_group>). 91 IF <fs_bu_group> IS ASSIGNED AND <fs_bu_group> IS NOT INITIAL. 92 ASSIGN COMPONENT 'BU_TYPE' OF STRUCTURE <fs_ls_data> TO FIELD-SYMBOL(<fs_bu_type>). 93 IF <fs_bu_type> IS ASSIGNED. 94 MOVE-CORRESPONDING <fs_ls_data> TO ls_bpheader. 95 ENDIF. 96 ENDIF. 97 ENDLOOP. 98 ENDIF. 99* Begin of changes TE552556 | POrg Derivation | INC6049796 100* Read Purchase org Data. 101 i_io_changed_data->read_data( EXPORTING i_entity = lc_bpporg 102 i_struct = 'KATTR' 103 IMPORTING er_t_data_mod = lo_data_porg ). 104 IF lo_data_porg IS BOUND. . 105 ASSIGN lo_data_porg->* TO <fs_lt_data>. 106 LOOP AT <fs_lt_data> ASSIGNING <fs_ls_data>. 107 MOVE-CORRESPONDING <fs_ls_data> TO ls_bp_porg_der. 108 APPEND ls_bp_porg_der TO lt_bp_porg_der. 109 ENDLOOP. 110 ENDIF. 111* EOC TE552556 | P Org Derivations | INC6049796 112*Read Centrl Data 113 READ TABLE lt_data_entity INTO ls_data_entity WITH KEY usmd_entity = lc_headr 114 usmd_entity_cont = lc_centrl. 115 116 IF sy-subrc = 0. 117 CLEAR lo_data_r. 118 lo_data_r = ls_data_entity-r_t_data. 119 ASSIGN lo_data_r->* TO <fs_lt_data>. 120 LOOP AT <fs_lt_data> ASSIGNING <fs_ls_data>.

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

Related questions and keywords

Alternative questions

  • How can purchasing organization defaults be derived in BP supplier MDG processing?
  • How is BP_PORG populated automatically from changed BP data?
  • What is the ABAP pattern for auto-deriving purchasing-org data in MDG BP?

Possible questions

  • Which BP entities and fields are read for purchasing-org derivation?
  • How does the derivation read active versus changed data in MDG?
  • What business rules control purchasing-org defaulting for supplier CR types?
  • How do I implement a similar purchasing-org derivation in ZCL_MDGBP_BP_DEFAULTS?
  • How do I write the derived BP_PORG data back to the MDG buffer?

Keywords

SAP MDGBusiness PartnerBP_PORGauto-derivepurchasing organizationchange bufferIF_USMD_APP_CONTEXTIF_USMD_MODEL_EXTIF_USMD_DELTA_BUFFER_WRITEZCL_MDGBP_BP_DEFAULTSUSMD_CREQUEST