SAP MDG · VALIDATION DERIVATION

How do I implement BP business data derivation in SAP MDG for a custom entity like ZBP_BUDET?

Implement the BP derivation hook so it reads the current change request, fetches BP_HEADER, checks the business partner group/account group, and then defaults the custom business-data field only when the target field is initial. In the provided example, ZSUPINT1 with specific account groups derives ZZOCOMCOD to ZZ070000.

Implement the BP derivation hook so it reads the current change request, fetches BP_HEADER, checks the business partner group/account group, and then defaults the custom business-data field only when the target field is initial. In the provided example, ZSUPINT1 with specific account groups derives ZZOCOMCOD to ZZ070000.

Implement the BP business data derivation in `ZIF_TE_DERIVATION~D_BP_BUDET` by reading the active change request from `CL_USMD_APP_CONTEXT`, fetching `BP_HEADER` via `IO_MODEL->READ_ENTITY_DATA_ALL`, and then looping over `CT_DATA` to default the custom field when the controlling CR type and account-group conditions are met. The sample pattern derives `ZZOCOMCOD` to `ZZ070000` for intercompany request type `ZSUPINT1` and selected groups, while leaving user-entered values intact unless the field is initial.

Process flow

  1. Open the derivation implementation in SE18 and confirm the BAdI/interface.
  2. Create or open the implementation in SE19 and assign the implementing class.
  3. Ensure the class implements the derivation interface containing D_BP_BUDET.
  4. Read the current change request ID from CL_USMD_APP_CONTEXT.
  5. Get the CR object with CL_USMD_CREQUEST_API=>GET_INSTANCE using model ZIF_BP_CONSTANTS=>DATA_MODEL-BP.
  6. Read BP_HEADER with IO_MODEL->READ_ENTITY_DATA_ALL.
  7. Assign BU_GROUP from BP_HEADER into a field symbol.
  8. Loop over CT_DATA and dynamically assign ZZOCOMCOD or the target field you need to derive. Apply the rule only for the relevant CR type and account groups. Activate and retest the CR flow.

Referenced tables

ObjectPurpose
USMD_CREQUESTChange request header data used by the MDG runtime and read through the change-request API.
BP_HEADERHeader entity read from the MDG model to obtain BP grouping/account-group context.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example

Exact relevant implementation excerpt from the knowledge document.

