Triggers for audit control

Good morning all,
I am in desperate need of a trigger for audit control, that is who is doing what action (udpate, delete, insert)to a record, old value, and new value. Time and date wouild also be helpful.
Problem -- and it's a big one. I don't know pl/sql. Trying to learn it, but in time for this project.
Thanks all.
P.S. If you have a link to a documentation that tells you how to do something like this, please let me know. Thanks again.

Hi,
The following example demonstrates a trigger that audits modifications to the Emp_tab table for each row. It requires that a "reason code" be stored in a global
package variable before the update. This shows how triggers can be used to provide value-based auditing and how to use public package variables.
Note:
You may need to set up the following data structures for the examples to work:
CREATE OR REPLACE PACKAGE Auditpackage AS
Reason VARCHAR2(10);
PROCEDURE Set_reason(Reason VARCHAR2);
END;
CREATE TABLE Emp99 (
Empno NOT NULL NUMBER(4)
Ename VARCHAR2(10)
Job VARCHAR2(9)
Mgr NUMBER(4)
Hiredate DATE
Sal NUMBER(7,2)
Comm NUMBER(7,2)
Deptno NUMBER(2)
Bonus NUMBER
Ssn NUMBER
Job_classification NUMBER);
CREATE TABLE Audit_employee (
Oldssn NUMBER
Oldname VARCHAR2(10)
Oldjob VARCHAR2(2)
Oldsal NUMBER
Newssn NUMBER
Newname VARCHAR2(10)
Newjob VARCHAR2(2)
Newsal NUMBER
Reason VARCHAR2(10)
User1 VARCHAR2(10)
Systemdate DATE);
CREATE OR REPLACE TRIGGER Audit_employee
AFTER INSERT OR DELETE OR UPDATE ON Emp99
FOR EACH ROW
BEGIN
/* AUDITPACKAGE is a package with a public package
variable REASON. REASON could be set by the
application by a command such as EXECUTE
AUDITPACKAGE.SET_REASON(reason_string). Note that a
package variable has state for the duration of a
session and that each session has a separate copy of
all package variables. */
IF Auditpackage.Reason IS NULL THEN
Raise_application_error(-20201, 'Must specify reason'
|| ' with AUDITPACKAGE.SET_REASON(Reason_string)');
END IF;
/* If the above conditional evaluates to TRUE, the
user-specified error number and message is raised,
the trigger stops execution, and the effects of the
triggering statement are rolled back. Otherwise, a
new row is inserted into the predefined auditing
table named AUDIT_EMPLOYEE containing the existing
and new values of the Emp_tab table and the reason code
defined by the REASON variable of AUDITPACKAGE. Note
that the "old" values are NULL if triggering
statement is an INSERT and the "new" values are NULL
if the triggering statement is a DELETE. */
INSERT INTO Audit_employee VALUES
(:old.Ssn, :old.Ename, :old.Job_classification, :old.Sal,
:new.Ssn, :new.Ename, :new.Job_classification, :new.Sal,
auditpackage.Reason, User, Sysdate );
END;
Optionally, you can also set the reason code back to NULL if you wanted to force the reason code to be set for every update. The following simple AFTER statement
trigger sets the reason code back to NULL after the triggering statement is run:
CREATE OR REPLACE TRIGGER Audit_employee_reset
AFTER INSERT OR DELETE OR UPDATE ON Emp_tab
BEGIN
auditpackage.set_reason(NULL);
END;
Hope that helps.
Thanks,
Sharmila

