SAP MDG · VALIDATION DERIVATION

How do I implement `USMD_RULE_SERVICE` `CHECK_ENTITY` and `DERIVE_ENTITY` in SAP MDG?

Use BAdI `USMD_RULE_SERVICE` in SE19 with an implementing class that redefines `CHECK_ENTITY` for validations and `DERIVE_ENTITY` for defaulting. Gate the logic by `id_entitytype`, read fields generically with `ASSIGN COMPONENT`, return validation errors in `et_message`, and modify `ct_data` in place for derivations.

Use BAdI `USMD_RULE_SERVICE` in SE19 with an implementing class that redefines `CHECK_ENTITY` for validations and `DERIVE_ENTITY` for defaulting. Gate the logic by `id_entitytype`, read fields generically with `ASSIGN COMPONENT`, return validation errors in `et_message`, and modify `ct_data` in place for derivations.

Use BAdI `USMD_RULE_SERVICE` for MDG entity-level validation and defaulting. In SE18 confirm the interface is `IF_EX_USMD_RULE_SERVICE`, then in SE19 create the implementation, assign the class, and maintain any required data-model filter. In the class, `CHECK_ENTITY` should validate records and return messages in `et_message`, while `DERIVE_ENTITY` should fill non-key target fields in `ct_data` only when they are initial.

Process flow

  1. Open `SE18` and display BAdI `USMD_RULE_SERVICE`.
  2. Confirm interface `IF_EX_USMD_RULE_SERVICE` and whether the BAdI is filter-dependent.
  3. Open `SE19` and create the BAdI implementation.
  4. Assign the implementing class and maintain the data-model filter if required.
  5. Implement `CHECK_ENTITY` for validation logic that returns `et_message` entries.
  6. Implement `DERIVE_ENTITY` for defaulting logic that updates `ct_data` in place.
  7. Activate the class and BAdI implementation.
  8. Test the business transaction and verify that the method is called with the expected entity type.
SE19

Create Implementation for BAdI `USMD_RULE_SERVICE`

Create and activate the BAdI implementation, assign the class, and maintain the data-model filter.

Referenced tables

ObjectPurpose
usmd_s_messageMessage structure used to return validation and information messages to the framework.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP example: 02_CLEAN_CHECK_ENTITY_ZCL_BP_COMPNY_DER_VAL.abap

Exact relevant implementation excerpt from the knowledge document set.

