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

Triggering an event when writing to Database

Former Member
0 Likes
2,836

Hi,

Does anyone knows a way to trigger some kind of event (some program / function)

when a specific standard table changes?

Thanks,

Doron Oded.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,542

Oded,

the range of your question is very wide. can you please tell us what standard table are you interested in and how are you changing it,

1. from a table maintenance --> Yes, table maintenance events are there which trigger here

2. from a tcode like PO, SO changes -> yes, a variety of events trigger depending upon object type

3. from running any program -> depends upon the program

4. a field for which change pointer is active -> yes, change document write is called.

so please specify what exactly is your requirement

again, you need to specify what are you changing.

say its from SM30, that means you are not changing transactional data(EBAN,EKPO hold transactional data). the data might be some master data or config data.

moreover, if its a customizing table then you will have logs by default, else you need to use maintenance events.

say it from ME22n, ME52n etc. that mean you are changing business documents, mostly these are logged in CDPOS/CDHDR. just like when you click environment->item changes in me23n, it actually reads from CDPOS and CDHDR. you can monitor these tables.

and yes, its a business document means it has a BOR object, BOR object has events like CREATE,CHANGE,DELETE etc etc.. with these event you can link workflows in SWE2. So, when ever any of these events trigger your workflow can trigger and you can put any logic. lets say for PO change you want to do some task, so for BUS2012, change event, you will link a WF. and inside the WF you can do the code..

19 REPLIES 19
Read only

madhu_vadlamani
Active Contributor
0 Likes
2,542

Hi Doron,

In general an entry will be created n a table when a record created from standard transaction and for change also.You can try will workflow.Ex:So created,changed,Po displayed, change.Then that even you can use for this.What is the business requirement.

Regards,

Madhu.

Read only

Former Member
0 Likes
2,543

Oded,

the range of your question is very wide. can you please tell us what standard table are you interested in and how are you changing it,

1. from a table maintenance --> Yes, table maintenance events are there which trigger here

2. from a tcode like PO, SO changes -> yes, a variety of events trigger depending upon object type

3. from running any program -> depends upon the program

4. a field for which change pointer is active -> yes, change document write is called.

so please specify what exactly is your requirement

Read only

0 Likes
2,542

Hi,

Thanks for your answers.

I know the question is quite general...

The requirement is to trigger a program whenever somw tables changes..

But they don't want to be depend a UE or a specific program.. But a general DB table change.

So, from all the options you mentioned table maintenance event sound the most promising..

What is that? could you elaborate a bit?

Thanks again,

Doron Oded.

Read only

0 Likes
2,542

Search.. follow this link.

http://www.sdn.sap.com/irj/scn/advancedsearch?query=tablemaintenanceevents

this explains maintenance view events. but know that this is only when you create data from SM30. its not for any where else.

and about being generic.. WONT help.

UPDATE statement as such wont trigger any event.. so it depends upon where the Update is written, according to that you can look for the events you are talking about

Read only

0 Likes
2,542

Hi friend,

You can do like this check the CDHDR and CDPOS table.

From the CDHDR table you will get CHANGENR, OBJECTID and OBJECTCLAS values passing these values to CDPOS, then you will be getting VALUE NEW and VALUE OLD.

So check whether your table is changed and with the help of TMG events or using the driver program where you are checking for the changes call the other program which you want to call.

I think this is much clear if you still face issues please revert back to me i will help you.

Thanks,

Sri Hari

Read only

0 Likes
2,542

Hi,

Change documents (CDHDR, CDPOS) could be a solution for this issue. But what about tables which are not change documents managed?

And what is TMG event? and driver program? Could you please elaborate about them a bit more? or tell me where can I find more documentation?

Thank a lot!!

Doron.

Read only

0 Likes
2,542

TMG - table maintenance generator - the sm30 thing which i told earlier

and the CDPOS/CDHDR wont get updated automatically. for that also you need to check if the fields are logged or not.

you can activate table logging, but it will activate for all the tables

http://help.sap.com/saphelp_nw04/helpdata/en/cf/21eaf9446011d189700000e8322d00/content.htm

Edited by: Soumyaprakash Mishra on Jan 5, 2012 11:25 PM

