Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views2 pages

Update and Create Events in Table Maintenance Gen

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Update and Create Events in Table Maintenance Gen

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Community

 Blog Posts

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.

What are you looking for today?

 Welcome to the New Community!


We are live! Log in now (or register) to
participate in our new SAP Community
platform. Learn about our latest features in
the What's New section.

Update and Create Events in Table


Maintenance Generator

former_member610990
Explorer

09-26-2019 8:54 AM

 38 Kudos

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

1 ------------------------------------------
2 ***INCLUDE LZTEMP_DTLSF01.
3 ------------------------------------------
FORM update.
4
** -- Data Declarations
5
DATA: lv_timestamp TYPE tzonref-tstamps
6 *-- Time stamp conversion
7 CALL FUNCTION 'ABI_TIMESTAMP_CONVERT_INTO'
8 EXPORTING
9 iv_date = sy-datum
10 iv_time = sy-uzeit
11 IMPORTING
12 ev_timestamp = lv_timestamp
13 EXCEPTIONS
conversion_error = 1
14
OTHERS = 2.
15
FIELD-SYMBOLS: <fs_field> TYPE any .
16 LOOP AT total.
17 CHECK <action> EQ aendern.
18 ** -- Updated By
19 ASSIGN COMPONENT 'UPDTD_BY' OF STRUCTURE
20 IF sy-subrc EQ 0.
21 <fs_field> = sy-uname.
22 ENDIF.
** -- Updated On
23
ASSIGN COMPONENT 'UPDTD_ON' OF STRUCTURE
24
IF sy-subrc EQ 0.
25
<fs_field> = lv_timestamp.
26 ENDIF.
27 READ TABLE extract WITH KEY <vim_xtotal_ke
28 IF sy-subrc EQ 0.
29 extract = total.
30 MODIFY extract INDEX sy-tabix.
31 ENDIF.
32 IF total IS NOT INITIAL.
MODIFY total.
33
ENDIF.
34
ENDLOOP.
35 ENDFORM.
36

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

1 ------------------------------------------
2 ***INCLUDE LZTEMP_DTLSF02.
3 ------------------------------------------
4 FORM create.
5 ** -- Data Declarations
6 DATA: lv_timestamp TYPE tzonref-tstamps.
7 *-- Time stamp conversion
8 CALL FUNCTION 'ABI_TIMESTAMP_CONVERT_INTO'
9 EXPORTING
10 iv_date = sy-datum
11 iv_time = sy-uzeit
12 IMPORTING
13 ev_timestamp = lv_timestamp
14 EXCEPTIONS
15 conversion_error = 1
16 OTHERS = 2.
17 ** -- Created On & Created By
18 ztemp_dtls-crtd_by = sy-uname.
19 ztemp_dtls-crtd_on = lv_timestamp.
20 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.

SAP Managed Tags:

ABAP Development

Tags:

TMG Events Update and Create events in TMG

Update Event in TMG

10 Comments

Sandra_Rossi
Active Contributor

09-26-2019 9:41 AM

 2 Kudos

Note that there are some nice explanations in


the SAP documentation "Event 01: Before
Saving the Data in the Database".

ennowulff
Active Contributor

09-27-2019 8:25 AM

 1 Kudo

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!

1 LOOP AT total.
2 CHECK <action> EQ aendern.
3 ** -- Updated By
4 ASSIGN COMPONENT 'UPDTD_BY' OF STRUCTURE

<vim_total_struc> seems to have the first


changed line in the view but not the one you
loop at!

Sandra_Rossi
Active Contributor

09-27-2019 3:49 PM

 2 Kudos

<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

06-01-2020 5:57 PM

 0 Kudos

Thanks for sharing very useful.

gaizka_gonzalez
Explorer

07-07-2020 11:27 AM

 0 Kudos

Thank you so much. Helped me a lot.

poornima12
Discoverer

03-09-2021 3:52 PM

 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.

former_member689892
Member

03-15-2021 9:22 AM

 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

04-19-2021 7:22 PM

 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

10-18-2023 6:33 PM

 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' O


F STRUCTURE <vim_total_struc> TO <fs_field
>.

IF sy-subrc = 0.

IF <fs_field> = zadov_scale_022-
technical_field.

ASSIGN COMPONENT 'ACTIVE' OF STRUCTU


RE <vim_total_struc> TO <fs_field>.
IF sy-subrc = 0.

<fs_field> = space.

ENDIF.

READ TABLE extract WITH KEY <vim_xtotal_k


ey>.

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

10-25-2023 10:00 AM

 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.

 You must be a registered user to add a


comment. If you've already registered,
sign in. Otherwise, register and sign in.

Comment

Labels In This Area


A Dynamic Memory Allocation Tool 1

APIs 5 Automation 2

Career Development 3

Cloud Extensibility 5 Cloud Native 3

Developing at Scale 3

Field Symbols in ABAP 1

Integration & Connectivity 3 OData 1

Programming Models 4 SAP Odata 1

Security 2 Tools 5 user experience 3

Popular Blog Posts

Get Started with the ABAP Development


Tools for SAP NetWeaver

OlgaDolinskaja
Product and Topic Expert

 170501  12  1439

Become an ABAP in Eclipse Feature


Explorer and earn the Explorer Badge

ThFiedler
Product and Topic Expert

 23157  147  366

Six kinds of debugging tips to find the


source code where the message is raised

JerryWang
Employee

 203305  56  317

Top Kudoed Authors

horst_keller  3175

OlgaDolinskaja  2866

hardyp180  2074

matt  1509

ThFiedler  1407

larshp  1225

JelenaP  1170

Michael_Keller  1138

JerryWang  1112

Sandra_Rossi  904

View all

Follow

Privacy Terms of Use

Copyright Legal Disclosure

Trademark Cookie Preferences

You might also like