Skip to Content

Trigger on Z* table

Hello,

I have a Z* table, which is update by an external program (not SAP). I need to know each time this table have a modif or an update.

Regards

Frédéric

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Mar 14, 2005 at 03:36 PM

    Hi everyone,

    I'm afraid I disagree that checking the flag "Log data changes" works with this issue, for the data is updated outside SAP. By checking this flag, every time a table is update within SAP, then tables CDHDR & CDPOS are populated.

    My suggestion is: create a trigger in the database where SAP lies, that is, *outside* SAP. It will work for sure. You know,

    create or replace trigger sapr3.your_trigger after update
    or insert or delete on sapr3.z* for each row
    (here your pl/sql)
    

    (this is Oracle-syntax)

    Please let us know if it helped. BR,

    Alvaro

    Message was edited by: Alvaro Vidal-Abarca

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Srinivas Adavi

      Hi Srinivas,

      well, not really. If you create a trigger, you can execute a piece of PL/SQL code every time an entry is inserted/updated/deleted. This PL/SQL could perform any operations on the DB where SAP is, or even on DB's outside SAP (via DB-links).

      In order to run a program in SAP, (sigh) I really don't know. Maybe you could call a Java class into this PL/SQL, and this Java class calls an OS-SAP-program (maybe "sapexec") that runs an ABAP-program.

      Phew!!!! That's a trigger that calls a PL/SQL that calls a Java class that calls an OS-program that calls an ABAP. I need a rest 😊

      Anyone can help guys?

      BR,

      Alvaro

  • Posted on Mar 14, 2005 at 03:17 PM

    Hi Frédéric ,

    some possible solutions:

    1) TA SCDO -> change documents (tables cdhdr /cdpos)

    2) append your z-table with field "udate" and

    update this field by every run of ext. program

    regards Andreas

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 14, 2005 at 03:21 PM

    Hi Frédéric ,

    In the technical Settings of the table, there's an option called "Log Data Changes". Please consider this option. You could start off with the F1 help for this checkbox.

    Regards,

    Anand Mandalika.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Mar 14, 2005 at 03:52 PM

    Hi Frederic,

    Here is another alternative. I am assuming that this is a table defined in SAP's data dictionary and this external program is updating the data through SAP's RFC mechanism. Also, I am assuming that you have a table maintenance generated for this table. If my assumption is correct, here is what I think will work.

    Use SE54 to create event for the table. The best event for you would be '02--> After saving the data in the database'. For this event you attach your code to trigger the other program which needs to know if any entry is made/changed/deleted in this table. I haven't tried calling another program from within the code of an event, but you can also try calling a function module to submit your program. Alternatively, you can raise a background event(not to be confused with the SE54 event) and scehdule a job to run your program when this event is raised. You can define this background event in SM62 and raise it using the function module BP_EVENT_RAISE.

    If this external program is updating the table at a underlying database level, then you have to work with database triggers, but I am not sure how you will let SAP program know that a trigger has been raised at the database level.

    Regards,

    Srinivas

    Add a comment
    10|10000 characters needed characters exceeded

    • You are correct Anand. I was not thinking. When I said an RFC, I was referring to just remote execution of the external program that updates the table, not the RFC function module that has access to the data. So if I call an external program 'abc.exe' that does a direct update to the database table(not through the SAP's application layer), then I think the events won't be of any use.

      But I think if we define a external OS command using SM69, and then execute it within an RFC using the FM 'SXPG_COMMAND_EXECUTE'. Then based on the return status (assuming the external program returns status), the SAP program can continue with its process of reading the new/updated records. You still need the extra fields for date/time updated/inserted though.

      Srinivas

  • Posted on Mar 14, 2005 at 09:18 PM

    Hi,

    to clarify some points on CDHDR/CDPOS:

    Tables CDPOS and CDHDR are populated by function modules *_WRITE_DOCUMENT. These function modules are generated from so-called Change Documents Objects, which are maintained in transaction SCDO.

    Most SAP applications call these function modules when updating standard tables. If you add Z* tables to an application, you have two choices:

    1) Extension of an existing business object

    Add your table to an existing change documents object in transaction SCDO. When updating your table, call ..._WRITE_DOCUMENT in the same LUW.

    2) New business object

    Create a new change document object in transaction SCDO. When updating your table, call ..._WRITE_DOCUMENT in the same LUW.

    The ..._WRITE_DOCUMENT are called for each changed table record. They receive a parameter containing the old state and another parameter containing the new state of the record. Both are compared and the differences are written into tables CDHDR and CDPOS as one change document. CDHDR contains the header of the change document. CDPOS contains one or more positions (changed field values) of the change document.

    Only changes to fields whose data elements are marked as relevant for the creation of change documents in SE11 lead to the creation of change documents. That is, if you call ..._WRITE_DOCUMENT with two identical records for old and new, no change document will be written. If the old and new record are different, but only in fields whose data elements do not have the "relevant for the creation of change documents" checkbox marked, no change documents will be written.

    Best regards,

    Thorsten

    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.