Application Development 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: 

Problem: Events in Table Maintenance

Former Member
0 Kudos

Hi,

I am currently working on events in table maintenance... It is not working properly. My objective is to save automatically four fields; changed_on, changed_by, created_by, and created_on.

I used event 02 (after saving) , 01 (before saving) , and 05 (create new). The problem is when I update the table it does not reflect the changes.

my code in the update is:

IF ztab-CREATED_ON IS INITIAL.

MOVE SY-DATUM TO ztab-CREATED_ON.

ENDIF.

IF ztab_Created_BY IS INITIAL.

MOVE SY-UNAME TO ztab-CREATED_BY.

ENDIF.

MOVE SY-DATUM TO ztab-LCHANGED_ON.

MOVE SY-UNAME TO ztab_-LCHANGED_BY.

Someone told me to use the table TOTAL. I am not quite sure how to use it.

Please help me regarding this problem...

Thanks in advance!

Regards,

Mike

10 REPLIES 10

Former Member
0 Kudos

Hi,

As you already mentioned that table TOTAL has to be used to update the table fields at runtime in the Event.

Suggest you to put a break point in the event and check for content in internal table Total and Extract.

You will get a good idea what exactly you have to do.

Refer to these links below

Refer similar code required below.

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_CHANGED_ON = SY-DATUM.

WA_CHANGED_BY = SY-UNAME.

..

...

MODIFY TOTAL.

CHECK F_INDEX GT 0.

EXTRACT = TOTAL.

MODIFY EXTRACT INDEX F_INDEX.

ENDIF.

<b>Reward points if this helps.

Manish</b>

0 Kudos

Hi Manish,

How could the WA_CHANGED_ON and WA_CHANGED_BY be transferred to TOTAL? thanks in advance!

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_CHANGED_ON = SY-DATUM.

WA_CHANGED_BY = SY-UNAME.

..

...

MODIFY TOTAL.

CHECK F_INDEX GT 0.

EXTRACT = TOTAL.

MODIFY EXTRACT INDEX F_INDEX.

ENDIF.

Former Member
0 Kudos

hi,

We have a following custom table which contains the fields “Date on which record was created” and “Name of the person who created the object”. We would like to have these to be filled up with SY-DATUM and SY-UNAME respectively.

Using the events, we can achieve this.

Please refer the following link:

http://abapliveinfo.blogspot.com/2007/12/events-in-table-maintenance-in-sap.html

Also,

Write a form routine in table maintanance generator.

1. SE11 > utilities > table maintenance generator

2. environment > modification > event

define the event and form routine to make use of the tigger. in the form routine define an object for the class and call the relevant method.

Or u can do it as:

Table maintenance generator is basically used to do table operations like (insert, delete, modify...).

if you create table maintenance for your table it will build a module pool program, by using you do the above operations.

below is the procedure to create table maintenance generator.

1) Create one function group.

2) after activating your Ztable, choose 'Utilities'----> 'Table maintenance genrator'.

3) then give the authorization group and function group created abobe in the next screen.

4) Then choose the "create" button in your application tool bar, which will creates the module pool program.

5) then create one Tcode by chosing "Transaction with parameters( parameter transaction)".

6) in transaction field give "SM30", select the check box "Skip initial screen".

7) in the below of that screen you can find the "Default values" frame.

😎 there under the "name of screen field" select the "View name' and 'update".

9) in value column against to "view name" give you table name, and against to "Update" put 'X' in capital letters.

save it then you can straight away use this newly created Tcode to maintain your table.

Note:- 1) make the modification while saving the data into your table using this newly generated program to carry out your validation (even though it looks like standard program; no need to enter the access key).

2) if you do any changes to your table and press the activate button automatically the table maintenace generator will be goes off, you need to create this again.

cheers,

Hema.

Former Member
0 Kudos

Hi,

I am now using this code:

LOOP AT TOTAL.

MOVE TOTAL to lwa_total.

IF <ACTION> = AENDERN OR <ACTION> = NEUER_EINTRAG.

