Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
Showing results for 
Search instead for 
Did you mean: 
Active Contributor

In this blog post, I would like to show you how to validate data on maintenance view screen before save.

Maintenance views are very useful interfaces to create a viewer and editor for database tables. And with events and search helps, we can make them even more useful.

In this blog post, we will create a table, where we can map company codes to special ranges for purchase orders. Table will have only 3 fields, client, company code and range. Before saving data on maintenance view, we will check both company code and range and if they are not valid we will warn user and will not let data to be saved.



Table Structure


Open Maintenance View

I assume you have created a maintenance view. And willing to add event to validate data. If you don’t know how to create maintenance view, please read on that link.

Add Event to Maintenance View


Add event before save and give a form name to be called when event is triggered.

Add Event and Form Name


Code Block

Click open editor and create form that you have given above ( BEFORE_SAVE in that example)


Above, from line 9 to 15 are used to collect new records or changed records data to recs internal table. total table contains all records and when we loop on total records, <vim_total_struc> field-symbol is assigned, by checking <action> field-symbol we can learn about state of record, if it is new or updated or being deleted.

Later on line 19, recs table is passed to a class that contains validation logic. That class method returns a status structure. If result is not success. we are setting vim_abort_saving abap_true on line 21. In that way, saving will not happen.

And we are showing message to inform user on line 22.

Here are the lines, that will be useful for you.
FORM before_save.
"Collect records to be checked
DATA : recs TYPE TABLE OF zmm_t_po_nr_cust,
rec TYPE zmm_t_po_nr_cust.
LOOP AT total.
IF <vim_total_struc> IS ASSIGNED AND ( <action> EQ 'N' OR <action> EQ 'U' ).
CLEAR rec.
MOVE-CORRESPONDING <vim_total_struc> TO rec.
APPEND rec TO recs.

"Validate changes
"Place your logic below
DATA(status) = zmm_cl_po_numbering=>validate_new_entries( recs = recs ).
IF status-status NE zutils_cl_defs=>c_stat_success.
vim_abort_saving = abap_true. "To abort saving
MESSAGE status-status_text TYPE 'S' DISPLAY LIKE 'E'.



Activate your changes and go to sm30 to test.

Try to save data with invalid company code


That is all. I hope that is useful for you.

Thanks for reading.


Reference Links
Labels in this area