SAP MDG · VALIDATION DERIVATION

How do I implement CHECK_ENTITY validation in SAP MDG BAdI USMD_RULE_SERVICE for a Business Partner company-code entity?

Use BAdI USMD_RULE_SERVICE method IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY for entity-level validation, gate the logic by the target entity and CR step, loop over IT_DATA with dynamic field access, append usmd_s_message entries to ET_MESSAGE, and enrich messages with GET_MESSAGE_ROW_ID before optional ADJUST_MESSAGES processing.

Use BAdI USMD_RULE_SERVICE method IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY for entity-level validation, gate the logic by the target entity and CR step, loop over IT_DATA with dynamic field access, append usmd_s_message entries to ET_MESSAGE, and enrich messages with GET_MESSAGE_ROW_ID before optional ADJUST_MESSAGES processing.

In SAP MDG, entity-level validation belongs in BAdI USMD_RULE_SERVICE method IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY. For a BP company-code entity, the standard pattern is to guard by application context and CR step, read the current entity data, check the relevant fields record by record, and return business errors through ET_MESSAGE with FIELDNAME so the UI can navigate to the exact row.

Process flow

  1. 1. Open SE18 and check the BAdI definition USMD_RULE_SERVICE and interface IF_EX_USMD_RULE_SERVICE.
  2. 2. Open SE19 and create or maintain the BAdI implementation with the correct Z* class.
  3. 3. Assign the implementing class and activate the class skeleton.
  4. 4. Implement IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY.
  5. 5. In CHECK_ENTITY, read the application context with CL_USMD_APP_CONTEXT=>GET_CONTEXT( ).
  6. 6. Read the CR details with ZCL_MDG_SUPPL_UTILITY=>GET_CR_DETAILS and gate the logic by the required CR step.
  7. 7. Read the entity data with IO_MODEL->READ_ENTITY_DATA_ALL when you need header/context values.
  8. 8. Loop over IT_DATA, assign the required components dynamically, and validate each record separately. 9. Fill USMD_S_MESSAGE with MSGID, MSGNO, MSGTY, FIELDNAME, and message variables. 10. Append each error or warning to ET_MESSAGE. 11. If

Referenced tables

ObjectPurpose
USMD_S_MESSAGEMessage structure used to return validation results to the MDG framework.
USMD_T_ENTITYEntity filter table used when reading entity data from the model.

ILLUSTRATIVE ABAP SAMPLE

CHECK_ENTITY implementation pattern for BP company-code validation

Source-supported sample adapted from ZCL_BP_COMPNY_DER_VAL. It validates company-code rows, appends messages to ET_MESSAGE, then enriches row IDs and adjusts message severity.

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 can I validate BP company-code fields in CHECK_ENTITY?
  • How do I add error messages in IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY?
  • How do I read CR context and entity data in an MDG validation BAdI?

Possible questions

  • How do I implement a company-code validation in SAP MDG Business Partner MDG?
  • Which BAdI method should I use for entity-level checks in SAP MDG?
  • How do I enrich CHECK_ENTITY messages with row IDs in MDG?
  • How do I debug USMD_RULE_SERVICE validations in MDG?
  • How do I use GET_MESSAGE_ROW_ID and ADJUST_MESSAGES after appending ET_MESSAGE?

Keywords

SAP MDGUSMD_RULE_SERVICEIF_EX_USMD_RULE_SERVICECHECK_ENTITYBusiness Partnercompany codevalidationET_MESSAGECL_USMD_APP_CONTEXTGET_MESSAGE_ROW_IDADJUST_MESSAGESSE18SE19