READ TABLE EXTRACT WITH KEY <vim_xtotal_key>.

IF SY-SUBRC EQ 0.

F_INDEX = SY-TABIX.

ELSE.

CLEAR F_INDEX.

ENDIF.

CHECK F_INDEX GT 0.

*for created by

IF lwa_TOTAL-CREATED_ON IS INITIAL.

MOVE SY-DATUM TO lwa_TOTAL-CREATED_ON.

ENDIF.

IF lwa_TOTAL-CREATED_BY IS INITIAL.

MOVE SY-UNAME TO lwa_TOTAL-CREATED_BY.

ENDIF.

*for last changed

MOVE SY-DATUM TO lwa_TOTAL-LCHANGED_ON.

MOVE SY-UNAME TO lwa_TOTAL-LCHANGED_BY.

*update field

MOVE Z157429_PICI-KOSTL TO lwa_total-KOSTL.

*MODIFY TOTAL INDEX f_index FROM lwa_TOTAL.

MOVE lwa_total to total.

modify total.

CHECK F_INDEX GT 0.

EXTRACT = TOTAL.

modify extract index f_index.

ENDIF.

ENDLOOP.

SY-SUBRC = 0.

But it seems the changes did not reflected on the record... did i missed something? thanks in advance!

Regards,

Mike

Former Member
0 Kudos

Hi,

any suggestions? thanks in advance!

Regards,

Mike

Former Member
0 Kudos

Use event 21.

0 Kudos

Hi,

Use only dialog event 05 (Creating New Entry).

Best regards ,

Surendarreddy

Former Member
0 Kudos

Hi,

Pls see the code which I had used in a similiar program.

Trust it helps.

In event '01'

DATA: BEGIN OF fs_total.

INCLUDE STRUCTURE zconcur_sae_hist.

INCLUDE STRUCTURE vimtbflags.

DATA END OF fs_total.

DATA: fs_record TYPE zconcur_sae_hist,

w_index LIKE sy-tabix,

w_bukrs TYPE zconcur_sae_hist-bukrs.

LOOP AT total INTO fs_total.

IF fs_total-vim_action = aendern OR

fs_total-vim_action = neuer_eintrag.

MOVE-CORRESPONDING fs_total TO fs_record.

fs_record-laeda = sy-datum.

fs_record-aenam = sy-uname.

READ TABLE extract WITH KEY fs_total.

IF sy-subrc EQ 0.

w_index = sy-tabix.

ELSE.

CLEAR w_index.

ENDIF. " IF sy-subrc EQ 0.

MOVE-CORRESPONDING fs_record TO fs_total.

MODIFY total FROM fs_total.

CHECK w_index GT 0.

MODIFY extract INDEX w_index FROM fs_total.

ENDIF. " IF fs_total-vim_action = aendern

ENDLOOP. " LOOP AT total

Please reward if helpful

Former Member
0 Kudos

I'm attempting to use event 07 which I had hoped would be triggered when a field was edited.

I have the event and form defined under table maintenance and can view the code. The include generated is defined in the top include. However, when I edit a field nothing happens. I have a break point within my form, within the include, but nothing is ever triggered.

Event 07 is "Before correcting the contents of a selected field". Which sounds like exactly what I need, but, what does it mean by 'selected field'?.

Anyone.

Former Member
0 Kudos

hi,

The changes are not reflected coz once data is saved ztab-CREATED_ON contain some value

then in your code in the update :

IF ztab-CREATED_ON IS INITIAL ---is not executed as ztab-CREATED_ON contain data .

MOVE SY-DATUM TO ztab-CREATED_ON.

ENDIF.

IF ztab_Created_BY IS INITIAL.

MOVE SY-UNAME TO ztab-CREATED_BY.

ENDIF.

MOVE SY-DATUM TO ztab-LCHANGED_ON.

MOVE SY-UNAME TO ztab_-LCHANGED_BY.

same is applied for others.

Please check it. removing this may solve ur problem.

Thanks & regards