How to Validate Data on Maintenance View(SM30) Before Save
source link: https://blogs.sap.com/2023/03/21/how-to-validate-data-on-maintenance-viewsm30-before-save/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to Validate Data on Maintenance View(SM30) Before Save
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
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)
FORM Content of BEFORE_SAVE
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.
ENDIF.
ENDLOOP.
"Validate changes
IF recs IS NOT INITIAL.
"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'.
ENDIF.
ENDIF.
ENDFORM.
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 Link
https://blogs.sap.com/2015/10/29/validate-data-in-table-maintenance-generator-event/
Recommend
-
7
Before handing off a maintenance project (or really any project), here are items you should document or get from the client or the previous person who worked on it...
-
5
Get a common view of asset maintenance across your chemicals business ...
-
3
Anuja Kawadiwale June 26, 2022 4 minute read...
-
3
pg_ivm The pg_ivm module provides Incremental View Maintenance (IVM) feature for PostgreSQL. The extension is compatible with PostgreSQL 13 and 14. Description Incremental View Maintenance (IVM)...
-
6
July 15, 2022 ...
-
6
Search Questions and Answers
-
8
Ranked #17 for todayValideateValidate ideas before spending time & money on itValideate is an idea validation tool and community. It he...
-
4
Save Money and Hassle with Routine Appliance Repair Maintenance How Regular Maintenance Can Extend the Lifespan of Your Appliances and...
-
3
SM30 Rant And Mass Data Input Idea Recently there was a question in the german DSAG Community if there is a trick to insert more lines at once into the table maintenance dialog than there are on the screen. Short answer: T...
-
3
Support is great. Feedback is even better."We are hustling to find out the most important pain points of people on their way to book a fitting stay. Please help us with your feedback!"The makers of AIReview
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK