Skip to Content
author's profile photo Former Member
Former Member

Auto fill date & user name whenever table is updated

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 09:51 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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 10:00 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 20, 2007 at 10:28 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 21, 2007 at 06:17 AM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.