SAP MDG · VALIDATION DERIVATION
How do I implement mandatory supplier attribute validation in SAP MDG Business Partner checks?
Implement the validation in IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY by reading the MDG application context, gating the logic to model BP and supplier-related CR types, loading mandatory-rule customizing from ZMDG_BP_MAND_VAL, reading inactive BP entity data, checking dynamic fields with ASSIGN COMPONENT, and returning error messages in ET_MESSAGE with FIELDNAME filled for UI navigation.
Implement the validation in IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY by reading the MDG application context, gating the logic to model BP and supplier-related CR types, loading mandatory-rule customizing from ZMDG_BP_MAND_VAL, reading inactive BP entity data, checking dynamic fields with ASSIGN COMPONENT, and returning error messages in ET_MESSAGE with FIELDNAME filled for UI navigation.
Use IF_EX_USMD_RULE_SERVICE~CHECK_ENTITY for mandatory supplier validation in MDG BP. The sample logic reads the application context, filters to model 'BP' and supplier-related CR types, loads rule rows from ZMDG_BP_MAND_VAL, reads inactive BP_HEADER data, and checks fields dynamically with ASSIGN COMPONENT before returning navigable error messages in ET_MESSAGE.
Process flow
- Open SE18 and validate the BAdI definition
USMD_RULE_SERVICEand interface IF_EX_USMD_RULE_SERVICE. - Create or open the implementation in SE19 and assign the implementing class.
- Implement CHECK_ENTITY for entity-level validation.
- Read application context with CL_USMD_APP_CONTEXT=>get_context( ).
- Gate the logic by model 'BP' and supplier-related CR types.
- Read mandatory-rule customizing from ZMDG_BP_MAND_VAL.
- Read inactive entity data for BP_HEADER using CL_USMD_MODEL_EXT.
- Loop through entity data, check dynamic components, and append error messages to ET_MESSAGE with FIELDNAME set for UI navigation.
Referenced tables
| Object | Purpose |
|---|---|
ZMDG_BP_MAND_VAL | Custom mandatory-field control table used to drive supplier validation by change request type, entity, field name, business partner grouping, and role mapping. |
AGR_USERS | Standard role assignment table used in the example to determine the current user's active roles for message applicability. |
ILLUSTRATIVE ABAP SAMPLE
Source ABAP example
Exact relevant implementation excerpt from the knowledge document.
1method check_mandatory_supplier_attr.
2*&H ------------------------------------------------------------------*
3*&H HEADER INFORMATION
4*&H-------------------------------------------------------------------*
5*&H AUTHOR: | Favela Rafael
6*&H Team : | SAP MDG
7*&H Date: | 14.02.2024
8*$*$------------------------------------------------------------------*
9*&D MDG BP Validation
10*$*$------------------------------------------------------------------*
11*&A Start CHANGE HISTORY
12*$*$------------------------------------------------------------------*
13*&A Program changes:
14*$*$------------------------------------------------------------------*
15*&A Date 04/02/2025 |TA-No. | Programmer Jithin Inreddy
16*&A Description : Added ZSUPBKD Company code ZZOCOMPNY field check
17*$*$------------------------------------------------------------------*
18
19 DATA:
20 lo_app_context TYPE REF TO if_usmd_app_context,
21 lv_msg_flg TYPE abap_boolean,
22 lv_crstep TYPE usmd_crequest_appstep,
23 lv_crtype TYPE usmd_crequest_type,
24 lv_cr_number TYPE usmd_crequest,
25 lv_bu_group TYPE bu_group,
26 lt_message TYPE usmd_t_message,
27 ls_message TYPE usmd_s_message.
28
29 FIELD-SYMBOLS:
30 <fs_ls_data> TYPE any.
31
32 TYPES: BEGIN OF ty_part,
33 partner TYPE bu_partner,
34 END OF ty_part.
35 DATA lt_cps TYPE TABLE OF ty_part.
36
37 lo_app_context = cl_usmd_app_context=>get_context( ).
38 CHECK lo_app_context IS BOUND.
39 CHECK io_model->d_usmd_model = 'BP'.
40
41 lo_app_context->get_attributes(
42 IMPORTING
43 ev_crequest_step = lv_crstep
44 ev_crequest_type = lv_crtype
45 ev_crequest_id = lv_cr_number ).
46 CHECK lv_crtype CS 'SUP'.
47
48 SELECT * INTO TABLE @DATA(lt_prop)
49 FROM zmdg_bp_mand_val
50 WHERE usmd_creq_type = @lv_crtype.
51
52 IF sy-subrc = 0.
53 TRY.
54 cl_usmd_model_ext=>get_instance(
55 EXPORTING
56 i_usmd_model = 'BP'
57 IMPORTING
58 eo_instance = DATA(ldo_model_ext)
59 et_message = DATA(lt_message1) ).
60 CATCH cx_root.
61 ENDTRY.
62
63 ldo_model_ext->read_entity_data_all(
64 EXPORTING
65 i_fieldname = 'BP_HEADER'
66 if_active = abap_false
67 i_crequest = lv_cr_number
68 IMPORTING
69 et_message = DATA(lt_message_inactive)
70 et_data_entity = DATA(lt_inactive_data) ).
71
72 SELECT agr_name,
73 uname,
74 from_dat,
75 to_dat
76 FROM agr_users
77 INTO TABLE @DATA(lt_roles)
78 WHERE uname = @sy-uname
79 AND from_dat LE @sy-datum
80 AND to_dat GT @sy-datum. "#EC CI_SGLSELECT
81
82 LOOP AT lt_inactive_data ASSIGNING FIELD-SYMBOL(<ls_inactive_data>).
83 ASSIGN <ls_inactive_data>-r_t_data->* TO FIELD-SYMBOL(<lt_data>).
84 LOOP AT <lt_data> ASSIGNING FIELD-SYMBOL(<ls_data>).
85 LOOP AT lt_prop INTO DATA(ls_prop)
86 WHERE usmd_entity = <ls_inactive_data>-usmd_entity_cont.
87
88 ASSIGN COMPONENT 'BP_HEADER' OF STRUCTURE <ls_data> TO FIELD-SYMBOL(<fs_bp>).
89 IF <fs_bp> IS ASSIGNED AND <fs_bp> IS NOT INITIAL.
90 READ TABLE lt_cps TRANSPORTING NO FIELDS WITH KEY partner = <fs_bp>.
91 IF sy-subrc = 0.
92 EXIT.
93 ENDIF.
94 ENDIF.
95
96 ASSIGN COMPONENT 'BU_GROUP' OF STRUCTURE <ls_data> TO FIELD-SYMBOL(<fs_grp>).
97 IF <fs_grp> IS ASSIGNED AND <fs_grp> = 'BPPE'.
98 APPEND <fs_bp> TO lt_cps.
99 EXIT.
100 ENDIF.
101
102 IF <ls_inactive_data>-usmd_entity_cont = 'BP_CENTRL'.
103 ASSIGN COMPONENT 'BPKIND' OF STRUCTURE <ls_data> TO FIELD-SYMBOL(<fs_bpkind>).
104 IF <fs_bpkind> IS NOT ASSIGNED OR ( <fs_bpkind> IS INITIAL OR <fs_bpkind> = 'ZCON' ).
105 EXIT.
106 ENDIF.
107 ENDIF.
108
109 ASSIGN COMPONENT ls_prop-usmd_fieldname OF STRUCTURE <ls_data> TO FIELD-SYMBOL(<fs_attr>).
110 IF sy-subrc = 0 AND <fs_attr> IS ASSIGNED AND <fs_attr> IS INITIAL AND <fs_bp> IS ASSIGNED.
111 LOOP AT lt_roles ASSIGNING FIELD-SYMBOL(<lfs_role>).
112 lv_msg_flg = abap_false.
113
114 IF ls_prop-usmd_entity = <ls_inactive_data>-usmd_entity_cont
115 AND ls_prop-bu_group = id_bu_group
116 AND ls_prop-agr_name = <lfs_role>-agr_name.
117 lv_msg_flg = abap_true.
118 ELSEIF ls_prop-usmd_entity = <ls_inactive_data>-usmd_entity_cont
119 AND ls_prop-bu_group = ''
120 AND ls_prop-agr_name = <lfs_role>-agr_name.The remaining configuration, implementation details, and testing guidance continue from this answer more…
Related questions and keywords
Alternative questions
- How do I add mandatory field validation for supplier change requests in MDG BP?
- How can I validate BP supplier attributes dynamically by change request type and role?
- What is the ABAP pattern for MDG rule-service entity validation of supplier data?
Possible questions
- How do I implement mandatory supplier attribute validation in SAP MDG Business Partner checks?
- How do I add mandatory field validation for supplier change requests in MDG BP?
- How can I validate BP supplier attributes dynamically by change request type and role?
- What is the ABAP pattern for MDG rule-service entity validation of supplier data?
- Which table drives mandatory supplier validation rules in this example?