SAP MDG · VALIDATION DERIVATION
How do I implement `IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY` for an SAP MDG BAdI validation?
Implement the BAdI in SE19, bind an ABAP class that implements `IF_EX_USMD_RULE_SERVICE`, and keep `CHECK_ENTITY` as a thin orchestrator: guard by CR type/process, delegate business rules to a rule class, and append local messages to `ET_MESSAGE`.
Implement the BAdI in SE19, bind an ABAP class that implements `IF_EX_USMD_RULE_SERVICE`, and keep `CHECK_ENTITY` as a thin orchestrator: guard by CR type/process, delegate business rules to a rule class, and append local messages to `ET_MESSAGE`.
`CHECK_ENTITY` is the MDG validation hook for entity-level checks. The recommended pattern is to create the BAdI implementation in SE19, assign an implementing class, keep the method explicit, guard the logic by CR type/process, and delegate detailed checks to a rule class before appending messages to `ET_MESSAGE`.
Process flow
- Open `SE18` and display BAdI definition `
USMD_RULE_SERVICE`. - Check interface `IF_EX_USMD_RULE_SERVICE`, method list, and whether the BAdI is filter-dependent.
- Open `SE19` and create the BAdI implementation.
- Assign the implementing class or create a new `Z*` class.
- Implement `IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY` in the class.
- Guard the code by CR type/process and entity type.
- Loop through `IT_DATA`, validate fields, and append `usmd_s_message` rows to `ET_MESSAGE`.
- Activate the class, BAdI implementation, and message/class dependencies in the correct order.
Referenced tables
| Object | Purpose |
|---|---|
usmd_s_message | Structure used to return validation messages from `CHECK_ENTITY` to the MDG framework. |
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 and code a `CHECK_ENTITY` validation in `
USMD_RULE_SERVICE`? - What is the recommended pattern for SAP MDG `CHECK_ENTITY` validations?
- How do I add entity-level validation messages to `ET_MESSAGE` in MDG?
Possible questions
- How do I implement `CHECK_ENTITY` for a Business Partner MDG validation?
- How do I create a BAdI implementation in SE18/SE19 for MDG validations?
- How should I build messages in `usmd_s_message` for MDG checks?
- How do I structure a thin orchestrator validation class in MDG?
- How do I guard MDG checks by CR type or process?