SAP MDG · VALIDATION DERIVATION

How do I implement MDG-M check and derivation rules with BRF+ and USMD_RULE_SERVICE?

Use MDGIMG / USMD_RULE to maintain the validation or derivation scenario, then implement the logic in BRF+ or in the BAdI `USMD_RULE_SERVICE`. For the documented material example, the source field `MMSTA` in `MARCBASIC` triggers target-entity derivation in `MARCMRPPP`, setting `DISMM = PD` and `DGRMRPPP = 0001` when `MMSTA = 40`, `DISMM = ND`, and `DGRMRPPP` is initial.

Use MDGIMG / USMD_RULE to maintain the validation or derivation scenario, then implement the logic in BRF+ or in the BAdI `USMD_RULE_SERVICE`. For the documented material example, the source field `MMSTA` in `MARCBASIC` triggers target-entity derivation in `MARCMRPPP`, setting `DISMM = PD` and `DGRMRPPP = 0001` when `MMSTA = 40`, `DISMM = ND`, and `DGRMRPPP` is initial.

Use `MDGIMG` → `USMD_RULE` to define the BRF+ validation/derivation scenario, then implement the runtime logic either in BRF+ or in `USMD_RULE_SERVICE`. For the documented MDG-M example, the rule watches source entity `MARCBASIC`, reads `MMSTA`, and forces target-entity derivation in `MARCMRPPP` when `MMSTA = 40` and the target fields are ready for defaulting.

Process flow

  1. Open `MDGIMG` and navigate to the MDG data modeling / validation and derivation rule area.
  2. Use `USMD_RULE` for the MM model to maintain the BRF+ validation or derivation scenario.
  3. Create the BRF+ function or rule and bind the relevant entity data object.
  4. For the material example, create `ATTRIBUTE_VALUE_01` bound to `USMD_VALUE`.
  5. Maintain the source condition for `MARCBASIC-MMSTA` and the target result for `MARCMRPPP`.
  6. Activate the BRF+ objects.
  7. Implement `IF_USMD_CONV_SOM_GOV_ENTITY~WRITE_ENTITY_DATA` as a post-exit.
  8. Call `Z_CL_ENFORCE_BRF_PLUS_CALL=>ENFORCE_BRF_PLUS_CALL` with source entity `MARCBASIC`, target entity `MARCMRPPP`, source attribute `MMSTA`, and target keys `MATERIAL` and `WERKS`.

Referenced tables

ObjectPurpose
USMD_T_ATTR_VALUETable type used for the BRF+ table variable `TABLE_OF_KEY_VALUES` in the cross-entity derivation example.
USMD_GOV_API_TS_ENT_DATATable type used to carry entity data in the runtime enforcement method.
USMD_GOV_API_TS_ENT_TABLTable type used for source entity keys in the runtime enforcement method.
USMD_T_CHANGED_ENTITIESTable of changed entities used to detect whether the source attribute actually changed.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example

Exact relevant implementation excerpt from the knowledge document.

