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

Update database table with username and date

Former Member
0 Likes
5,404

Hi all,

Happy new year 2007..!

I have created a Z table which is maintained via SM30. Is it possible by any means that the username of the person updating the table and the date in which the updation is done can be entered in the same table automatically...

Please help (very Urgent!!)

Thanks in advance.....

Message was edited by:

pranati dalvi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,548

Hi,

Use the event '01' which is before saving..

Also paste your code that you have in your subroutine..

Thanks,

Naren

21 REPLIES 21
Read only

Former Member
0 Likes
3,548

Hi,

You can use SM30 events..Check this..

Go to the view V_TVIMF.

Add an entry with the following entry.

EVent - '01' (Before saving the data in the database)

Form rourtine - 'ADD_USERNAME'

Save the entry in a CR.

Then in the function group that you created for the table maintenance add this subroutine..

FORM ADD_USERNAME.

  • Types Declaration

DATA: BEGIN OF WA_ZTABLE.

INCLUDE STRUCTURE ZTABLE.

DATA: update_fl TYPE char1,

mark TYPE char1,

END OF WA_ZTABLE.

LOOP AT TOTAL.

WA_ZTABLE = TOTAL.

<b>WA_ZTABLE-USER_NAME = SY-UNAME.

WA_ZTABLE-USER_TIME = SY-UZEIT.</b>

TOTAL = WA_ZTABLE.

MODIFY TOTAL.

ENDLOOP.

ENDFORM.

Thanks,

Naren

Read only

0 Likes
3,548

Hi Naren,

Thank you so much for your help and prompt reply..

can you please tell me where exactly in the function group i have to write..i did not create a function group for table maintenance. I used an existing one. so is it okay to modify it if I have to...

Thanks again for your help..

Read only

0 Likes
3,548

Hi Pranati,

Check out this weblog in SDN which explains about maintaing custom subroutine in the view v_tvimf.

/people/sudheer.cheedella/blog/2006/02/20/extracting-data-in-table-maintenance

Above link will give you an immediate idea of creating a subroutine. Then, as mentioned by others, create two fields with data elements 'LAEDA' and 'AENAM'. Once this is done, include following code in your custom subroutine for this table.

move: sy-uname to ZTABLE-MODIFIED_BY,

sy-datum to ZTABLE-MODIFIED_ON.

That's it. You will be done. )

Try it and if you can't finish, mention your email and I will send you a word document which has all these step by step.

Thanks and have a nice day

Regards,

Vivek

Read only

0 Likes
3,548

Hi vivek,

Thank you for the link. That was very informative.

But still the values are not getting populated.

I created the table fields. but they are not showing up in the element list of the screens mentioned in the maintenance screen. is the problem because of this ?

I succeeded in creating the include, the sub routine, and i wrote the code like

----


***INCLUDE LZH_TABLE_GENF01 .

----


form get_uname_date.

move sy-datum to zfpbtc-aedtm.

move sy-uname to zfpbtc-uname.

endform. " get_uname_date

can u please tell me wht could be wrong..

please bear with me, I am little slow in picking up !!... my mail is

[email protected]

can u please send the document you said about..

Read only

0 Likes
3,548

Hi Pranati,

What Naren said is correct, you have to delete and create new screens for maintaing when ever you touch the table fields. Also, once you create new screens, go to se14 (database utility), activate and adjust database selecting 'save data' option. This will readjust the table.

Anyway, I will send you the document to email id mentioned.

Regards,

Vivek

Read only

Former Member
0 Likes
3,548

in ur ztable declare the 2 fields....Now, for these fields write a routinue inside as to populate sy-uname & sy-datum. So, when user uses SM30 automatically these columns are been filled.

Read only

Former Member
0 Likes
3,548

Hi,

go to SE80..

Give the function group name..Press display (glass) button ..

Doube click on the function group (Under the text "Object name")..

It will give a popup..Press main program button..

Go to the change mode (Ctrl + F1)..

In the last line of the code..give..

INCLUDE Z_CUSTOM_ROUTINES. "Or whatever name you give.

Double click on the Z_CUSTOM_ROUTINES..

It will ask you to create a include..

Continue to create..

Here in the include give the subroutine code..

FORM ADD_USERNAME.

.....

ENDFORM.

Please reward points for helpful answers..

Thanks,

Naren

Read only

0 Likes
3,548

Hi Naren,

Thank you for your reply..! I am working on similar lines..

- Pranati

Read only

Former Member
0 Likes
3,548

Hi,

If the new fields are appearing on the screen..

Regenerate the table maintenance in SE11 to have the new fields..

Please reward points for helpful answers..

Thanks,

Naren

Read only

0 Likes
3,548

Hi Naren/Vivek,

I think finally I am nearing a solution..! I had put the event value as 02 and i gave the code as Naren had mentioned earlier. so in the edit screen the username and date comes as soon as i save. but if i take se11 in a new session and try to see the table contents, the values disappears..

Will event 05 help.. my requirement is that the username and date should appear when the table data is created/changed.

regarding points.. this is my first query in sdn..so can u pls tell me if i can give points for all the replies i get..or is it to be given after the question is answered

Thanks

Pranati

Message was edited by:

pranati dalvi

Message was edited by:

pranati dalvi

Message was edited by:

pranati dalvi

Read only

0 Likes
3,548

Hi Naren,

form set_uname_date.

  • Types Declaration

data begin of l_t_zfpbtc.

include structure zfpbtc.

data: l_update_fl type char1.

data: l_mark type char1.

data end of l_t_zfpbtc.

loop at total.

l_t_zfpbtc = total.

l_t_zfpbtc-uname = sy-uname.

l_t_zfpbtc-aedtm = sy-datum.

total = l_t_zfpbtc.

modify total.

endloop.

endform. "SET_UNAME_DATE

This is the code i gave

Read only

0 Likes
3,548

Hi Narendra

I have got tipical problem while modifying the user & time while changing the entries through SM30.

Created a routine from V_TVIMF view.

Since my table contains some of the key fields as DEC , I could not populate my ztable from total, instead I;m using to populate only change_by and Change_time from total and vice versa.

So it does change to the SSM30 screen when I click on save but not the database save, means once i go to display mode in the SM30 the changes get refereshed to old values.

Any idea to resolve this issue highly appreciated.

Thanks a lot.

Sarika

Here is my code.

DATA: f_index LIKE sy-tabix. "Index to note the lines found

DATA BEGIN OF total_s.

INCLUDE STRUCTURE zds_sheet_trim.

DATA action.

DATA mark.

DATA END OF total_s.

DATA extract_s LIKE total_s.

DATA: ls_time TYPE ttztstmp.

*

**// Set the change user and change time

ls_time-date = sy-datum.

ls_time-time = sy-uzeit.

LOOP AT total.

IF <action> = 'U'.

  • MOVE total TO total_s.

  • total+83 = total_s-change_by.

  • total+95 = total_s-change_time.

READ TABLE extract WITH KEY total.

IF sy-subrc EQ 0.

f_index = sy-tabix.

  • extract_s = extract.

extract_s-change_time = ls_time.

extract_s-change_by = sy-uname.

ELSE.

CLEAR f_index.

ENDIF.

  • (make desired changes to the line TOTAL)

total_s-change_time = ls_time.

total_s-change_by = sy-uname.

total+83 = total_s-change_by.

total+95 = total_s-change_time.

MODIFY total.

CHECK f_index GT 0.

extract = total.

MODIFY extract INDEX f_index.

ELSEIF <action> = 'N'.

  • MOVE total TO total_s.

READ TABLE extract WITH KEY total.

IF sy-subrc EQ 0.

f_index = sy-tabix.

extract_s = extract.

ELSE.

CLEAR f_index.

ENDIF.

  • (make desired changes to the line TOTAL)

total_s-change_time = ls_time.

total_s-change_by = sy-uname.

total+83 = total_s-change_by.

total+95 = total_s-change_time.

MODIFY total.

CHECK f_index GT 0.

extract = total.

MODIFY extract INDEX f_index.

ELSEIF total IS INITIAL.

total+83 = total_s-change_by.

total+95 = total_s-change_time.

READ TABLE extract WITH KEY total.

IF sy-subrc EQ 0.

f_index = sy-tabix.

  • extract_s = extract.

extract_s-change_time = ls_time.

extract_s-change_by = sy-uname.

ELSE.

CLEAR f_index.

ENDIF.

  • (make desired changes to the line TOTAL)

DELETE total.

CHECK f_index GT 0.

DELETE extract INDEX f_index.

ENDIF.

ENDLOOP.

sy-subrc = 0.

ENDFORM. "get_transaction_data

Read only

Former Member
0 Likes
3,549

Hi,

Use the event '01' which is before saving..

Also paste your code that you have in your subroutine..

Thanks,

Naren

Read only

0 Likes
3,548

Hi Naren,

I put 01 and it is working....!!!

Thank you SO much..without you and Vivek it would not have been possible.

Thanks...

-Pranati.

Read only

Former Member
0 Likes
3,548

Hi,

B.T.W..Is it two screen maintenance or single screen maintenance..

Thanks,

Naren

Read only

0 Likes
3,548

Hi Naren,

It is one screen maintenance.

Pranati.

Read only

Former Member
0 Likes
3,548

Hi,

You are welcome..

Thanks,

Naren

Read only

Former Member
0 Likes
3,548

Hi,

One more thing..I would like to add in your code..Marked in bold..

form set_uname_date.

  • Types Declaration

data begin of l_t_zfpbtc.

include structure zfpbtc.

data: l_update_fl type char1.

data: l_mark type char1.

data end of l_t_zfpbtc.

loop at total.

l_t_zfpbtc = total.

<b>* check if a new entry is inserted or an existing is updated..</b>

<b>CHECK l_t_zfpbtc-l_update_fl = 'U' OR l_t_zfpbtc-l_update_fl = 'N'.</b>

l_t_zfpbtc-uname = sy-uname.

l_t_zfpbtc-aedtm = sy-datum.

total = l_t_zfpbtc.

modify total.

endloop.

endform. "SET_UNAME_DATE

Thanks,

Naren

Read only

0 Likes
3,548

Hi

Thanks again !!

Pranati.

Read only

Former Member
0 Likes
3,548

Hi,

Please create a new thread for your question.

Thanks

Naren

Read only

0 Likes
3,548

hi ,

Its giving the problem 'Total is not defined'.