Skip to Content
Technical Articles

Update and Create Events in Table Maintenance Generator

INTRODUCTION:

I got the requirement to capture the Created by Created on and Updated by Updated on logs for the custom table using Table Maintenance Generator events.

Here is the step by step process to capture the table change logs.

Step 1:

Create a custom table. 

Step 2:

Click on utilities, go to table maintenance generator.

Step 3:

Enter the details of the function group, propose screen numbers and click on save, we will provide the package name.

There are two different maintenance screen types

  1. one step and
  2. Two step

one step

  • In one step we will have only overview screen.
  • Will able to see and maintain only through the overview screen.

Two step

  • We will have two screens. overview screen and Single/Detail screen.
  • overview screen will contain key fields and Single screen will contain all the other fields.

Step 4:

For TMG events, In menu Click on Environment–>Modifications–>Events

Following screen will be displayed. From the below list i have used Update and Create Events.

Update Event

Select the Update event and press enter, the following screen will appear.

Source Code

----------------------------------------------------------------------
***INCLUDE LZTEMP_DTLSF01.
----------------------------------------------------------------------
FORM update.
** -- Data Declarations
DATA: lv_timestamp TYPE tzonref-tstamps.
*-- Time stamp conversion
CALL FUNCTION 'ABI_TIMESTAMP_CONVERT_INTO'
EXPORTING
iv_date = sy-datum
iv_time = sy-uzeit
IMPORTING
ev_timestamp = lv_timestamp
EXCEPTIONS
conversion_error = 1
OTHERS = 2.
FIELD-SYMBOLS: <fs_field> TYPE any .
LOOP AT total.
CHECK <action> EQ aendern.
** -- Updated By
ASSIGN COMPONENT 'UPDTD_BY' OF STRUCTURE <vim_total_struc> TO <fs_field>.
IF sy-subrc EQ 0.
<fs_field> = sy-uname.
ENDIF.
** -- Updated On
ASSIGN COMPONENT 'UPDTD_ON' OF STRUCTURE <vim_total_struc> TO <fs_field>.
IF sy-subrc EQ 0.
<fs_field> = lv_timestamp.
ENDIF.
READ TABLE extract WITH KEY <vim_xtotal_key>.
IF sy-subrc EQ 0.
extract = total.
MODIFY extract INDEX sy-tabix.
ENDIF.
IF total IS NOT INITIAL.
MODIFY total.
ENDIF.
ENDLOOP.
ENDFORM.

Once the code is completed then we need check and activate the include.Here we need to activate the below two objects.

Create Event

Select the Create event and press enter, the following screen will appear.

Same process we have to go for the Create event.

Source Code

----------------------------------------------------------------------
***INCLUDE LZTEMP_DTLSF02.
----------------------------------------------------------------------
FORM create.
** -- Data Declarations
DATA: lv_timestamp TYPE tzonref-tstamps.
*-- Time stamp conversion
CALL FUNCTION 'ABI_TIMESTAMP_CONVERT_INTO'
EXPORTING
iv_date = sy-datum
iv_time = sy-uzeit
IMPORTING
ev_timestamp = lv_timestamp
EXCEPTIONS
conversion_error = 1
OTHERS = 2.
** -- Created On & Created By
ztemp_dtls-crtd_by = sy-uname.
ztemp_dtls-crtd_on = lv_timestamp.
ENDFORM.

Check  and activate it.

Step 5:

Now To test the Update and Create events Go to Table maintenance generator ( SM30 Tcode) and Click on maintain button as per shown below.

Next, Create the data by clicking on new entries and click on save then we will able to see the Create logs.

Update the existing data then click on save, then we will able to see the Update logs.

Conclusion:

By following the above steps,we are able to see the table create and update logs for a custom table, which contains the fields “Date on which record was created” and “Name of the person who created the object”.

 

Thanks for reading.

 

 

3 Comments
You must be Logged on to comment or reply to a post.
  • Hey Roja, thanks for sharing!

    In this special requirement you should create a separate view for the table and mark the log fields as “read-only” so they cannot be changed by the user. Also it makes clear that the user does not has to enter values here.

    Also check event “21 – fill hidden fields” for this case.

    btw: I am sure that below code does not work correctly!

    LOOP AT total.
    CHECK <action> EQ aendern.
    ** -- Updated By
    ASSIGN COMPONENT 'UPDTD_BY' OF STRUCTURE <vim_total_struc> TO <fs_field>.

    <vim_total_struc> seems to have the first changed line in the view but not the one you loop at!

    • <vim_total_struc> is a global field symbol which is assigned by SAP, at the very beginning of the initialization of the dialog program, via ASSIGN total TO <vim_total_struc>, so it should work.