1METHOD if_ex_usmd_rule_service~check_entity. 2 FIELD-SYMBOLS: <lt_bp_header> TYPE any table, 3 <ls_bp_header> TYPE any, 4 <ls_row> TYPE any, 5 <lv_ktokk> TYPE any, 6 <lv_comp> TYPE any, 7 <lv_recon> TYPE any, 8 <lv_paym> TYPE any. 9 10 DATA: lt_filter TYPE usmd_t_entity, 11 ls_filter TYPE usmd_s_entity, 12 ls_message TYPE usmd_s_message, 13 lo_app_context TYPE REF TO if_usmd_app_context. 14 15 lo_app_context = cl_usmd_app_context=>get_context( ). 16 CHECK lo_app_context IS BOUND. 17 18 zcl_mdg_suppl_utility=>get_cr_details( 19 IMPORTING 20 ev_crequest_type = DATA(lv_crequest_type) 21 ev_crequest_step = DATA(lv_crequest_step) ). 22 23 CHECK lv_crequest_step = zif_bp_constants=>cr_step-step_00. 24 25 ls_filter = zif_bp_constants=>entity_type-bp_header. 26 INSERT ls_filter INTO TABLE lt_filter. 27 28 io_model->read_entity_data_all( 29 EXPORTING 30 i_fieldname = 'BP_HEADER' 31 if_active = abap_false 32 i_crequest = id_crequest 33 it_entity_filter = lt_filter 34 IMPORTING 35 et_data_entity = DATA(lt_header_entity) 36 et_message = DATA(lt_read_msg) ). 37 38 READ TABLE lt_header_entity INTO DATA(ls_header_entity) 39 WITH KEY usmd_entity = zif_bp_constants=>bp_header-bp_header. 40 IF sy-subrc = 0. 41 ASSIGN ls_header_entity-r_t_data->* TO <lt_bp_header>. 42 ENDIF. 43 44 IF <lt_bp_header> IS ASSIGNED. 45 READ TABLE <lt_bp_header> ASSIGNING <ls_bp_header> INDEX 1. 46 IF sy-subrc = 0. 47 ASSIGN COMPONENT zif_bp_constants=>bp_header-bu_group OF STRUCTURE <ls_bp_header> TO <lv_ktokk>. 48 ENDIF. 49 ENDIF. 50 51 CHECK it_data IS NOT INITIAL. 52 53 LOOP AT it_data ASSIGNING <ls_row>. 54 ASSIGN COMPONENT zif_bp_constants=>bp_compny-company OF STRUCTURE <ls_row> TO <lv_comp>. 55 CHECK <lv_comp> IS ASSIGNED AND <lv_comp> IS NOT INITIAL. 56 57 ASSIGN COMPONENT zif_bp_constants=>bp_compny-ref_bpcmp OF STRUCTURE <ls_row> TO <lv_recon>. 58 IF <lv_recon> IS ASSIGNED AND <lv_recon> IS INITIAL. 59 CLEAR ls_message. 60 ls_message-msgid = zif_bp_constants=>message-msg_class. 61 ls_message-msgty = zif_bp_constants=>message-msg_error. 62 ls_message-msgno = '007'. 63 ls_message-fieldname = zif_bp_constants=>bp_compny-ref_bpcmp. 64 ls_message-msgv1 = <lv_comp>. 65 APPEND ls_message TO et_message. 66 ENDIF. 67 68 ASSIGN COMPONENT zif_bp_constants=>bp_compny-zwels OF STRUCTURE <ls_row> TO <lv_paym>. 69 IF <lv_paym> IS ASSIGNED AND <lv_paym> IS INITIAL. 70 CLEAR ls_message. 71 ls_message-msgid = zif_bp_constants=>message-msg_class. 72 ls_message-msgty = zif_bp_constants=>message-msg_error. 73 ls_message-msgno = '008'. 74 ls_message-fieldname = zif_bp_constants=>bp_compny-zwels. 75 ls_message-msgv1 = <lv_comp>. 76 APPEND ls_message TO et_message. 77 ENDIF. 78 ENDLOOP. 79 80 IF et_message IS NOT INITIAL. 81 zcl_mdg_suppl_utility=>get_message_row_id( 82 EXPORTING 83 io_model = io_model 84 id_crequest = id_crequest 85 id_entitytype = id_entitytype 86 CHANGING 87 ct_message = et_message ). 88 89 zcl_mdgbp_bp_validation=>adjust_messages( 90 EXPORTING 91 cr_number = id_crequest 92 CHANGING 93 ct_message = et_message ). 94 ENDIF. 95ENDMETHOD.

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

Related questions and keywords

Alternative questions

  • How do I create a BAdI implementation for `USMD_RULE_SERVICE` in SE19?
  • What is the standard pattern for `CHECK_ENTITY` validations in SAP MDG?
  • How do I default entity fields with `DERIVE_ENTITY` in SAP MDG?

Possible questions

  • How do I validate mandatory fields in MDG entity data?
  • How do I derive default values for an MDG entity after key entry?
  • Which BAdI and method should I use for MDG entity validation?
  • What is the ABAP sample for a flattened `USMD_RULE_SERVICE` implementation?
  • How do I register a rule-service class in SE19?

Keywords

USMD_RULE_SERVICEIF_EX_USMD_RULE_SERVICECHECK_ENTITYDERIVE_ENTITYSE18SE19usmd_s_messageusmd1_cs_msgtyCL_USMD_APP_CONTEXTct_datait_data