Sunteți pe pagina 1din 3

Auto fill date & user name

whenever table is updated


This question has been Answered.

Harshada Patil
Nov 20, 2007 10:43 AM

Hi

I have a ztable with date & uname as last two fields. My requirement is whenever user maintains new entry in the table ( thru SM30 - we are giving tcode for Sm30 screen ) , system date & user name should be added along with this record automatically.
We will not display these two fields as input to user. These values should be updated directly.
Somebody told me to write code in module pool for the screen which is generated by table maintainance generator. But I could not proceed.
Pls let me know how this can be acheived.
Regards
Harshada

Correct Answer by Manish Kumar on Nov 20, 2007 10:54 AM


Hi Harshada,
You need to write a code in table Maintenance Events.
Refer the similar issue below.
Requirement:
1. Table Name: ZORDER_RESTRICT.
2. Contains many custom fields + Changed By and Changed
On fields.
3. When any user changes an existing record, I need to populate the Changed By and Changed On fields.
Issue:
1. I have coded the events on SE54 as follows:
FORM Z_MODIFY_USER_INFO_GENERATION.
DATA: F_INDEX LIKE SY-TABIX.
DATA: WA_ZORDER_RESTRICT TYPE ZORDER_RESTRICT.
BREAK-POINT.
LOOP AT TOTAL.
IF <ACTION> = AENDERN.
READ TABLE EXTRACT WITH KEY <VIM_XTOTAL_KEY>.
IF SY-SUBRC EQ 0.
F_INDEX = SY-TABIX.
ELSE.
CLEAR F_INDEX.
ENDIF.
WA_ZORDER_RESTRICT = TOTAL.
WA_ZORDER_RESTRICT-CHANGED_BY = SY-UNAME.
WA_ZORDER_RESTRICT-CHANGE_DATE = SY-DATUM.
TOTAL = WA_ZORDER_RESTRICT.
MODIFY TOTAL.
CHECK F_INDEX GT 0.
EXTRACT = TOTAL.
MODIFY EXTRACT INDEX F_INDEX.
ENDIF.
ENDLOOP.
SY-SUBRC = 0.
ENDFORM. "Z_MODIFY_USER_INFO_GENERATION
2. The event is "01 = Before saving the data in the database".
Extended Table Maintenance Events : Event 01 Before Saving the Data in the Database . I add one Form uoutine as follows code:
FORM change_field_vaule.
DATA: f_index LIKE sy-tabix. "Index to note the lines found
LOOP AT total.
IF <action> = aendern.
READ TABLE extract WITH KEY <vim_xtotal_key>.
IF sy-subrc EQ 0.
f_index = sy-tabix.
ELSE.
CLEAR f_index.
ENDIF.
*Custom code
<b> total-upd_date = sy-datum.
total-uname = sy-uname</b>
modify total.
CHECK f_index GT 0.
extract = total.
MODIFY extract INDEX f_index.
ENDIF.
ENDLOOP.
sy-subrc = 0.

ENDFORM.

"change_field_vaule

Refer to these links below


Do validations on fields while User enters data thru SM30
validation of table entries by table maintenance
<b>Reward points if this helps.
Manish</b>
Message was edited by:
Manish Kumar
See the answer in context

3966 Views

Topics: abap

Average User Rating


(0 ratings)

Manish Kumar
Hi Harshada,

Correct AnswerRe: Auto fill date & user name whenever table is updated

Nov 20, 2007 10:54 AM (in response to Harshada Patil)

You need to write a code in table Maintenance Events.


