Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Issue with Table Maintenance Generator event

ilyasahmed
Explorer
4,063

Hello Everyone,

I have a requirement in TMG to have fields Created by and changed by filled programmatically.

I created TMG and was able to implement created by field with username using event no 5 i.e. create a new entry.

The issue i have is with field Changed by. When a user edits an entry or several entries i need to add the user name in Changed by field. I am unable to implement this step. I tried with event 18 i.e. After checking whether the data has changed, but i get only the last record in structure.

Thanks,

Ilyas

1 ACCEPTED SOLUTION
Read only

ilyasahmed
Explorer
1,886

Hello Everyone.

Finally i implemented the requirement.

The changed by field is now programatically added with user name.

The code is same as above except for a statement which put me in lot of trouble and found it after several debugging recursions.

<action> = 'U'.

MODIFY total.

before modify total the statement <action> = 'U'. needs to be added.

after modify the <action> was changed because of which it was not saving to database.

Thanks for the support and i hope this issue will be a reference for those who wish to modify TMG entries before save.

Thanks,

Ilyas Ahmed

6 REPLIES 6
Read only

JackGraus
Active Contributor
0 Likes
1,886

Hi, have been using event AB (database changes) for this.

Parts of my coding are:

FORM event_ab.

LOOP AT total.
CHECK <action> IS NOT INITIAL.

ASSIGN COMPONENT 'AEDAT' OF STRUCTURE total TO <zlv_aedat>.
<zlv_aedat> = syst-datum.

ENDLOOP.
PERFORM db_upd_zvmemvbrp.

ENDFORM.

Regards Jack

Read only

former_member191735
Active Contributor
0 Likes
1,886

>

> Hello Everyone,

>

> I have a requirement in TMG to have fields Created by and changed by filled programmatically.

>

> I created TMG and was able to implement created by field with username using event no 5 i.e. create a new entry.

>

> The issue i have is with field Changed by. When a user edits an entry or several entries i need to add the user name in Changed by field. I am unable to implement this step. I tried with event 18 i.e. After checking whether the data has changed, but i get only the last record in structure.

>

>

> Thanks,

>

> Ilyas

05 should be alright.

I have the same in View... Here is the code you need to add in the form routine.

assuming my view name is: yview_v

yview_v-changed_by = sy-uname.

That simple step will add the user name who changed the object.

Read only

0 Likes
1,886

Hi Ahmed,

Can you provide the part of code which is not working in event "05"?

Regards,

Ramnivas

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,886

Hello Ilyas,

Why don't you use the Event 01(Before Saving the Data in the Database) for this purpose? Read this documentation for further details: [Event 01: Before Saving the Data in the Database|http://help.sap.com/saphelp_nw04/helpdata/en/91/ca9f0ba9d111d1a5690000e82deaaa/content.htm]

@Others: I have never tried it though. But will Event 05(When Creating a New Entry) trigger if you change a field value? As per SAP:

This event occurs when a new entry is made with the function 'New entry' or 'Copy'

BR,

Suhas

Read only

ilyasahmed
Explorer
0 Likes
1,886

Thanks for all your replies.

Hi i have added below code in event 01 i.e before saving to DB.

LOOP AT total.

READ TABLE extract WITH KEY <vim_xtotal_key>.

IF sy-subrc EQ 0.

f_indx = sy-tabix.

ELSE.

CLEAR f_indx.

ENDIF.

IF <action> = 'U'. "Entry changed

*added code to capture changed by

MODIFY total.

CHECK f_indx GT 0.

extract = total.

MODIFY extract INDEX f_indx.

ENDIF.

ENDLOOP.

sy-subrc = 0.

This code is displaying the changed by with user name on the SM30 screen as intended.

But the issue is its not saving to database. the changes done along with other fields is not saved to database

When i comment the code in the event 01, i get the changes saved.

Is there any field that needs to be set in order to save the changes in database.

Read only

ilyasahmed
Explorer
1,887

Hello Everyone.

Finally i implemented the requirement.

The changed by field is now programatically added with user name.

The code is same as above except for a statement which put me in lot of trouble and found it after several debugging recursions.

<action> = 'U'.

MODIFY total.

before modify total the statement <action> = 'U'. needs to be added.

after modify the <action> was changed because of which it was not saving to database.

Thanks for the support and i hope this issue will be a reference for those who wish to modify TMG entries before save.

Thanks,

Ilyas Ahmed