We can implement events to the table maintenance to have additional functionalities such as authorization checks, populating audit trails information and etc. during entry creation, before and after saving data in the database, before and after deleting data displayed and etc., just to name a few.
A custom table with table maintenance Display/Maintenance Allowed. Please refer to the article Table Maintenance.
First, go to transaction code SE11 -> Utilities -> Table Maintenance Generator to change the required custom table.
Next, go to Environment -> Events.
Click New Entries to create a new event.
Click the Search icon to choose a suitable maintenance event.
Each event has their own use case. For this example, we will use 01 Before saving the data in the database.
Maintain the form routine name. Click Save and click the Editor button.
Press Enter again.
At here, you can include the required business logic. Always enclose the business logic with the form routine maintained previously. Otherwise, you will encounter an error that this business logic is not accessible.
For line no. 5, the structure is the structure of the custom table.
Total consists of all existing and new table entries. For entries that are:
- Newly inserted,
VIM_ACTIONfield will indicate N
VIM_ACTIONfield will indicate U
VIM_ACTIONfield will indicate D
Custom business logic(s) may be implemented according to various insert, update or delete operations. Activate the code once it is completed.
FORM check_data. TYPES: BEGIN OF lty_total. INCLUDE STRUCTURE zsf_test. INCLUDE STRUCTURE vimtbflags. TYPES: END OF lty_total. FIELD-SYMBOLS: <ls_total> TYPE lty_total. LOOP AT total ASSIGNING <ls_total> CASTING. IF <ls_total>-vim_action = neuer_eintrag OR "New entry <ls_total>-vim_action = aendern OR "Update entry <ls_total>-vim_action = vim_ds_loeschen. "Delete entry "Perform any custom logic here ENDIF. ENDLOOP. ENDFORM.
When inserting a new entry via transaction code SM30,
VIM_ACTION will indicate N.
When updating an existing entry via transaction code SM30,
VIM_ACTION will indicate U.
When deleting an existing entry via transaction code SM30,
VIM_ACTION will indicate D.
P/S: Please take note for Maintenance Event 02 After saving the data in the database,
VIM_ACTION will always be empty. Thus, if the requirement is to have business logic according to insert, update or delete of specific entries, this event is not suitable to be used.