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

Change Record in Table Maintenace using Events

Former Member
0 Likes
23,053

Hi,

I have a z table and have created table maintenanace for it. In my Z table I have below fields.

delivery no

delivery type

created on

created by

changed on

chnged by

When I am creating a new entry. Created on and Created by are geeting filled automatically using Event 05.

But, When I am trying to change the record any field. Change on and changed By are not getting filled in the maintenace screen as well as in database.

Please let me know how we can handle this.

Thanks in Advance.

Vikas

17 REPLIES 17
Read only

arindam_m
Active Contributor
0 Likes
8,676

Hi,

May be you need to do it in the following event:

01     Before saving the data in the database

Check the below link for further details:

http://wiki.sdn.sap.com/wiki/display/ABAP/TABLE+MAINTENANCE+GENERATOR+and+ITS+EVENTS

Cheers,

Arindam

Read only

0 Likes
8,676

Hi Vikas,

Table maintenance event 5 will be triggered only, when a new entry is created.

Try other events like 01(Before saving) or 02(After Saving) to fill change date and change time while changing a table entry

Hope this Helps

Sreedhar

Read only

Former Member
0 Likes
8,676

Hi,

Use event number 01 to serve your requirement.

And in subroutine,use EXTRACT and TOTAL internal tables to update your database table.

EXTRACT and TOTAL are system defined internal tables.Check for these tables on internet.

This would help you.Let me know if you want more help.

Regards,

Abdul

Read only

0 Likes
8,676

Hi Abdul,

I have checked in Debugging mode and changed the values. It worked. but not sure how we will achieve this through code because the values are coming as text in field LINE.

Please help.

Thanks in Advance.

Vikas

Read only

Venkat_Sesha
Product and Topic Expert
Product and Topic Expert
0 Likes
8,676

Hi Vikas,

How many screen do you have...?

These discussions happened lot of times in SCN. so Please be specific about the issue.

You can achieve it several ways.. Using Events or using PBO/PAI code of the particular screen in the TMG and the Function Group. What is your problem exactly.

Read only

0 Likes
8,676

Hi Vikas,

What is the issue exactly??

Regards,

Abdul

Read only

Former Member
0 Likes
8,676

Hi Vikas,

               you created table key field is delivery no.

can you check the one how to created table entries and events in table maintenance generator

.

http://wiki.sdn.sap.com/wiki/display/ABAP/TABLE+MAINTENANCE+GENERATOR+and+ITS+EVENTS

Read only

SwadhinGhatuary
Active Contributor
0 Likes
8,676

Hello Vikas ,

you have to use  01 event instead of 05 as you already create the record.

01     Before saving the data in the database
02     After saving the data in the database
03     Before deleting the data displayed
04     After deleting the data displayed
05     Creating a new entry
Read only

0 Likes
8,676

Hi,

 

Have to write code for updating the field Change on and changed by.

We can use the Even 01 and create the form routine

The field <VIM_XTOTAL_KEY> contains the key.

For changing the current record, we need to modify both the corresponding extract and total table values.

The <ACTION> field indicates the current user action : new insertion or updation or deletion.

 

FIELD-SYMBOLS: <record> TYPE ANY. " Work area for table

  * Modify changed by and changed on fields for any updates

LOOP AT total.

    * Assign the table header line to the work area

ASSIGN total TO <record>.

IF sy-subrc = 0. " If assigning is successful.

* Check if data was changed and get the corresponding line index

IF <action> = 'U' " Updated entry

Update the changed by and changed on to the total.

Thanks,

Prabakaran

Applexus Technologies

Read only

former_member220538
Active Participant
0 Likes
8,676


Hi Vikas,

The event 05 (New entries) will work only if you create new entries
When changing the data the event 05 will not work.

You have to use the event 01 (Before saving the data).

This event will be triggered when you save the data.

Regards,

Jeffin

Read only

Former Member
0 Likes
8,676

Hi Vikas,

Go to the flow logic of the TMG screen where you input the values to the filled.

Ceck whether your field is included in the

CHAIN.

.

.

.

ENDCHAIN.

Statement in the PAI of the screen.

Please refer this code of such a TMG Screen attached below.

Regards.

Read only

Former Member
0 Likes
8,676

I had this exact problem a month ago and solved it by putting this code in event 01, before saving in the database.

FORM before_save.


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


* Variable TOTAL is not transparent, this structure is how we access

* the individual fields.

  DATA BEGIN OF l_row.

    INCLUDE STRUCTURE zcatsappr_nogl.

    INCLUDE STRUCTURE vimtbflags.

  DATA END OF l_row.

*Add Changed-By and Changed-On for changed entries.

  LOOP AT total.

    CHECK <action> = aendern.

    READ TABLE extract WITH KEY <vim_xtotal_key>.

    IF sy-subrc EQ 0.

      f_indx = sy-tabix.

    ELSE.

      CLEAR f_indx.

    ENDIF.

    l_row = total.

    l_row-changed_on = sy-datum.

    l_row-changed_by = sy-uname.

    total = l_row.

    MODIFY total.

    CHECK f_indx GT 0.

    extract = total.

    MODIFY extract INDEX f_indx.

  ENDLOOP.

  sy-subrc = 0.

  ENDFORM.                    "before_save

The code was adapted from the sample in Event 01: Before Saving the Data in the Database.  Let me know if this doesn't work for you!

Read only

0 Likes
8,676

In my case, the problem wasn't solved. The fields aren't filled when I update data.

Read only

0 Likes
8,676

Use event 21 as change by and change date is for modification history, hence you can keep them as hidden fields by changing the attributes of TMG screen and populate as below. It will work in all scenarios.

  ztab-changedby  = sy-uname.

  ztab-udate     = sy-datum.

  ztab-utime     = sy-uzeit.

Thanks,

Suresh

Read only

0 Likes
8,676

Thanks K Suresh, but it worked when I added <ACTION> = AENDERN. before of  MODIFY total.

Read only

0 Likes
8,676

Thanks with event 21 the field was able to update. Example code as below:

" Populate update date field with today's date

   ztbl-udate = sy-datum.


" If Update then modify table

   IF <action> = aendern.

     MODIFY ztbl.

   ENDIF.


Thanks once again

Read only

Former Member
0 Likes
8,676

I normally use Event 21 to fill the Changed by and Changed on fields.