1*---------------------------------------------------------------------* 2* Maintain Check and Derivation Rules in MDG for Material 3* ABAP code/program fragments reproduced from the source guide. 4*---------------------------------------------------------------------* 5 6*---------------------------------------------------------------------* 7* 8.1.3 - Z-Class method code 8* Example class: Z_CL_ENFORCE_BRF_PLUS_CALL 9* Example method: ENFORCE_BRF_PLUS_CALL 10*---------------------------------------------------------------------* 11********************************************************************* 12* Method enforces the BRF+ rules for the target entity, if the value of 13* the source attribute is changed. 14********************************************************************* 15 16data: 17 ls_entity_data type usmd_gov_api_s_ent_data, 18 lt_entity_keys type usmd_gov_api_ts_ent_tabl, 19 ls_entity_keys type usmd_gov_api_s_ent_tabl, 20 lt_changes type usmd_t_changed_entities, 21 ls_changes type usmd_s_changed_entities, 22 lo_model type ref to if_usmd_model_ext, 23 lo_so_gov_api type ref to if_usmd_conv_som_gov_api, 24 lv_model type usmd_model, 25 ltr_data type ref to data, 26 lo_instance type ref to if_usmd_model, 27 lo_app_context type ref to if_usmd_app_context, 28 lv_edition type usmd_edition, 29 lv_entity type usmd_entity, 30 lv_entity_fieldname type usmd_fieldname, 31 lv_fieldname type usmd_fieldname, 32 lt_entity_fieldname type usmd_ts_entity_fieldname, 33 ls_entity_fieldname type usmd_s_entity_fieldname, 34 lt_data type usmd_gov_api_ts_ent_data, 35 ls_data type usmd_gov_api_s_ent_data, 36 lv_enforce type boole_d, 37 lt_attr type usmd_ts_field, 38 ls_attr type usmd_s_field, 39 lv_attr type usmd_attribute, 40 lt_sel type usmd_ts_sel, 41 ls_sel type usmd_s_sel, 42 lv_lines type int4, 43 lv_usmd_value type usmd_value, 44 lv_usmd_struc type usmd_struct, 45 lt_message type usmd_t_message. 46 47field-symbols: 48 <lt_entity_data> type index table, 49 <ls_entity_data> type any, 50 <ls_changed_entity> type usmd_s_changed_entity, 51 <ls_key_value> type usmd_s_attr_value, 52 <lt_data> type sorted table, 53 <ls_data> type any, 54 <lv_value> type any. 55 56clear: lv_edition. 57if iv_source_entity is initial or it_source_attr is initial or 58 iv_target_entity is initial. 59 return. 60endif. 61 62"------------------------------------------------------------------ 63" Preparation 64"------------------------------------------------------------------ 65" Determine the application context and the change request of the 66" context. 67lo_app_context = cl_usmd_app_context=>get_context( ). 68 69"Get model-instance and the edition 70if lo_app_context is bound. 71 lo_app_context->get_attributes( 72 importing 73 ev_edition = lv_edition 74 eo_model = lo_model ). 75 assert lo_model is bound. 76 lv_model = lo_model->if_usmd_model_metadata_ext~d_usmd_model. 77 assert lv_model is not initial. 78endif. 79 80" Belong the BRF_plus-rule to the right model? If not return. 81if iv_model <> lv_model. 82 return. 83endif. 84 85" Get a suitable modelinstance to get the field name of the entity 86" (the previous calculated model-instance cannot be needed) 87cl_usmd_model=>get_instance( 88 exporting 89 i_usmd_model = lv_model 90 importing 91 eo_instance = lo_instance 92 et_message = lt_message ). 93assert lo_instance is not initial. 94 95"------------------------------------------------------------------ 96" Checks 97"------------------------------------------------------------------ 98 99"Get fieldname of the source entity 100lv_entity_fieldname = cl_usmd_services=>entity2fieldname( 101 io_model = lo_instance 102 i_entity = iv_source_entity ). 103lv_entity = lv_entity_fieldname. 104 105" Do entity data refer to the source entity? 106loop at it_entity_data into ls_entity_data where entity = lv_entity. 107 clear ls_entity_keys. 108 ls_entity_keys-entity = lv_entity. 109 ls_entity_keys-tabl = ls_entity_data-entity_data. 110 insert ls_entity_keys into table lt_entity_keys. 111endloop. 112 113" If the entity data do not refer to the source entity => don't 114" enforce a rule 115if lt_entity_keys is initial. 116 return. 117endif. 118 119" Check whether an attribute from the given list IT_SOURCE_ATTR 120" has been changed: If yes then enforce the BRF_plus rule for the

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

Related questions and keywords

Alternative questions

  • How can I validate an MDG Material field with BRF+?
  • How do I derive MDG-M target entity data when a source field changes?
  • How do I enforce a BRF+ derivation for a target MDG entity in Material?

Possible questions

  • How do I validate an MDG attribute using BRFplus?
  • How can I derive an MDG field automatically?
  • Which transaction is used for MDG BRFplus rules?
  • How do I implement entity-level validations in SAP MDG via USMD_RULE_SERVICE?
  • How do I trigger a target-entity derivation when source data changes?

Keywords

SAP MDGMDG-MBRF+USMD_RULE_SERVICEUSMD_RULE_SERVICE_CROSS_ETMDGIMGUSMD_RULECHECK_ENTITYDERIVE_ENTITYMMSTADISMMDGRMRPPPMARCBASICMARCMRPPPUSMD_VALUEIF_USMD_CONV_SOM_GOV_ENTITY~WRITE_ENTITY_DATA