cancel
Showing results for 
Search instead for 
Did you mean: 

MDG - Empty list validation

12-04-2023 1:40 PM
1000 views 3 comments
0 Likes
SAP Managed Tags
Subscribe

Hello MDG Experts.

We have a custom data model, where we have an entity type 4 (N:1 relation to an entity type 1), which is a simple list UIBB in the application.

That list cannot be empty, meaning users have to enter at least one row.

We tried several approaches to implement this validation. None of them worked:

1- Entity validation BADI is only triggered when there is some change in the entity. In this case users have not changed anything, the list is initial. So it doesn't work.

2- Cross-entity BADI has Derivation only, no Validation method (weird).

3- BRF+ is not triggered, cannot be debugged and seems far too complex for such a small requirement and short deadline.

Please, anyone who could provide some directions on how to implement something that should be so straightforward ?

Thank you !

0 Likes

Accepted Solutions (0)

Answers (2)

Answers (2)

saikatjay
Participant

Hello Fabio,

Please use the BADI USMD_RULE_SERVICE to implement the validation in CHECK_ENTITY method.

Use external model api IF_USMD_MODEL_EXT to read the data of the SU Type 4 entity. If data is not present, then throw the error message.

The validation must be placed insided the CHECK_ENTITY method without any control statement for parameter ID_ENTITYTYPE which will ensure that your validation is called always for all the round trips of the change request ensuring that the entity data must always be filled.

Regards,

Saikat.

fabiobelloc
Member
0 Likes

Thank you Saikat.

That is exactly what I did, and it worked perfectly !
Code below (CHECK_ENTITY method):

CALL METHOD cl_usmd_model_ext=>get_instance
EXPORTING
i_usmd_model = 'ZP'
IMPORTING
eo_instance = DATA(lr_model).

" Set Prod/Mat entity filter
ls_filter-usmd_entity = 'ZPNS_PROD'.
APPEND ls_filter TO lt_filter.

" Read Prod/Mat data for current Change Request
lr_model->read_entity_data_all( EXPORTING i_fieldname = 'ZPNS'
if_active = ''
i_crequest = id_crequest
it_entity_filter = lt_filter
IMPORTING et_data_entity = lt_data_entity ).

" Check if record exists
READ TABLE lt_data_entity INTO DATA(ls_data_entity) INDEX 1.

" If not, raise error message
IF sy-subrc NE 0.

"Throw error message
ENDIF.


Thank you very much !
ps: can we award points here ?

saikatjay
Participant
0 Likes

Hello Fabio,

I am glad it worked.

Kindly accept my answer and that will award the points.

Thanks and Regards,

Saikat.