Similar Messages

  • Oracle triggers for auditing

    Let us say I want to audit data updates, deletes on existing table EMP_TAB that
    has a few hundred thousands of records.
    I created a shadow table Emp_tab_audit and added few audit columns
    Emp_tab (
    Empno NUMBER NOT NULL,
    Ename VARCHAR2(10),
    Job VARCHAR2(9),
    Mgr NUMBER(4),
    Hiredate DATE,
    Sal NUMBER(7,2),
    Comm NUMBER(7,2),
    Deptno NUMBER(2) NOT NULL);
    CREATE TABLE Emp_tab_audit (
    seq number
    operation varchar2(3),
    user varchar2(20),
    Timestamp date,
    ip_address varchar2(25),
    Terminal varchar2(10,
    Empno NUMBER NOT NULL,
    Ename VARCHAR2(10),
    Job VARCHAR2(9),
    Mgr NUMBER(4),
    Hiredate DATE,
    Sal NUMBER(7,2),
    Comm NUMBER(7,2),
    Deptno NUMBER(2) NOT NULL);
    I am mostly interested in UPDATES and DELETES but I decided to add INSERTS to have full history for
    each eomplyee in one table (audit schema) instead of querying two tables all the time (production
    table and audit table) to see the changes.
    I created this AFTER INSERT, UPDATE, DELETE trigger.
    I decided to copy the :NEW values for INSERT and UPDATE and :OLD values for DELETE.
    see attached.
    so when insert happens, the first audit row is created in EMP_TAB_AUDIT.
    when update happens, the 2nd new row is created in EMP_TAB_AUDIT.
    The problem I am facing is the old records that curently exist. If someone updates an old row I am
    copying the :NEW values so I won't have a copy of the :OLD values unless I create 2 ROWS (one for
    the old and one for the new).
    Do you think I should copy all the hundreds of thousands of records to the AUDIT tables for this to
    work. I am hesitant to do that.
    ANy better ideas. I am applying this solution to several tables (not just one).
    This is also in 9i and i dont flexibility other than using a trigger to track data changes.
    CREATE OR REPLACE TRIGGER TRG_EMP_AUDIT
    AFTER INSERT OR DELETE OR UPDATE ON EMP_TAB
    FOR EACH ROW DECLARE
    v_operation VARCHAR2(10) := NULL;
    v_user VARCHAR2(20);
    v_timestamp Date;
    v_ip_address VARCHAR2(25),
    v_terminal VARCHAR2(10);
    BEGIN
    v_user := USERENV(user);
    v_timestamp := SYSDATE;
    v_ip_address := USERENV(ip_address);
    v_terminal := USERENV(terminal);
    IF INSERTING THEN
    v_operation := 'INS';
    ELSIF UPDATING THEN
    v_operation := 'UPD';
    ELSE
    v_operation := 'DEL';
    END IF;
    IF INSERTING OR UPDATING THEN
    INSERT INTO EMP_TAB_AUDIT (
    seq,
    operation,
    user
    timestamp,
    ip_address,
    terminal,
    empno,
    job,
    mgr,
    hiredate,
    sal,
    comm,
    deptno )
    VALUES (
    audit_seq.nextval,
    v_operation,
    v_user,
    v_timestamp,
    v_ip_address,
    v_terminal,
    :new.empno,
    :new.job,
    :new.mgr,
    :new.hiredate,
    :new.sal,
    :new.comm,
    :new.deptno);
    ELSIF DELETING THEN
    INSERT INTO EMP_TAB_AUDIT (
    seq,
    aud_action,
    user
    timestamp,
    ip_address,
    terminal,
    empno,
    job,
    mgr,
    hiredate,
    sal,
    comm,
    deptno )
    VALUES (
    audit_seq.nextval,
    v_operation,
    v_user,
    v_timestamp,
    v_ip_address,
    v_terminal,
    :old.empno,
    :old.job,
    :old.mgr,
    :old.hiredate,
    :old.sal,
    :old.comm,
    :old.deptno);
    END IF;
    END;
    *******************************************************************************

    For auditing normailly you do AFTER triggers (not BEFORE) as ther could be other triggers that change the :NEW data stored in the row.
    You can capture :OLD in AFTER too, but the issue you are saving the updated values. You are storing an image of the OLD row so you still need to check the current row to find out what has been updated. My preference was to store NEW values on updates.

  • Enter event not triggering for read-only checkbox

    I have some objects in a form that get "locked" when the user signs the form.  I'm not using the digital signatures.  Instead, when the user types their name into the signature text field, a script runs on the change event that makes all of the fields in the form read only.  It also unlocks the fields if the signature is deleted.
    I was worried that we would get a lot of phone calls with users that didn't understand that the form had locked ("Why doesn't this form work?!"), so I added some code to the enter event for all of the fields that would pop up a messagebox to explain to people trying to edit a signed form that the form was locked and that they would need to delete the signature to edit the form.
    This plan works perfect for my text fields and decimal fields.  It does NOT work at all for my checkboxes.  For some reason, the enter event is never triggered for read-only checkboxes.  I don't see any other events that would obviously work for me though.  Any ideas?
    Thanks

    Thanks, those are reasonable suggestions.
    In the first suggestion, I'm unclear about one aspect of how I would accomplish this.  I assume I would allow people to modify fields in the form, but that when they did, a msgbox would pop up that would inform them that, if they continued with this modification to a signed form, the signature would be removed.  I'm all good to that point.  But if they answered that they do not want to continue modifying that field and removing the signature, how can I code it to set the value back to what it was before the change?  Is there some method that will give me access to the value of the field BEFORE the attempted modification?  I went looking for something like $.previousvalue, but found nothing.
    I'd suggest that I could use a two-stage solution, in which I store the previous value on the enter event, and save it just in case they do not want to change the field when prompted by the msgbox, but since the enter event does not exist for checkboxes (my original problem), that seems like it won't work.
    As far as radio button suggestion, I like radio buttons very much except for one fatal flaw: they aren't (as far as I can tell) clearable.  That is a shame.  Clearly some people (like me) want both exclusivity AND clearability.  And we'd like the controls to have an enter event.  But I know I'm demanding   Anyway, as it is, I just end up having to use checkboxes and create a boatload of silly code to make them exclusive.
    Emily

  • Event not getting triggered for PR generated through MRP run

    Hi All,
    Could anyone let me know how to get a workflow triggered for the ReleaseStepCreated event (obj - bus2105) when the PR is created through MRP run. The MD02 control paramters have the value '1'.
    Interstingly the workflow triggers when the value is set to '2' or '3'.
    Thanks,
    Ameekar

    Thanks Aman,
    I checked field restrictions but there are none there. Actually i checked them for other object 'AOOMARA' which is being thrown as an exception when i am creating the PR through MRP run.
    Exception says -> field not maintained.
    So i guess, i need to maintain the field for Change Document but i am not sure how. COuld you please aid me with that.
    Thanks A lot !!

  • How to configure the requirements for output control ?

    Hi ,
    I have some problems in configuring the requirements for output control like following :
    My aim is to make a condition check when i create an inbound delivery ( VL31N)  or MIGO ...., as default in the requirement check for output , a message type will be created automatically if the it satisfies the condition in the KOBEV .....KOBEV( each sub routine was defined with a message type ( V6 )  ( if sy-subrc = 0) . And then a printing program will be triggered to print the SAPscripts form in the table "tnapr"  but even if i have put sy-subrc in ( KOBEV...KOBEV ) always = 0 the printing was not executed , and in this case i do not understand the reason why , If you please to help me this .
    Thanks ,

    Hi,
    it seems that the requirement you made is not the reason why it's not printed. If you set sy-subrc to 0, this code should have no effect.
    Cheers,
    Stefan.

  • Audit control

    A new engineer in our SQA (Software Quality Assurance) department mentioned some mechanism for ensuring that test sequences run in production are the same versions of the sequences as when they were reviewed and approved by SQA.  He mentioned "audit control" and said TestStand has a way to generate a file containing some sort of hash value representing the approved version of all sequences, and that modifying any sequence would result in a run-time check failing and a note on the final report that the sequence isn't SQA approved.
    Can you help me understand how to implement this?  The Senior SQA guy's eyes lit up when he heard about this.
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

    Dennis Knutson wrote:
    I've never heard of anything like this.
     I'm glad to hear that.
    Ryan T wrote:
    Hi jcarmody,
    I believe that what you are trying to accomplish can be done through the Differ Application. I would keep one copy of the sequence file as a standard and always use a different copy of the sequence file to run tests.  Then you can run the differ application in order to make sure nothing has changed in the sequence file.
    Another option you could pursue is to create a user that only has privileges to run sequence files instead of editing and saving them.
    Thanks
    Thanks.  I'll try the Differ.  My question wasn't prompted because operators can edit sequences (I alone have access), this was from the SQA department that wants to ensure that I don't change anything outside of the formal change process.
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

  • When and where IDOC is triggered for TCode MD04

    Please guide me when and where IDOC is triggered for TCode MD04. In my case it is triggering even though I am trying to save a PO with error or on hold.

    Hi,
    Idoc triggers when we save or change the PO. It depends on the message control settings in the partner profile. Check the message control settings.
    thanks
    sarvesh

  • How may I include the table for audit?

    How may I include global tables for audit? We are going to control changes.
    Do you know which table contained the list with it?
    Thanks

    Hi Marina,
    The following is the information on table log:
    You must start the SAP system with the rec/client parameter. This parameter specifies whether the SAP system logs changes to table data in all clients or only in specific clients. The parameter can have
    the following values:
    - rec/client = ALL logs all clients
    - rec/client = 000 [,...] logs the specified clients
    - rec/client = OFF turns logging off
    In the technical settings (use transaction SE13), set the Log data changes flag for those tables that you want to have logged.
    If both of these conditions are met, the database logs table changes in the DBTABPRT table. You can also check at transaction SCU3.
    Use the RSTBHIST report to obtain a list of those tables that are currently set to be logged.
    Hope it helps.
    Please award points if it is useful.
    Thakns & Regards,
    Santosh

  • STOCK REPORT FOR AUDIT

    Hi GUYS
    I am working for a Garment Industry and the audit is in next month end.
    I need your advice in how to catch up with the things related to Stock for Audit.
    We have 3-4 locations in System
    Like
    FABRIC STORE
    CUTTING STORE
    STICHING STORE
    FINISHING STORE
    FINISHED GOOD STORE(from there the material gets dispached EXPORT/LOCAL)
    I need to maintain the STOCK from Cutting to Finishing , Stock at Sub Contractor, How much dispached and how much left, rejected etc
    Please Advice how to do the things.
    I know its all related to MB51 MB52, MBLB, ME2L, MC.9, MB5B ETC
    But i am Confused from where to start and how to proceed.
    I dont even know from which report the auditor will get the details and ask us
    SHD i take the Physical report ie Work in progress report in my hand first or shd i take the SAP Reports first
    I am looking after the following things
    SUB COntracting PO
    STO
    GRN(Fabric, CUT PART , ACCESSORIES ETC)
    Out Bound Dillivery
    PI
    CI
    EI
    Work Related to PP Making production orders etc
    Need a procedure to maintain the stuff in SAP
    Thanks & REGards
    Abhishek

    Dear Abhishek,
    It all depends on how efficiently your company Uses SAP, If company has properly entered all the transactions that take place on a day to day basis in SAP, then there is nothing which can't be answered to the Auditor, its all Integrated and you can see all the stock movements that have happend, If required you can go for a Physical Inventory Count Also so that these is no discrepancy in the system stock and Physical Stock.
    Rest for any material if any question comes up then you can readily use MB5B which will give the material movements in a specified period along with Opening and Closing Stock. The basic questions which Auditors Put up is on the movement of Stock and sometimes the reason for the movement, so if everything is maintained properly in SAP you will have no issues in getting any data.

  • PO Release Strategy not triggerred for particular Total Net Order Value

    Dear,
    I am currently facing the issue where release strategy for purchase orders is not getting triggered for a particular value or lower.
    For order value 1 INR or less, no release strategy is triggered for new created PO. And for value > 1 INR release strategy is getting triggered.
    All otehr PO characterstics are the same, I mean to say the values for other characterstics such as plant material group are identical.
    But the characterstics for release for Total net order value are <= 30000 INR. There are two system copies, where in one system the same release strategy is working as expected. But in other system the above mentioned issue occurs. There is no differnce which I can see in the release strategy setup.
    Please suggest for solution.
    Thank you.
    Warm Regards.

    Dear All,
    While looking further into the issue by going into debugging mode, we have found that in include LCLSCF2I, Internal table p_selection_criteria_tab , the value for ATFLV (Internal Floating point from) gets different values in the two systems. For example, in the affected system, for PO with 1INR tottal value, for one of the Total value chaaracterstics before INR characterstic, ATFLV value is 0,0000000000000000E+00, hence it gets out of loop and doesn't trigger release strategy.
    But in another system for same PO values and release setup, ATFLV value is 1,0000000000000000E+00 for that characterstic.
    May I know how the value for this field gets calculated.
    Thank you.
    Warm Regards.

  • Error when scheduling job for Job Control LO

    Hi all,
    I tried to schedule the job for collective update after I set the job parameter in tcode LBWE for LO Data Extraction. But they said 'Error generating job' without any description why.
    Maybe you can help me about this since I still can't do the delta extraction for LO.
    Thanks and appreciate for your help.
    -Martin Darmawi-

    Hi!
    You have to pass two parameters for job control scheduling.In that you have traffic light for the respective parameters,defaulty those will appear in red.when you have specified parameters,both turns in to green.then you can say start.hope this will helps.....
    Best Regards
    Sunil.

  • How to create two different implementation class for a Control

    Hi,
    I am a newbie to beehieve. I want to know that is it possible to create two different 'Impl' classes for a Control. If yes then how do we instantiate them ? How can we chain them (something like calling one 'Impl' from the other one? Thanks in Advance!!!
    Regards,
    Abhishek

    You are sure you are in the right forum?
    This is the JDeveloper and ADF forum...
    Timo

  • How can I set up a custom keyboard shortcut for volume control?

    Hi all,
    I use my black MacBook at work, connected to an external monitor and external keyboard. I'm looking for a way to set up the F buttons on my external keyboard as volume control, just as they do on my laptop keyboard. Looking for F3 to F5 to be volume mute, down, and up, respectively.
    I tried going into Keyboard Shortcuts in System Preferences but since there is no menu item for volume control I can't seem to add it. Anyone know how I can go about doing this or what I'm missing?
    Thanks
    Mike

    paste the following into Applescrpt Editor (it's in /Applications/Utilities)
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #ADD8E6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    set curVolume to output volume of (get volume settings)
    -- work out the new setting
    if curVolume < 96 then
    set newVolume to curVolume + 5
    else
    -- can't go over 100
    set newVolume to 100
    end if
    -- and apply it
    set volume output volume newVolume</pre>
    this script will increase volume by 5 (out of 100) any time you run it. you can adjust this of course. save the script somewhere.
    You can use a 3rd part app launcher to bind a keyboard shortcut to it. I use Butler. there are many others: Quicksilver, ikeys, quickeys, Spark, Launchbar.
    this will work the fastest.
    If you don't want to use 3rd party tools for this you can make a service using automator but that might be a bit slower than the first option. open automator. it will give you a pulldown screen wiuth the choice of what you want to make. choose "service". set it to receive no input and be available in all applications. add the following "run apple script" action to the service
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #ADD8E6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    on run {input, parameters}
    set curVolume to output volume of (get volume settings)
    -- work out the new setting
    if curVolume < 96 then
    set newVolume to curVolume + 5
    else
    -- can't go over 100
    set newVolume to 100
    end if
    -- and apply it
    set volume output volume newVolume
    end run</pre>
    save the service, go to keyboard system preferences->keyboard shortcuts->services and make a shortcut for the service you just created.

  • How to Set default value for taxonomywebtagging control with terms and nested terms

    Hi,
    I have created taxonomy control in custom aspx page and I am able to select terms but I am trying to setup default value to that control.
    Can anybody let me know how to set the default value for TaxonomyWebTagging control in custom.aspx page with nested terms?
    Any help would be greatly apprecited.
    Control code in aspx page:
    <td>
    <asp:Label runat="server" ID="lblLanguages">Field A: </asp:Label><asp:Label runat="server" ID="rfvlblLanguages" CssClass="errorMsg" ForeColor="Red">*</asp:Label>
    </td>
    <td>
    <Taxonomy:TaxonomyWebTaggingControl ID="term" Width="385px" runat="server" /></td>Mapping metedata code:TaxonomySession session = new TaxonomySession(SPContext.Current.Site);
    //Set the Business Unit Field
    SPSite site = SPContext.Current.Web.Site;
    TermStore termStore = session.TermStores["Managed Metadata Service"];
    Group group = termStore.Groups["GROUPName"];
    TermSet termSet = group.TermSets["TERMSETNAME"];
    Term term = termSet.Terms["TermA"];
    Guid termGuid = term.Id;
    term.SspId.Add(termStore.Id);
    term.TermSetId.Add(termSet.Id);
    term.AllowFillIn = true;
    term.AnchorId = countryGuid;
    term.IsMulti = true;
    Thank you.
    AA.

    Hi,
    According to your description, you want to set default value for TaxonomyWebTaggingControl.
    I have a test in my environment. It could be achieved by setting the Text Property of TaxonomyWebTaggingControl.
    Here is the code snippet:
    TaxonomySession session = new TaxonomySession(SPContext.Current.Site);
    SPSite site = SPContext.Current.Web.Site;
    TermStore termStore = session.TermStores["Managed Metadata Service"];
    Group group = termStore.Groups["GroupA"];
    TermSet termSet = group.TermSets["A"];
    Term term = termSet.Terms["A1"];
    TaxonomyWebTaggingControl1.SspId.Add(termStore.Id);
    TaxonomyWebTaggingControl1.SSPList = termStore.Id.ToString();
    TaxonomyWebTaggingControl1.TermSetId.Add(termSet.Id);
    TaxonomyWebTaggingControl1.TermSetList = termSet.Id.ToString();
    TaxonomyWebTaggingControl1.AllowFillIn = true;
    TaxonomyWebTaggingControl1.IsAddTerms = true;
    TaxonomyWebTaggingControl1.IsMulti = false;
    TaxonomyWebTaggingControl1.Text = string.Format("{0}|{1}", term.Name, term.Id.ToString());
    Here is a detailed article for your reference:
    http://blog.bugrapostaci.com/2010/09/23/taxonomywebtaggingcontrol-sharepoint/
    Feel free to Reply the test result.
    Thanks
    Patrick Liang
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Patrick Liang
    TechNet Community Support

  • How to change properties for some controls in runtime ?

    hi,
    I would like to change some of the properties for some controls in front panel in runtime. Number of control properties I want to change is depending of a log file user opens in final application.
    I attach an example where I'm trying to change the visibility of numeric controls. Problem I have I don't know which reference to connect to property node in case the control in for loop is not a numeric control. The example relies to label.text property but I could use the more generic classname property as well.  
    regards,
    petri
    Solved!
    Go to Solution.
    Attachments:
    dynamic reference.vi ‏11 KB

    pcardinale wrote:
    Initially, a control has no caption.  It's not just that the caption string is empty and the caption not visible, but the caption object does not exist.
    I think this should probably be changed in future versions, because even if each control had a caption, it would still be a negligible small part of the VI. The current behavior made sense many years ago where HD and memory space was very precious. Not any more!
    This issue comes up often enough that it warrants addressing the root of the problem.
    It is hard to convince the casual that the caption does not exist if he can simply do a "show caption" at edit time and it will show in all glory, even with the default set to the current label. It is confusing!
    There is even an idea about this that seems worth supporting (also read the link in the discussion).
    What do you think?
    LabVIEW Champion . Do more with less code and in less time .

Maybe you are looking for