Read only

0 Likes
2,542

Hi Doro,

TMG nothing but table maintenance generator.

Regards,

Madhu.

Read only

0 Likes
2,542

Hi,

OK, thats sounds not bad at all.. 2 questions:

1. If we activate Logging (change docs..), will all the tables be included or only a part?

2. How would we know a change has occured? should we scan the table periodically for changes? or is there some trigger/event?

Thanks again, you all are great!

Doron.

Read only

0 Likes
2,542

There is the catch... there are 3 things which can be done for table logging

1. system wide(all clients)

2. specific clients(better) -->this one you can go for if you want to

3. no logging

so, this is gonna activate for all tables.

the change can be checked though regular monitoring of SCU3. you can pull out a report and stuff from it.

Read only

0 Likes
2,542

To clarify, it takes the setting of rec/client AND the activation of logging for each table in its technical settings to actually activate the logging in table DBTABLOG (not CDHDR/CDPOS, that's something else), so it does not affect all tables.

And no, I don't know of any generic trigger that you can react on within an ABAP context after DB table entries have changed, irrespective of how they were changed.

The functionality that creates the entries in DBTABLOG must be somewhere down in the kernel or database.

Thomas

Read only

0 Likes
2,542

The functionality that creates the entries in DBTABLOG must be somewhere down in the kernel or database

Yes. Database layer

Read only

0 Likes
2,542

Hi,

When you say "you have to enable it for each table"..

where this should be done?

And, does it require a change request?

Thanks again,

Doron.

Read only

0 Likes
2,542

in technical setting(in se11) for any table you will find this logging activated flag. only if the logging flag is set then only you can trace it though SCU3.

go though this link for details

http://help.sap.com/saphelp_nw04/helpdata/en/7e/c81ebb52c511d182c50000e829fbfe/content.htm

Edited by: Soumyaprakash Mishra on Jan 6, 2012 4:35 AM

Read only

0 Likes
2,542

My friends,

I'm affraid this is not quite answering my question.. appearantly..

Because this is not a general enough solution, I've checked for example if tables EBAN, and MSEG are logging-enbaled in standard, and I was very dissapointed to see that they are not..

If I need an access key to change these kind of most basic logistics tables, this is the wrong solution.

So, I hope you won't be upset with me if I'll take our wonderfull discussion a bit back, and ask again,

is there a simple way to trigger some program when tables change?

The change could be from any program - SM30, or MIGO, or ME52n... Hence, it (the way) should not be based on the updating program (via UE), It should not require access keys for changing standard table settings..

Thanks again, and I appologize for my stubbornness,

Doron.

P.S: Have a lovely weekend.

Read only

0 Likes
2,542

again, you need to specify what are you changing.

say its from SM30, that means you are not changing transactional data(EBAN,EKPO hold transactional data). the data might be some master data or config data.

moreover, if its a customizing table then you will have logs by default, else you need to use maintenance events.

say it from ME22n, ME52n etc. that mean you are changing business documents, mostly these are logged in CDPOS/CDHDR. just like when you click environment->item changes in me23n, it actually reads from CDPOS and CDHDR. you can monitor these tables.

and yes, its a business document means it has a BOR object, BOR object has events like CREATE,CHANGE,DELETE etc etc.. with these event you can link workflows in SWE2. So, when ever any of these events trigger your workflow can trigger and you can put any logic. lets say for PO change you want to do some task, so for BUS2012, change event, you will link a WF. and inside the WF you can do the code..

Read only

0 Likes
2,542

The general solution you are looking for is not available, to my knowledge.

EBAN and MSEG are not logged, because they are tracked via change documents (CDHDR/CDPOS) by the application.

Thomas

Read only

0 Likes
2,542

Hey guys,

It seams reasonable to check CDHDR and CDPOS in order to track changes to business objects.. But. There are some very important tables that are not documented there.. The most obvious example is MSEG.. It has no change documents management..

So, does any of you know any other method of triggering a program when tables change?

Thanks,

Doron.

Read only

0 Likes
2,542

you can go for MB_DOCUMENT_BADI. this badi triggers when a material document is posted.