SAP MDG · VALIDATION DERIVATION

How do I implement `IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY` in SAP MDG to add real validation logic for a BP-related entity?

Implement the `USMD_RULE_SERVICE` BAdI in SE19, assign a Z* implementing class, and code `IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY` to validate the entity rows in `IT_DATA` and return messages in `ET_MESSAGE`. The retrieved SAP pattern recommends keeping the method thin, guarding by model/entity type, building `USMD_S_MESSAGE` entries with `MSGID`, `MSGNO`, `MSGTY`, and `FIELDNAME`, and delegating complex rules to separate classes or utilities.

Implement the `USMD_RULE_SERVICE` BAdI in SE19, assign a Z* implementing class, and code `IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY` to validate the entity rows in `IT_DATA` and return messages in `ET_MESSAGE`. The retrieved SAP pattern recommends keeping the method thin, guarding by model/entity type, building `USMD_S_MESSAGE` entries with `MSGID`, `MSGNO`, `MSGTY`, and `FIELDNAME`, and delegating complex rules to separate classes or utilities.

Implement `IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY` in your BAdI class to validate the entity payload and return business errors in `ET_MESSAGE`. The source pattern shows that the current `ZCL_BP_VENVAL_DER_CHARACTERIS` method is only an empty starter, so the next step is to add real validation logic, guard it by entity/model context, and create proper MDG messages with field references.

Process flow

  1. Open `SE18` and inspect `USMD_RULE_SERVICE` to confirm the interface name and method intent.
  2. Open `SE19` and create or edit the BAdI implementation with a Z* name.
  3. Assign the implementing class or create a new Z* class that implements `IF_EX_USMD_RULE_SERVICE`.
  4. Implement `IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY` with guards for application context, model, and entity type.
  5. Loop over `IT_DATA`, read the required fields dynamically, and append `USMD_S_MESSAGE` entries to `ET_MESSAGE` when rules fail.
  6. Optionally enrich the messages for navigation or row mapping.
  7. Activate the class first, then the BAdI implementation, and test in the MDG transaction flow.

Referenced tables

ObjectPurpose
USMD_S_MESSAGEMessage structure used to return validation findings from `CHECK_ENTITY`.
USMD_TS_MESSAGEMessage table type used by the framework for `ET_MESSAGE`.

ILLUSTRATIVE ABAP SAMPLE

Source ABAP implementation example

Concrete CHECK_ENTITY implementation pattern from the same knowledge document set.

1METHOD if_ex_usmd_rule_service~check_entity. 2 DATA: lo_app_context TYPE REF TO if_usmd_app_context, 3 lt_message TYPE usmd_t_message, 4 ls_message TYPE usmd_s_message, 5 lv_crtype TYPE usmd_crequest_type, 6 lv_crstep TYPE usmd_crequest_appstep, 7 lv_crid TYPE usmd_crequest. 8 9 FIELD-SYMBOLS: <ls_data> TYPE any, 10 <lv_value> TYPE any. 11 12 lo_app_context = cl_usmd_app_context=>get_context( ). 13 CHECK lo_app_context IS BOUND. 14 CHECK io_model->d_usmd_model = 'BP'. 15 16 lo_app_context->get_attributes( 17 IMPORTING 18 ev_crequest_type = lv_crtype 19 ev_crequest_step = lv_crstep 20 ev_crequest_id = lv_crid ). 21 22 CHECK it_data IS NOT INITIAL. 23 24 LOOP AT it_data ASSIGNING <ls_data>. 25 ASSIGN COMPONENT 'SOME_MAND_FIELD' OF STRUCTURE <ls_data> TO <lv_value>. 26 IF <lv_value> IS ASSIGNED AND <lv_value> IS INITIAL. 27 CLEAR ls_message. 28 ls_message-msgid = 'ZMDG_SUPPL'. 29 ls_message-msgno = '001'. 30 ls_message-msgty = 'E'. 31 ls_message-fieldname = 'SOME_MAND_FIELD'. 32 APPEND ls_message TO et_message. 33 ENDIF. 34 ENDLOOP. 35 36 IF et_message IS NOT INITIAL. 37 zcl_mdgbp_bp_validation=>adjust_messages( 38 EXPORTING 39 cr_number = lv_crid 40 CHANGING 41 ct_message = et_message ). 42 ENDIF. 43ENDMETHOD.

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

Related questions and keywords

Alternative questions

  • How do I activate validation logic in `ZCL_BP_VENVAL_DER_CHARACTERIS`?
  • What is the implementation pattern for `CHECK_ENTITY` in `USMD_RULE_SERVICE`?
  • How do I add custom entity validation messages in SAP MDG?

Possible questions

  • How do I create the BAdI implementation in SE19?
  • Which fields should I fill in `USMD_S_MESSAGE`?
  • How do I debug `CHECK_ENTITY` in MDG?
  • How do I route validations by CR type or step?
  • How do I return navigation messages from MDG validation?

Keywords

SAP MDGUSMD_RULE_SERVICEIF_EX_USMD_RULE_SERVICECHECK_ENTITYSE18SE19BP validationET_MESSAGEUSMD_S_MESSAGECL_USMD_APP_CONTEXTBAdI implementation