TMG Events
In SAP ABAP, TMG (Table Maintenance Generator) events are used to customize the behavior of table maintenance dialogs generated by the Table Maintenance Generator. The Table Maintenance Generator is a tool provided by SAP that allows developers to create basic maintenance screens for database tables without having to write extensive ABAP code.
TMG events are predefined function modules that are called at specific points during the execution of the table maintenance dialog. These events provide developers with hooks to add custom logic or validations to the standard table maintenance process without modifying the generated code.
Some common TMG events in SAP ABAP include:
- BEFORE OUTPUT: This event is triggered before the maintenance screen is displayed. Developers can use this event to modify the screen layout or initialize screen fields.
- AFTER INPUT: This event is triggered after the user enters data on the maintenance screen and clicks the save button. Developers can use this event to validate user input or perform additional processing before saving the data to the database.
- BEFORE SAVE: This event is triggered before the data is saved to the database. Developers can use this event to perform additional validations or modifications to the data.
- AFTER SAVE: This event is triggered after the data has been successfully saved to the database. Developers can use this event to perform post-save processing or trigger additional actions.
By leveraging TMG events, developers can enhance the standard table maintenance functionality provided by SAP and tailor it to meet specific business requirements without having to create custom maintenance screens from scratch.
- Create a Table with below fields.
- Create a TMG.
- Click on menu icon Environemet --Modification -- Events
- Select event from drop down and enter form name 'CREATE_ENTRY' and click on 'Editor'.
- Select the include in which you want to Write the code and write the below code.
*----------------------------------------------------------------------*
***INCLUDE LZVBEMP_DTLS1F01.
*----------------------------------------------------------------------*
FORM CREATE_ENTRY.
ZVBEMP_DTLS1-CRTD_BY = SY-UNAME.
ZVBEMP_DTLS1-CRTD_ON = SY-DATUM.
ZVBEMP_DTLS1-CRTD_AT = SY-UZEIT.
ENDFORM.
- Like this write the code for other events.
FIELD-SYMBOLS:<lr_col> TYPE scxtab_column.
LOOP AT <vim_tctrl>-cols ASSIGNING <lr_col>.
IF <lr_col>-screen-name = 'ZVBEMP_DTLS1-CRTD_BY' OR
<lr_col>-screen-name = 'ZVBEMP_DTLS1-CRTD_ON' OR
<lr_col>-screen-name = 'ZVBEMP_DTLS1-CRTD_AT' OR
<lr_col>-screen-name = 'ZVBEMP_DTLS1-UPDTD_BY' OR
<lr_col>-screen-name = 'ZVBEMP_DTLS1-UPDTD_ON' OR
<lr_col>-screen-name = 'ZVBEMP_DTLS1-UPDTD_AT' .
<lr_col>-screen-input = 0.
ENDIF.
ENDLOOP.
ENDFORM.
FORM CHANGE_RECORD.
IF ZVBEMP_DTLS1-CRTD_BY IS NOT INITIAL.
ZVBEMP_DTLS1-UPDTD_BY = SY-UNAME.
ZVBEMP_DTLS1-UPDTD_ON = SY-DATUM.
ZVBEMP_DTLS1-UPDTD_AT = SY-UZEIT.
ENDIF.
ENDFORM.
Comments
Post a Comment