1* Purpose: Interface hook for BP business data derivation. 2 3 METHOD zif_te_derivation~d_bp_budet. 4 DATA:lt_filter TYPE usmd_t_entity, 5 wa_filter LIKE LINE OF lt_filter. 6 7 CONSTANTS: lc_header TYPE usmd_fieldname VALUE 'BP_HEADER'. 8 9 FIELD-SYMBOLS: <fs_t_data_bp_header> TYPE ANY TABLE, 10 <fs_t_data_bp_compny> TYPE ANY TABLE, 11 <fs_t_data> TYPE ANY TABLE, 12 <fs_data> TYPE any. 13 14 DATA(lo_context) = cl_usmd_app_context=>get_context( ). 15 CHECK lo_context IS BOUND. 16 17 lo_context->get_attributes( IMPORTING ev_crequest_id = DATA(lv_crequest_id) ). 18 19 cl_usmd_crequest_api=>get_instance( 20 EXPORTING 21 iv_crequest = lv_crequest_id 22 iv_model_name = zif_bp_constants=>data_model-bp " Data Model 23 IMPORTING 24 et_message = et_message " Messages 25 re_inst_crequest_api = DATA(lo_crequest) " Change Request API Interface 26 ). 27 lo_crequest->read_crequest( 28 IMPORTING 29 es_crequest = DATA(ls_crequest) " Change Request 30 ). 31 32 ASSIGN ct_data TO <fs_t_data>. 33***** IF ( id_crequest_type = 'ZSUPL2P1' 34***** OR id_crequest_type = 'ZSUPINT2' 35***** OR id_crequest_type = 'ZSUPL4P2' ) 36***** AND id_entitytype = 'ZBP_BUDET'. 37***** IF zcl_mdgbp_bp_validation=>cleared_fields NE 'X'. 38***** LOOP AT <fs_t_data> ASSIGNING FIELD-SYMBOL(<fs_data_budet>). 39***** FIELD-SYMBOLS: <fs_field> TYPE any. 40***** " Check ZZOCOMCOD 41***** ASSIGN COMPONENT 'ZZOCOMCOD' OF STRUCTURE <fs_data_budet> TO <fs_field>. 42***** IF sy-subrc EQ 0. 43***** <fs_field> = ''. 44***** ENDIF. 45***** 46***** ASSIGN COMPONENT 'ZZOCOMPNY' OF STRUCTURE <fs_data_budet> TO <fs_field>. 47***** IF sy-subrc EQ 0. 48***** <fs_field> = ''. 49***** ENDIF. 50***** 51***** ASSIGN COMPONENT 'ZZOPU_DEP' OF STRUCTURE <fs_data_budet> TO <fs_field>. 52***** IF sy-subrc EQ 0. 53***** <fs_field> = ''. 54***** ENDIF. 55***** zcl_mdgbp_bp_validation=>cleared_fields = 'X'. 56***** ENDLOOP. 57***** ENDIF. 58***** ENDIF. 59* Get Header Details 60 wa_filter = zif_bp_constants=>entity_type-bp_header. 61 INSERT wa_filter INTO TABLE lt_filter. 62 io_model->read_entity_data_all( 63 EXPORTING 64 i_fieldname = lc_header 65 if_active = abap_false 66 i_crequest = ls_crequest-usmd_crequest 67 it_entity_filter = lt_filter 68 IMPORTING 69 et_message = DATA(lt_et_message) " Messages 70 et_data_entity = DATA(lt_data_bp_header) " Data for Entity Types 71 ). 72 DATA ls_data_bp_header LIKE LINE OF lt_data_bp_header. 73 IF lt_data_bp_header IS NOT INITIAL. 74 READ TABLE lt_data_bp_header INTO ls_data_bp_header WITH KEY usmd_entity = zif_bp_constants=>bp_header-bp_header. 75 IF sy-subrc EQ 0. 76 ASSIGN ls_data_bp_header-r_t_data->* TO <fs_t_data_bp_header>. 77 ENDIF. 78 ENDIF. 79 IF <fs_t_data_bp_header> IS ASSIGNED. 80 LOOP AT <fs_t_data_bp_header> ASSIGNING FIELD-SYMBOL(<fs_bp_header>). 81 ASSIGN COMPONENT zif_bp_constants=>bp_header-bu_group OF STRUCTURE <fs_bp_header> TO FIELD-SYMBOL(<fs_ktokk>). 82 ENDLOOP. 83 ENDIF. 84 85 IF <fs_ktokk> IS ASSIGNED AND <fs_ktokk> IS INITIAL. 86 <fs_ktokk> = iv_bu_group. 87 ENDIF. 88 89 LOOP AT <fs_t_data> ASSIGNING <fs_data>. 90* Commodity code to be derived to ZZ070000 for ZSUPINT1 (Intercompany) for account group Z002 and Z010. 91 IF id_crequest_type = zif_bp_constants=>creq_type-zsupint1. 92 IF <fs_ktokk> IS ASSIGNED AND <fs_ktokk> IS NOT INITIAL. 93 IF <fs_ktokk> EQ zif_bp_constants=>ktokk-z002 OR 94 <fs_ktokk> EQ zif_bp_constants=>ktokk-v002 OR 95 <fs_ktokk> EQ zif_bp_constants=>ktokk-vd02 OR 96 <fs_ktokk> EQ zif_bp_constants=>ktokk-z010 OR 97 <fs_ktokk> EQ zif_bp_constants=>ktokk-v010 OR 98 <fs_ktokk> EQ zif_bp_constants=>ktokk-vd10. 99 ASSIGN COMPONENT zif_bp_constants=>zbp_budet-zzocomcod OF STRUCTURE <fs_data> TO FIELD-SYMBOL(<fs_comcode>). 100 IF <fs_comcode> IS ASSIGNED. "AND <fs_comcode> IS INITIAL. 101 <fs_comcode> = 'ZZ070000'. 102 ENDIF. 103 ENDIF. 104 ENDIF. 105 ENDIF. 106 ENDLOOP. 107 ENDMETHOD. 108 109 110 111* Generic note: custom helper calls in this method are documented by role in the paired knowledge note. 112* Generic note: small constants and selector literals are business-rule markers, not separate logic.

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

Related questions and keywords

Alternative questions

  • How do I derive custom BP fields in MDG using IF_EX_USMD_RULE_SERVICE or the TE derivation hook?
  • How do I default ZZOCOMCOD in BP derivation based on change request type and account group?
  • How do I implement derivation for BP business data in a custom MDG entity?

Possible questions

  • How can I populate a custom BP business-data entity during MDG change request processing?
  • What is the ABAP pattern for BP derivation in ZIF_TE_DERIVATION~D_BP_BUDET?
  • How do I read BP_HEADER and derive ZBP_BUDET values in MDG?
  • How do I make derivation conditional on CR type like ZSUPINT1 in MDG BP?
  • What are the steps to implement a BP derivation BAdI in SE18/SE19?

Keywords

SAP MDGBusiness PartnerderivationdefaultingIF_EX_USMD_RULE_SERVICEZIF_TE_DERIVATIOND_BP_BUDETBP_HEADERUSMD_RULE_SERVICESE18SE19change requestaccount groupZZOCOMCOD