- December 29, 2025
- Admin
- 0
Introduction
TMG Events in SAP ABAP play a critical role when you want to control validations, default values, and audit fields during table maintenance using SE11 and SM30. In real SAP projects, relying only on standard Table Maintenance Generator settings is often not sufficient, which is why implementing TMG Events becomes a practical necessity rather than an option.
What Are TMG Events in SAP ABAP?
TMG Events in SAP ABAP are predefined event hooks provided by the Table Maintenance Generator. These events allow developers to inject custom ABAP logic during different stages of table maintenance processing in SM30.
In other words, instead of allowing free data entry, TMG events help you:
Validate user input before saving
Automatically populate default values
Restrict changes based on user roles
Maintain audit fields consistently
As a result, your table maintenance becomes safer, cleaner, and more aligned with business requirements.
Why TMG Events in SAP ABAP Are Required? (Real Project Scenario)
In real-time SAP environments, table maintenance is often used by functional users. However, uncontrolled access may lead to incorrect or inconsistent data. Therefore, using TMG Events in SAP ABAP becomes essential.
Key benefits include:
Preventing invalid or duplicate data entries
Enforcing mandatory fields
Automatically setting values like client, user, or date
Applying logic without modifying standard screens
Moreover, TMG events are transport-friendly and easy to maintain, which makes them ideal for enterprise projects.
TMG Events Used in This Implementation
In this solution, we are using the following events:
Event 05 – Create a New Entry
Used to initialize values during record creation
Event 01 – Before Save
Used to handle both new and updated records just before database commit
Event 05 – Create a New Entry
Event 01 – Before Save
Steps to Configure the TMG Event
Follow the 6 steps carefully for configuring TMG Events
Go to SE11
Enter your custom table name
Choose Utilities → Table Maintenance Generator
Click on Environment → Modifications → Events
Add the following entries:
01 – Before Save
05 – Create a New Entry
Assign the include generated by SAP (do not create a custom report)
Once this setup is done, SAP automatically calls your FORM routines during SM30 execution.
Production-Verified SAP Code
*———————————————————————-*
***INCLUDE L*************
*———————————————————————-*
FORM f_on_create.
<tablename>-createdby = sy-uname.
<tablename>-createdon = sy-datum.
ENDFORM.
FORM f_on_save.
CONSTANTS : lc_new_entry TYPE c VALUE ‘N’,
lc_upd_entry TYPE c VALUE ‘U’.
*–*Note – We cannot use into data of Total/Extract tables, hence used traditionl
*–* Way of implementaion for the below code
LOOP AT total.
IF <action> = lc_new_entry OR <action> = lc_upd_entry.
IF sy-subrc EQ 0.
ASSIGN COMPONENT ‘CHANGEDBY’ OF STRUCTURE <vim_total_struc> TO FIELD-SYMBOL(<lv_ernam>).
IF <lv_ernam> IS ASSIGNED.
<lv_ernam> = sy-uname.
ENDIF.
ASSIGN COMPONENT ‘CHANGEDON’ OF STRUCTURE <vim_total_struc> TO FIELD-SYMBOL(<lv_erdat>).
IF <lv_erdat> IS ASSIGNED.
<lv_erdat> = sy-datum.
ENDIF.
READ TABLE extract WITH KEY <vim_xtotal_key>.
IF sy-subrc EQ 0.
extract = total.
MODIFY extract INDEX sy-tabix.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
Common Mistakes to Avoid
Even experienced developers sometimes misuse TMG events. Therefore, avoid the following mistakes:
Writing complex logic inside multiple events
Hardcoding user IDs or client values
Ignoring transport dependencies
Skipping authorization checks
By avoiding these issues, your implementation remains stable and scalable.
Key Takeaways
TMG events provide a clean and SAP-recommended approach to control table maintenance logic.
Events allow you to populate CREATEDBY, CREATEDON, CHANGEDBY, and CHANGEDON fields automatically.
The Before Save event is ideal for handling validations and audit fields just before database commit.
No modification to standard SAP programs is required, ensuring upgrade safety.
This approach works reliably even when SM30 does not expose traditional PAI/PBO logic.
Conclusion
TMG events are a practical and reliable way to enhance table maintenance behavior in SAP. With minimal code and proper event handling, you can meet real project requirements while keeping the solution clean and easy to maintain.






