SAP MDG · VALIDATION DERIVATION

How do I implement SAP MDG entity validation in CHECK_ENTITY using BAdI USMD_RULE_SERVICE?

Implement CHECK_ENTITY in IF_EX_USMD_RULE_SERVICE as a guarded, entity-specific validation: read application context, check the BP model, loop over IT_DATA with dynamic field access, append USMD_S_MESSAGE entries to ET_MESSAGE, and normalize messages if needed.

Implement CHECK_ENTITY in IF_EX_USMD_RULE_SERVICE as a guarded, entity-specific validation: read application context, check the BP model, loop over IT_DATA with dynamic field access, append USMD_S_MESSAGE entries to ET_MESSAGE, and normalize messages if needed.

Implement CHECK_ENTITY in IF_EX_USMD_RULE_SERVICE when you need entity-level MDG validations such as mandatory fields, format checks, or cross-entity consistency checks. The retrieved template shows the standard flow: read application context first, guard by model BP, process IT_DATA generically, build USMD_S_MESSAGE entries with MSGID, MSGNO, MSGTY, and FIELDNAME, then append them to ET_MESSAGE. If messages need harmonization, the sample calls ZCL_MDGBP_BP_VALIDATION=>ADJUST_MESSAGES before returning.

Process flow

  1. Open SE18 and inspect BAdI definition USMD_RULE_SERVICE.
  2. Create or change the implementation in SE19.
  3. Assign or create the implementing class that implements IF_EX_USMD_RULE_SERVICE.
  4. Implement CHECK_ENTITY with early guards for application context and model BP.
  5. Loop over IT_DATA and validate target fields dynamically using ASSIGN COMPONENT.
  6. Build USMD_S_MESSAGE entries with MSGID, MSGNO, MSGTY, and FIELDNAME.
  7. Append messages to ET_MESSAGE and optionally call ZCL_MDGBP_BP_VALIDATION=>ADJUST_MESSAGES.
  8. Activate the class, implementation, and dependent objects in the correct order.

Referenced tables

ObjectPurpose
USMD_S_MESSAGEMessage structure used to return validation errors and warnings from CHECK_ENTITY.
USMD_T_MESSAGEInternal message table type used to collect validation messages before returning them in ET_MESSAGE.

ILLUSTRATIVE ABAP SAMPLE

Generic CHECK_ENTITY validation template for SAP MDG BP

Source-adapted template from the retrieved CHECK_ENTITY example; replace SOME_MAND_FIELD, message class, and message number with your business-specific values.

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 write a CHECK_ENTITY validation for SAP MDG business partner data?
  • How do I implement mandatory-field checks in IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY?
  • How do I add BP validation messages in SAP MDG without hard errors?

Possible questions

  • How do I implement SAP MDG entity validation in CHECK_ENTITY using BAdI USMD_RULE_SERVICE?
  • What is the standard pattern for CHECK_ENTITY in SAP MDG?
  • Which messages and fields should I fill in USMD_S_MESSAGE?
  • How do I activate and test a USMD_RULE_SERVICE BAdI implementation?
  • How do I adapt a generic CHECK_ENTITY template for BP validations?

Keywords

SAP MDGUSMD_RULE_SERVICEIF_EX_USMD_RULE_SERVICECHECK_ENTITYCHECK_REQUESTDERIVE_ENTITYCL_USMD_APP_CONTEXTUSMD_S_MESSAGEET_MESSAGEFIELDNAMEBP validationmandatory checkBAdI implementation