Handling Events in Table Maintenance Generator
Sometimes we need to do validations and checks while creating new entries in table. Or we need to store the current date and username in table fields while creating the new entries. Implementing the table maintenance events will be useful in such situations.
Consider the scenario, where we have to store the creation date and user name who updated the record.
Step 1 – Create custom Table.
Custom Table
Field | Table Key | Data Element | Data Type | Length | Text |
MANDT | Yes | MANDT | CLNT | 3 | Client |
CARRID | Yes | S_CARR_ID | CHAR | 3 | Airline Code |
ERDAT | | ERDAT | DATS | 8 | Creation Date |
ERNAM | | ERNAM | CHAR | 12 | Person Created |
Step 2 Create table maintenance Generator.
Go to Utilities-> Table Maintenance Generator.
Authorization Group: &NC&
Function group: Any E.g.: ZEVENTS_TEST
Maintenance type: Two Step
- Maint. Screen no:
Overview screen 100
Single screen 200
Click on Create
Step 3- Create maintenance events
Go to Enviornment->Modification->Events
Click on new entries
List of Events Available.
Click on the event ‘05’ Creating new entry
This event will be triggered while creating a new entry in SM30 or using the TCODE.
FORM Name- any suitable name e.g. CREATE_NEW_ENTRY
Double click on the editor .
Create for ‘create_new_entry’
Create another event: 02 for “After Save”
This will update the entries when any modifications done for the record.
FORM save_entries
.
Zevents_test-mandt = extract+0(3).
Zevents_test-carrid = extract+3(3)..
zevents_test-ERDAT = sy-datum.
zevents_test-ERNAM = sy-uname.
MODIFY zevents_test.
ENDFORM.
After this when you create or change any entry in the custom table, it will update the current date and user name to the table.