ibm-information-center/dist/eclipse/plugins/i5OS.ic.cl_5.4.0.1/addpftrg.htm

504 lines
19 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<!doctype html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head><META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Add Physical File Trigger (ADDPFTRG)</title>
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body bgcolor="white">
<script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<a name="ADDPFTRG.Top_Of_Page"></a>
<h2>Add Physical File Trigger (ADDPFTRG)</h2>
<table width="100%">
<tr>
<td valign="top" align="left"><b>Where allowed to run: </b>All environments (*ALL)<br>
<b>Threadsafe: </b>Conditional
</td>
<td valign="top" align="right">
<a href="#ADDPFTRG.PARAMETERS.TABLE">Parameters</a><br>
<a href="#ADDPFTRG.COMMAND.EXAMPLES">Examples</a><br>
<a href="#ADDPFTRG.ERROR.MESSAGES">Error messages</a></td>
</tr>
</table>
<div> <a name="ADDPFTRG"></a>
<p>The Add Physical File Trigger (ADDPFTRG) command adds a system trigger to a specified physical file. A <b>trigger</b> defines a program that is called with a delete, insert, update or read operation occurs for a file.
</p>
<p>The trigger program can be specified to be called before or after a change operation occurs. The change operation can be an insert, update, delete or read operation through any interface. Change operations do not include clearing, initializing, moving, applying journal changes, removing journal changes, or changing end of data operations.
</p>
<p>A maximum of 300 triggers can be added to one physical file. The trigger program to be called can be the same for each trigger or it can be a different program for each trigger.
</p>
<p>An exclusive-no-read lock is held on the physical file when adding a trigger to that file. All logical files which are built over the physical file are also held with the exclusive-no-read lock.
</p>
<p>Once a trigger is added to the physical file, all members of that specified file are affected by the trigger. When a change operation occurs on a member of the specified file, the trigger program is called. The trigger program is also called when a change operation occurs by way of either a dependent logical file or a Structured Query Language (SQL) view that is built over the physical file.
</p>
<p>More information on the trigger program is in the Database information in the iSeries Information Center at http://www.ibm.com/eserver/iseries/infocenter.
</p>
<p><b>Restrictions</b>
</p>
<ul>
<li>You must have read (*READ), object operational (*OBJOPR), and object alter (*OBJALTER) or object management (*OBJMGT) authorities to the physical file, execute (*EXECUTE) authority to the file library, and *EXECUTE authority to the trigger program and its library to use this command.
</li>
<li>You must have update (*UPD) and *OBJOPR authorities to the file if ALWREPCHG(*YES) has been specified.
</li>
<li>If the physical file or a dependent logical file or SQL view is opened in this or another job, a trigger cannot be added.
</li>
<li>While this command is running, neither the physical file nor any dependent logical files can be opened.
</li>
<li>The trigger program must be a program of object type *PGM. It cannot be an Integrated Language Environment (ILE) service program of object type *SRVPGM.
</li>
<li>This command is conditionally threadsafe. In multithreaded jobs, this command is not threadsafe for distributed files and fails for distributed files that use relational databases of type *SNA.
</li>
<li>Triggers may not be added to files in library QTEMP.
</li>
<li>Read triggers may not be added to SQL materialized query tables.
</li>
</ul>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
<hr size="2" width="100%">
<div>
<h3><a name="ADDPFTRG.PARAMETERS.TABLE">Parameters</a></h3>
<table border="1" cellpadding="4" cellspacing="0">
<!-- col1="10" col2="15" col3="30" col4="10" -->
<tr>
<th bgcolor="aqua" valign="bottom" align="left">Keyword</th>
<th bgcolor="aqua" valign="bottom" align="left">Description</th>
<th bgcolor="aqua" valign="bottom" align="left">Choices</th>
<th bgcolor="aqua" valign="bottom" align="left">Notes</th>
</tr>
<tr>
<td valign="top" rowspan="3"><a href="#ADDPFTRG.FILE"><b>FILE</b></a></td>
<td valign="top">Physical file</td>
<td valign="top"><i>Qualified object name</i></td>
<td valign="top" rowspan="3">Required, Positional 1</td>
</tr>
<tr>
<td valign="top">Qualifier 1: Physical file</td>
<td valign="top"><i>Name</i></td>
</tr><tr>
<td valign="top">Qualifier 2: Library</td>
<td valign="top"><i>Name</i>, <b><u>*LIBL</u></b>, *CURLIB</td>
</tr><tr>
<td valign="top"><a href="#ADDPFTRG.TRGTIME"><b>TRGTIME</b></a></td>
<td valign="top">Trigger time</td>
<td valign="top">*BEFORE, *AFTER</td>
<td valign="top">Required, Positional 2</td>
</tr>
<tr>
<td valign="top"><a href="#ADDPFTRG.TRGEVENT"><b>TRGEVENT</b></a></td>
<td valign="top">Trigger event</td>
<td valign="top">*INSERT, *DELETE, *UPDATE, *READ</td>
<td valign="top">Required, Positional 3</td>
</tr>
<tr>
<td valign="top" rowspan="3"><a href="#ADDPFTRG.PGM"><b>PGM</b></a></td>
<td valign="top">Program</td>
<td valign="top"><i>Qualified object name</i></td>
<td valign="top" rowspan="3">Required, Positional 4</td>
</tr>
<tr>
<td valign="top">Qualifier 1: Program</td>
<td valign="top"><i>Name</i></td>
</tr><tr>
<td valign="top">Qualifier 2: Library</td>
<td valign="top"><i>Name</i>, <b><u>*LIBL</u></b>, *CURLIB</td>
</tr><tr>
<td valign="top"><a href="#ADDPFTRG.RPLTRG"><b>RPLTRG</b></a></td>
<td valign="top">Replace trigger</td>
<td valign="top"><b><u>*NO</u></b>, *YES</td>
<td valign="top">Optional</td>
</tr>
<tr>
<td valign="top"><a href="#ADDPFTRG.TRG"><b>TRG</b></a></td>
<td valign="top">Trigger</td>
<td valign="top"><i>Character value</i>, <b><u>*GEN</u></b></td>
<td valign="top">Optional</td>
</tr>
<tr>
<td valign="top"><a href="#ADDPFTRG.TRGLIB"><b>TRGLIB</b></a></td>
<td valign="top">Trigger library</td>
<td valign="top"><i>Name</i>, <b><u>*FILE</u></b>, *CURLIB</td>
<td valign="top">Optional</td>
</tr>
<tr>
<td valign="top"><a href="#ADDPFTRG.ALWREPCHG"><b>ALWREPCHG</b></a></td>
<td valign="top">Allow Repeated Change</td>
<td valign="top"><b><u>*NO</u></b>, *YES</td>
<td valign="top">Optional</td>
</tr>
<tr>
<td valign="top"><a href="#ADDPFTRG.THDSAFE"><b>THDSAFE</b></a></td>
<td valign="top">Threadsafe</td>
<td valign="top"><b><u>*UNKNOWN</u></b>, *NO, *YES</td>
<td valign="top">Optional</td>
</tr>
<tr>
<td valign="top"><a href="#ADDPFTRG.MLTTHDACN"><b>MLTTHDACN</b></a></td>
<td valign="top">Multithreaded job action</td>
<td valign="top"><b><u>*SYSVAL</u></b>, *MSG, *NORUN, *RUN</td>
<td valign="top">Optional</td>
</tr>
<tr>
<td valign="top"><a href="#ADDPFTRG.TRGUPDCND"><b>TRGUPDCND</b></a></td>
<td valign="top">Trigger update condition</td>
<td valign="top"><b><u>*ALWAYS</u></b>, *CHANGE</td>
<td valign="top">Optional</td>
</tr>
</table>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
</div>
<div> <a name="ADDPFTRG.FILE"></a>
<h3>Physical file (FILE)</h3>
<p>Specifies the physical file to which this trigger program is added. The file must exist on the system.
</p>
<p>This is a required parameter.
</p>
<p><b>Qualifier 1: Physical file</b>
</p>
<dl>
<dt><b><i>name</i></b></dt>
<dd>Specify the name of the file to which the trigger program is added.
</dd>
</dl>
<p><b>Qualifier 2: Library</b>
</p>
<dl>
<dt><b><u>*LIBL</u></b></dt>
<dd>All libraries in the library list for the current thread are searched until the first match is found.
</dd>
</dl>
<dl>
<dt><b>*CURLIB</b></dt>
<dd>The current library for the job is searched. If no library is specified as the current library for the job, the QGPL library is used.
</dd>
<dt><b><i>name</i></b></dt>
<dd>Specify the name of the library to be searched.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFTRG.TRGTIME"></a>
<h3>Trigger time (TRGTIME)</h3>
<p>Specifies the time when the trigger program is called.
</p>
<p>This is a required parameter.
</p>
<dl>
<dt><b>*BEFORE</b></dt>
<dd>The trigger program is called before the change operation on the specified physical file.
</dd>
<dt><b>*AFTER</b></dt>
<dd>The trigger program is called after the change operation on the specified physical file.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFTRG.TRGEVENT"></a>
<h3>Trigger event (TRGEVENT)</h3>
<p>Specifies the event (the change operation to the physical file) that calls the trigger program. Only one event can be specified for each command issued.
</p>
<p>This is a required parameter.
</p>
<dl>
<dt><b>*INSERT</b></dt>
<dd>An insert operation calls the trigger program.
<p>
<b>Note: </b>If the physical file is not read and write capable, the *INSERT value cannot be specified.
</p>
</dd>
<dt><b>*DELETE</b></dt>
<dd>A delete operation calls the trigger program.
<p><b>Notes:</b>
</p>
<ul>
<li>If the physical file is not read and delete capable, the *DELETE value cannot be specified.
</li>
<li>If the physical file has a referential constraint with a delete rule of CASCADE, the *DELETE value cannot be specified.
</li>
</ul>
</dd>
<dt><b>*UPDATE</b></dt>
<dd>An update operation calls the trigger program.
<p><b>Notes:</b>
</p>
<ul>
<li>If the physical file is not read and update capable, the *UPDATE value cannot be specified.
</li>
<li>If the physical file is a dependent file which has a foreign key with a delete rule of SET NULL or SET DEFAULT, the *UPDATE value cannot be specified.
</li>
</ul>
</dd>
<dt><b>*READ</b></dt>
<dd>A read operation calls the trigger program.
<p>
<b>Note: </b>If the physical file is not read capable, the *READ value cannot be specified.
</p>
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFTRG.PGM"></a>
<h3>Program (PGM)</h3>
<p>Specifies the program that is called when the specified event occurs on the physical file. The program must exist on the system and be of object type *PGM.
</p>
<p>This is a required parameter.
</p>
<p><b>Qualifier 1: Program</b>
</p>
<dl>
<dt><b><i>name</i></b></dt>
<dd>Specify the name of the program to be called when the specified event occurs on the specified physical file.
</dd>
</dl>
<p><b>Qualifier 2: Library</b>
</p>
<dl>
<dt><b><u>*LIBL</u></b></dt>
<dd>All libraries in the library list for the current thread are searched until the first match is found.
</dd>
</dl>
<dl>
<dt><b>*CURLIB</b></dt>
<dd>The current library for the job is searched. If no library is specified as the current library for the job, the QGPL library is used.
</dd>
<dt><b><i>name</i></b></dt>
<dd>Specify the name of the library to be searched.
</dd>
</dl>
<p>
<b>Note: </b>The special values *LIBL and *CURLIB are the values of the job running when the trigger program is added.
</p>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFTRG.RPLTRG"></a>
<h3>Replace trigger (RPLTRG)</h3>
<p>Specifies whether an existing trigger is replaced by the trigger to be added when the triggers have the same trigger event and trigger time.
</p>
<dl>
<dt><b><u>*NO</u></b></dt>
<dd>The existing trigger is not replaced.
</dd>
<dt><b>*YES</b></dt>
<dd>The existing trigger is replaced. If *GEN was specified for the trigger name and the time and event match a single entry, the trigger will be replaced. If a trigger name was specified and it matches an existing entry, the trigger will be replaced. If a trigger with the specified trigger name does not exist, the new trigger is added to the physical file.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFTRG.TRG"></a>
<h3>Trigger (TRG)</h3>
<p>Specifies the name of the trigger being added.
</p>
<dl>
<dt><b><u>*GEN</u></b></dt>
<dd>The system generates a trigger name.
</dd>
<dt><b><i>character-value</i></b></dt>
<dd>Specify the name of the trigger. The trigger name must be unique to the library. The trigger name is used to distinguish triggers with the same time and event values. You can specify a maximum of 128 characters without delimiters or 258 characters with quotation mark (") delimiters.
<p>
<b>Note: </b>The case is preserved when lowercase characters are specified.
</p>
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFTRG.TRGLIB"></a>
<h3>Trigger library (TRGLIB)</h3>
<p>Specifies the library for the trigger being added.
</p>
<dl>
<dt><b><u>*FILE</u></b></dt>
<dd>The library for the file specified on the FILE parameter is used.
</dd>
<dt><b>*CURLIB</b></dt>
<dd>The current library for the job is used. If no library is specified as the current library for the job, the QGPL library is used.
<p>
<b>Note: </b>The special value *CURLIB is the value of the job running when the trigger program is added.
</p>
</dd>
<dt><b><i>name</i></b></dt>
<dd>Specify the name of the library to be used.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFTRG.ALWREPCHG"></a>
<h3>Allow Repeated Change (ALWREPCHG)</h3>
<p>Specifies whether repeated changes to a record within a trigger are allowed.
</p>
<dl>
<dt><b><u>*NO</u></b></dt>
<dd>Repeated changes to a record within a trigger are not allowed.
</dd>
<dt><b>*YES</b></dt>
<dd>Repeated changes to a record within a trigger are allowed.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFTRG.THDSAFE"></a>
<h3>Threadsafe (THDSAFE)</h3>
<p>Specifies whether the trigger program is threadsafe. This is intended for documentation purposes only. It may be used in determining the MLTTHDACN value, but there is no direct relationship between the THDSAFE and MLTTHDACN keywords.
</p>
<dl>
<dt><b><u>*UNKNOWN</u></b></dt>
<dd>The threadsafe status of the trigger program is not known.
</dd>
<dt><b>*NO</b></dt>
<dd>The trigger program is not threadsafe.
</dd>
<dt><b>*YES</b></dt>
<dd>The trigger program is threadsafe.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFTRG.MLTTHDACN"></a>
<h3>Multithreaded job action (MLTTHDACN)</h3>
<p>Specifies the action to take when the trigger program is called in a multithreaded job. The THDSAFE attribute of the trigger program can be used in determining the action, however, there is no direct relationship between the THDSAFE and MLTTHDACN keywords.
</p>
<dl>
<dt><b><u>*SYSVAL</u></b></dt>
<dd>Use the QMLTTHDACN system value to determine the action to take.
</dd>
<dt><b>*MSG</b></dt>
<dd>Run the trigger program in a multithreaded job, but send a diagnostic message.
</dd>
<dt><b>*NORUN</b></dt>
<dd>Do not run the trigger program in a multithreaded job. Send an escape message.
</dd>
<dt><b>*RUN</b></dt>
<dd>Run the trigger program in a multithreaded job.
</dd>
</dl>
<p>If you do use the THDSAFE value to determine the value for MLTTHDACN, please read the following recommendations:
</p>
<ul>
<li>If the THDSAFE value is *NO, MLTTHDACN should be set to *NORUN.
</li>
<li>If the THDSAFE value is *UNKNOWN, MLTTHDACN should be set to *SYSVAL.
</li>
<li>If the THDSAFE value is *YES, MLTTHDACN should be set to *RUN.
</li>
</ul>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
<div> <a name="ADDPFTRG.TRGUPDCND"></a>
<h3>Trigger update condition (TRGUPDCND)</h3>
<p>Specifies the condition under which an update event calls the trigger program.
</p>
<p>
<b>Note: </b>This parameter applies only when *UPDATE is specified for the <b>Trigger event (TRGEVENT)</b> parameter.
</p>
<dl>
<dt><b><u>*ALWAYS</u></b></dt>
<dd>The trigger program is called whenever a record is updated, whether or not a value changes.
</dd>
<dt><b>*CHANGE</b></dt>
<dd>The trigger program is called only when a record is updated and a value is changed.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
<hr size="2" width="100%">
<div><h3><a name="ADDPFTRG.COMMAND.EXAMPLES">Examples</a> </h3>
<p><b>Example 1: Adding a Trigger for an Insert Event</b>
</p>
<p>
<pre>
ADDPFTRG FILE(EMP) TRGTIME(*AFTER) TRGEVENT(*INSERT)
PGM(LIB2/INSTRG)
</pre>
</p>
<p>This command adds a trigger with trigger program INSTRG in library LIB2 to the physical file named EMP. When an insert operation occurs on the EMP file, the program INSTRG is called after the insert operation. The library list (*LIBL) is used to find the file because the FILE value is not qualified by a library name.
</p>
<p><b>Example 2: Setting Multiple Trigger Events to Call One Trigger Program</b>
</p>
<p>
<pre>
ADDPFTRG FILE(EMP) TRGTIME(*AFTER) TRGEVENT(*INSERT)
PGM(LIB2/INSTRG)
ADDPFTRG FILE(EMP) TRGTIME(*AFTER) TRGEVENT(*UPDATE)
PGM(LIB2/INSTRG)
</pre>
</p>
<p>These two commands add triggers to call the trigger program INSTRG in library LIB2 when an insert or update operation occurs on the EMP file.
</p>
<p><b>Example 3: Adding a Trigger Only When an Update Event Changes Values</b>
</p>
<p>
<pre>
ADDPFTRG FILE(EMP) TRGTIME(*BEFORE) TRGEVENT(*UPDATE)
PGM(LIB2/UPDTRG) TRGUPDCND(*CHANGE)
</pre>
</p>
<p>The trigger program UPDTRG in library LIB2 is called before a value for a field of a record in the EMP file changes during an update.
</p>
<p><b>Example 4: Replacing an Existing Trigger</b>
</p>
<p>
<pre>
ADDPFTRG FILE(EMP) TRGTIME(*BEFORE) TRGEVENT(*UPDATE)
PGM(LIB2/NEWPGM) RPLTRG(*YES) TRGUPDCND(*CHANGE)
</pre>
</p>
<p>The trigger program NEWPGM being added to the file EMP has the same trigger time (*BEFORE) and trigger event (*UPDATE) as the trigger program UPDTRG that was added in Example 3. Therefore, the added trigger program NEWPGM replaces the existing trigger program UPDTRG.
</p>
<p><b>Example 5: Replacing a Trigger with a Trigger for a Different Update Condition</b>
</p>
<p>
<pre>
ADDPFTRG FILE(EMP) TRGTIME(*BEFORE) TRGEVENT(*UPDATE)
PGM(LIB2/NEWPGM) RPLTRG(*YES) TRGUPDCND(*ALWAYS)
</pre>
</p>
<p>The trigger added in Example 4 that calls the trigger program NEWPGM only is the values are changed, is replace by a trigger that always calls the trigger program NEWPGM regardless of the values.
</p>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
<hr size="2" width="100%">
<div><h3><a name="ADDPFTRG.ERROR.MESSAGES">Error messages</a> </h3>
<p><b><u>*ESCAPE Messages</u></b>
</p>
<dl>
<dt><b>CPF32C6</b></dt>
<dd>Trigger operation not successful.
</dd>
</dl>
</div>
<table width="100%">
<tr><td align="right"><a href="#ADDPFTRG.Top_Of_Page">Top</a></td></tr>
</table>
</body>
</html>