<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Redaware Limited - Computer Services &#38; Business IT Solutions in Tenbury Wells, Worcestershire &#187; IBM</title>
	<atom:link href="http://www.redaware.net/category/ibm/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redaware.net</link>
	<description></description>
	<lastBuildDate>Tue, 31 Jan 2012 10:49:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using SQL Triggers to create an audit trail on iSeries</title>
		<link>http://www.redaware.net/2009/11/using-sql-triggers-to-create-an-audit-trail-on-iseries/</link>
		<comments>http://www.redaware.net/2009/11/using-sql-triggers-to-create-an-audit-trail-on-iseries/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 08:46:32 +0000</pubDate>
		<dc:creator>tsymonds</dc:creator>
				<category><![CDATA[IBM]]></category>
		<category><![CDATA[AS/400]]></category>
		<category><![CDATA[Audit]]></category>
		<category><![CDATA[i5]]></category>
		<category><![CDATA[iSeries]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Trigger]]></category>

		<guid isPermaLink="false">http://www.redaware.net/?p=142</guid>
		<description><![CDATA[We recently completed a development project to create a .NET application to populate an iSeries file. The client required an audit trail to be setup, this is how to do it: Firstly create an audit file, ensure that the file has all the fields you wish to audit. The best way to achieve this is [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>We recently completed a development project to create a .NET application to populate an iSeries file. The client required an audit trail to be setup, this is how to do it: </p>
<p>Firstly create an audit file, ensure that the file has all the fields you wish to audit.<br />
The best way to achieve this is to copy the original source member and use an “A” suffix.<br />
Then add three addition fields to the end of the file:</p>
<pre class="brush: plain; title: ; notranslate">
A            TIMESMP         Z         TEXT('AUDIT TIMESTAMP')
A            AUDTYP         1          TEXT('AUDIT TYPE')
A            AUDIMG         1          TEXT('AUDIT IMAGE')
</pre>
<p>To add SQL Triggers, use the STRSQL command. Copy the sample code below substituting library, file and fields for your own details.<br />
For new records:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TRIGGER library.trigger_name
  AFTER INSERT ON library.file_name
  REFERENCING NEW AS new_row
  FOR EACH ROW MODE DB2ROW
BEGIN
  INSERT INTO library.audit_file(field1,field2,field3,field4, audtyp, audimg)  VALUES(new_row.field1, new_row.field2, new_row.field3, new_row.field4,’I’,’ A‘ );
END
</pre>
<p>For deletions:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TRIGGER library.trigger_name
  AFTER DELETE ON library.file_name
  REFERENCING OLD AS old_row
  FOR EACH ROW MODE DB2ROW
BEGIN
  INSERT INTO library.audit_file(field1,field2,field3,field4, audtyp, audimg)  VALUES(old_row.field1, old_row.field2, old_row.field3, old_row.field4,’D’,’B’ );
END
</pre>
<p>For record changes:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TRIGGER library.trigger_name
  AFTER UPDATE ON library.file_name
  REFERENCING OLD AS old_row
                            NEW AS new_row
  FOR EACH ROW MODE DB2ROW
BEGIN
  /* Before update*/
  INSERT INTO library.audit_file(field1,field2,field3,field4,audtyp,audimg)  VALUES(old_row.field1, old_row.field2, old_row.field3, old_row.field4 ,‘ U‘,’B’);
  /* After update*/
  INSERT INTO library.audit_file(field1,field2,field3,field4,audtyp,audimg)  VALUES(new_row.field1, new_row.field2, new_row.field3, new_row.field4,’U’,’A’ );
END
</pre>
<p>Removing triggers<br />
You can remove triggers using the Remove Physical File Trigger (RMVPFTRG) command, the SQL DROP TRIGGER statement, and iSeries Navigator.</p>
<div class="shr-publisher-142"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.redaware.net/2009/11/using-sql-triggers-to-create-an-audit-trail-on-iseries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

