Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
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.

 

 
10 Comments
Sandra_Rossi
Active Contributor
ennowulff
Active Contributor
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!
Sandra_Rossi
Active Contributor
<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.
sundarjeevaraj
Explorer
0 Kudos
Thanks for sharing very useful.
gaizka_gonzalez
Explorer
0 Kudos
Thank you so much. Helped me a lot.
poornima12
Discoverer
0 Kudos
thanks for sharing this code. I had other query in one step its using very well. but how to create and update two step in table maintenance generator? if anyone know please share.
0 Kudos
Perfect!

Have been struggling with the change solution on a view of mine.

Then I googled and found your solution  - which works perfect !

 

Thanks

/Lars
ashwinv22
Explorer
0 Kudos
can we create a single include for different event ? I see it always ask for new include for each event
gabriel_redware
Explorer
0 Kudos
Thank you so much. Helped me a lot.

but i made this changes below on my source code.

LOOP AT total.

ASSIGN COMPONENT 'TECHNICAL_FIELD' OF STRUCTURE <vim_total_struc> TO <fs_field>.

IF sy-subrc 0.

IF <fs_field> zadov_scale_022-technical_field.

ASSIGN COMPONENT 'ACTIVE' OF STRUCTURE <vim_total_struc> TO <fs_field>.
IF sy-subrc 0.

<fs_field> space.

ENDIF.

READ TABLE extract WITH KEY <vim_xtotal_key>.

IF sy-subrc 0.

extract total.

MODIFY extract INDEX sy-tabix.

ENDIF.

IF total IS NOT INITIAL.

MODIFY total.

ENDIF.

ENDIF.

ENDIF.

ENDLOOP.
vincenzocappelluti
Participant
0 Kudos

This works perfectly!! Thank you!

I only use sy-datum instead of 'ABI_TIMESTAMP_CONVERT_INTO' function. It is more clear and efficient.