Refer the similar issue below.
Requirement:
1. Table Name: ZORDER_RESTRICT.
2. Contains many custom fields + Changed By and Changed
On fields.
3. When any user changes an existing record, I need to populate the Changed By and Changed On fields.
Issue:
1. I have coded the events on SE54 as follows:
FORM Z_MODIFY_USER_INFO_GENERATION.
DATA: F_INDEX LIKE SY-TABIX.
DATA: WA_ZORDER_RESTRICT TYPE ZORDER_RESTRICT.
BREAK-POINT.
LOOP AT TOTAL.
IF <ACTION> = AENDERN.
READ TABLE EXTRACT WITH KEY <VIM_XTOTAL_KEY>.
IF SY-SUBRC EQ 0.
F_INDEX = SY-TABIX.
ELSE.
CLEAR F_INDEX.
ENDIF.
WA_ZORDER_RESTRICT = TOTAL.
WA_ZORDER_RESTRICT-CHANGED_BY = SY-UNAME.
WA_ZORDER_RESTRICT-CHANGE_DATE = SY-DATUM.
TOTAL = WA_ZORDER_RESTRICT.
MODIFY TOTAL.
CHECK F_INDEX GT 0.
EXTRACT = TOTAL.
MODIFY EXTRACT INDEX F_INDEX.
ENDIF.
ENDLOOP.
SY-SUBRC = 0.
ENDFORM. "Z_MODIFY_USER_INFO_GENERATION
2. The event is "01 = Before saving the data in the database".
Extended Table Maintenance Events : Event 01 Before Saving the Data in the Database . I add one Form uoutine as follows code:
FORM change_field_vaule.
DATA: f_index LIKE sy-tabix. "Index to note the lines found
LOOP AT total.
IF <action> = aendern.
READ TABLE extract WITH KEY <vim_xtotal_key>.
IF sy-subrc EQ 0.
f_index = sy-tabix.
ELSE.
CLEAR f_index.
ENDIF.
*Custom code
<b> total-upd_date = sy-datum.
total-uname = sy-uname</b>
modify total.
CHECK f_index GT 0.
extract = total.
MODIFY extract INDEX f_index.
ENDIF.
ENDLOOP.
sy-subrc = 0.

ENDFORM.

"change_field_vaule

Refer to these links below


Do validations on fields while User enters data thru SM30
validation of table entries by table maintenance
<b>Reward points if this helps.
Manish</b>
Message was edited by:
Manish Kumar

o
o

Harshada Patil

Alert Moderator

Like (0)

Re: Auto fill date & user name whenever table is updated

Nov 21, 2007 7:57 AM (in response to Manish Kumar)

Thanks for reply.


I got solution for my problem.
I just want to know if table maintenance is generated again , then will it affect my code?

Alert Moderator

Gagan Choudha

Like (0)

Re: Auto fill date & user name whenever table is updated

Nov 20, 2007 11:00 AM (in response to Harshada Patil)

Hi,
I table maintainance generator screen go to environment->modification-->events and then choode events number 5 which is Creating a new entry and then in form routine give any name of routine then in function group one included will be add now u can
code on that include between routine name which u entered earlier.
tables : makt.
form zcreation.
clear makt.
clear zfib_intco.
select single * from zfib_intco where matnr = zfib_mmpg-bismt.
zfib_mmpg-OLDDC = zfib_intco-maktx.
select single * from makt where matnr = zfib_mmpg-matnr and spras = 'EN'.
zfib_mmpg-maktx = makt-maktx.
IF ZFIB_MMPG-MATNR = SPACE.
zfib_mmpg-maktx = 'Blank Material'.
ENDIF.
endform.
here i am attaching a code on which material description autimatically comes while creating the entry through SM30.
Rewards if helpful.

Regards
Gagan

Alert Moderator

Like (0)

Re: Auto fill date & user name whenever table is updated

Harshada Patil

Nov 21, 2007 7:05 AM (in response to Gagan Choudha)

Thanks for reply.


I have created a new routine as
form zauto_update.
zps_auth-syuname = sy-uname.
zps_auth-sydatum = sy-datum.
zps_auth-syuzeit = sy-uzeit.
endform.
but my table is still not getting updated.
pls. help

Alert Moderator

Like (0)

Re: Auto fill date & user name whenever table is updated

Harshada Patil

Nov 21, 2007 7:08 AM (in response to Gagan Choudha)

Thanks for reply.


form zauto_update.
zps_auth-syuname = sy-uname.
zps_auth-sydatum = sy-datum.
zps_auth-syuzeit = sy-uzeit.
endform.
but my table is not getting updated .
pls. help

Alert Moderator

Like (0)

Re: Auto fill date & user name whenever table is updated

Lokesh Aggarwal

Nov 20, 2007 11:28 AM (in response to Harshada Patil)

Hi Harshada,
Goto the table maintenance generator of the Table.
On this screen.
Environment -> Modification -> Events
Create New entry in the table with T = 05 and Z* <any name>
Save it.
An editor button appears next to the from name.
Click on it and create an include.
Write statements.
Tabname-ChangedBy = sy-uname.
Tabname-ChangedOn = sy-datum.
Hope it helps.
Lokesh

Alert Moderator

Like (0)

Re: Auto fill date & user name whenever table is updated

Gagan Choudha

Nov 21, 2007 7:17 AM (in response to Harshada Patil)

Hi,
Event no 5 will work only when you create new entry on Z table u can try event 2 for entry at the time of change.
Rewards if helpful.
Regards
Gagan

Alert Moderator

Like (0)

S-ar putea să vă placă și