ibm-information-center/dist/eclipse/plugins/i5OS.ic.dbp_5.4.0.1/rbaforzahftrj.htm

280 lines
14 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Example: Insert trigger written in RPG" />
<meta name="abstract" content="The RPG trigger program inserts records into the ATMTRANS file in this example." />
<meta name="description" content="The RPG trigger program inserts records into the ATMTRANS file in this example." />
<meta name="DC.Relation" scheme="URI" content="rbaforzahftri.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rbaforzahftrj" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Example: Insert trigger written in RPG</title>
</head>
<body id="rbaforzahftrj"><a name="rbaforzahftrj"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Example: Insert trigger written in RPG</h1>
<div><p>The RPG trigger program inserts records into the ATMTRANS file
in this example. </p>
<div class="section"><div class="note"><span class="notetitle">Note:</span> By using the code examples, you agree to the terms of the <a href="codedisclaimer.htm">Code license and disclaimer information</a>.</div>
</div>
<div class="section"><div class="p"><pre>* Program Name : INSTRG
* This is an insert trigger for the application
* file. The application inserts the following three
* records into the ATMTRANS file.
*
* ATMID ACCTID TCODE AMOUNT
* --------------------------------
* 10001 20001 D 100.00
* 10002 20002 D 250.00
* 10003 20003 D 500.00
*
* When a record is inserted into ATMTRANS, the system calls
* this program, which updates the ATMS and
* ACCTS files with the correct deposit or withdrawal amount.
* The input parameters to this trigger program are:
* - TRGBUF : contains trigger information and newly inserted
* record image of ATMTRANS.
* - TRGBUF Length : length of TRGBUF.
*
H 1
*
* Open the ATMS file and the ACCTS file.
*
FATMS UF E DISK KCOMIT
FACCTS UF E DISK KCOMIT
*
* DECLARE THE STRUCTURES THAT ARE TO BE PASSED INTO THIS PROGRAM.
*
IPARM1 DS
* Physical file name
I 1 10 FNAME
* Physical file library
I 11 20 LNAME
* Member name
I 21 30 MNAME
* Trigger event
I 31 31 TEVEN
* Trigger time
I 32 32 TTIME
* Commit lock level
I 33 33 CMTLCK
* Reserved
I 34 36 FILL1
* CCSID
I B 37 400CCSID
* Reserved
I 41 48 FILL2
* Offset to the original record
I B 49 520OLDOFF
* length of the original record
I B 53 560OLDLEN
* Offset to the original record null byte map
I B 57 600ONOFF
* length of the null byte map
I B 61 640ONLEN
* Offset to the new record
I B 65 680NOFF
* length of the new record
I B 69 720NEWLEN
* Offset to the new record null byte map
I B 73 760NNOFF
* length of the null byte map
I B 77 800NNLEN
* Reserved
I 81 96 RESV3
* Old record ** not applicable
I 97 112 OREC
* Null byte map of old record
I 113 116 OOMAP
* Newly inserted record of ATMTRANS
I 117 132 RECORD
* Null byte map of new record
I 133 136 NNMAP
IPARM2 DS
I B 1 40LENG
******************************************************************
* SET UP THE ENTRY PARAMETER LIST.
******************************************************************
C *ENTRY PLIST
C PARM PARM1
C PARM PARM2
******************************************************************
* Use NOFF, which is the offset to the new record, to
* get the location of the new record from the first
* parameter that was passed into this trigger program.
* - Add 1 to the offset NOFF since the offset that was
* passed to this program started from zero.
* - Substring out the fields to a CHARACTER field and
* then move the field to a NUMERIC field if it is
* necessary.
******************************************************************
C Z-ADDNOFF O 50
C ADD 1 O
******************************************************************
* - PULL OUT THE ATM NUMBER.
******************************************************************
C 5 SUBSTPARM1:O CATM 5
******************************************************************
* - INCREMENT "O", WHICH IS THE OFFSET IN THE PARAMETER
* STRING. PULL OUT THE ACCOUNT NUMBER.
******************************************************************
C ADD 5 O
C 5 SUBSTPARM1:O CACC 5
******************************************************************
* - INCREMENT "O", WHICH IS THE OFFSET IN THE PARAMETER
* STRING. PULL OUT THE TRANSACTION CODE.
******************************************************************
C ADD 5 O
C 1 SUBSTPARM1:O TCODE 1
******************************************************************
* - INCREMENT "O", WHICH IS THE OFFSET IN THE PARAMETER
* STRING. PULL OUT THE TRANSACTION AMOUNT.
******************************************************************
C ADD 1 O
C 5 SUBSTPARM1:O CAMT 5
C MOVELCAMT TAMT 52
*************************************************************
* PROCESS THE ATM FILE. ****************
*************************************************************
* READ THE FILE TO FIND THE CORRECT RECORD.
C ATMN DOUEQCATM
C READ ATMS 61EOF
C END
C 61 GOTO EOF
* CHANGE THE VALUE OF THE ATM BALANCE APPROPRIATELY.
C TCODE IFEQ 'D'
C ADD TAMT ATMAMT
C ELSE
C TCODE IFEQ 'W'
C SUB TAMT ATMAMT
C ELSE
C ENDIF
C ENDIF
* UPDATE THE ATM FILE.
C EOF TAG
C UPDATATMFILE
C CLOSEATMS
*************************************************************
* PROCESS THE ACCOUNT FILE. ****************
*************************************************************
* READ THE FILE TO FIND THE CORRECT RECORD.
C ACCTN DOUEQCACC
C READ ACCTS 62 EOF2
C END
C 62 GOTO EOF2
* CHANGE THE VALUE OF THE ACCOUNTS BALANCE APPROPRIATELY.
C TCODE IFEQ 'D'
C ADD TAMT BAL
C ELSE
C TCODE IFEQ 'W'
C SUB TAMT BAL
C ELSE
C ENDIF
C ENDIF
* UPDATE THE ACCT FILE.
C EOF2 TAG
C UPDATACCFILE
C CLOSEACCTS
*
C SETON LR</pre>
</div>
</div>
<div class="section"><p>After the insertions by the application, the ATMTRANS file contains
the following data: </p>
</div>
<div class="section"><div class="p">
<table cellpadding="4" cellspacing="0" border="1" class="tableborder"><tr><td>
<table cellpadding="4" cellspacing="0" summary="" width="100%" border="0"><thead align="left"><tr><th align="center" valign="bottom" width="25%" id="d0e36">ATMID</th>
<th align="center" valign="bottom" width="25%" id="d0e38">ACCTID</th>
<th align="center" valign="bottom" width="25%" id="d0e40">TCODE</th>
<th align="center" valign="bottom" width="25%" id="d0e42">AMOUNT</th>
</tr>
</thead>
<tbody><tr><td align="center" valign="top" width="25%" headers="d0e36 ">10001</td>
<td align="center" valign="top" width="25%" headers="d0e38 ">20001</td>
<td align="center" valign="top" width="25%" headers="d0e40 ">D</td>
<td align="center" valign="top" width="25%" headers="d0e42 ">100.00</td>
</tr>
<tr><td align="center" valign="top" width="25%" headers="d0e36 ">10002</td>
<td align="center" valign="top" width="25%" headers="d0e38 ">20002</td>
<td align="center" valign="top" width="25%" headers="d0e40 ">D</td>
<td align="center" valign="top" width="25%" headers="d0e42 ">250.00</td>
</tr>
<tr><td align="center" valign="top" width="25%" headers="d0e36 ">10003</td>
<td align="center" valign="top" width="25%" headers="d0e38 ">20003</td>
<td align="center" valign="top" width="25%" headers="d0e40 ">D</td>
<td align="center" valign="top" width="25%" headers="d0e42 ">500.00</td>
</tr>
</tbody>
</table>
</td></tr></table>
After being updated from the ATMTRANS file by the insert trigger program,
the ATMS file and the ACCTS file contain the following data:
<table cellpadding="4" cellspacing="0" border="1" class="tableborder"><tr><td>
<table cellpadding="4" cellspacing="0" summary="" width="100%" border="0"><thead align="left"><tr><th align="center" valign="bottom" width="33.33333333333333%" id="d0e80">ATMN</th>
<th align="center" valign="bottom" width="33.33333333333333%" id="d0e82">LOCAT</th>
<th align="center" valign="bottom" width="33.33333333333333%" id="d0e84">ATMAMT</th>
</tr>
</thead>
<tbody><tr><td align="center" valign="top" width="33.33333333333333%" headers="d0e80 ">10001</td>
<td align="center" valign="top" width="33.33333333333333%" headers="d0e82 ">MN</td>
<td align="center" valign="top" width="33.33333333333333%" headers="d0e84 ">300.00</td>
</tr>
<tr><td align="center" valign="top" width="33.33333333333333%" headers="d0e80 ">10002</td>
<td align="center" valign="top" width="33.33333333333333%" headers="d0e82 ">MN</td>
<td align="center" valign="top" width="33.33333333333333%" headers="d0e84 ">750.00</td>
</tr>
<tr><td align="center" valign="top" width="33.33333333333333%" headers="d0e80 ">10003</td>
<td align="center" valign="top" width="33.33333333333333%" headers="d0e82 ">CA</td>
<td align="center" valign="top" width="33.33333333333333%" headers="d0e84 ">750.00</td>
</tr>
</tbody>
</table>
</td></tr></table>
<table cellpadding="4" cellspacing="0" border="1" class="tableborder"><tr><td>
<table cellpadding="4" cellspacing="0" summary="" width="100%" border="0"><thead align="left"><tr><th align="center" valign="bottom" width="33.33333333333333%" id="d0e116">ACCTN</th>
<th align="center" valign="bottom" width="33.33333333333333%" id="d0e118">BAL</th>
<th align="center" valign="bottom" width="33.33333333333333%" id="d0e120">ACTACC</th>
</tr>
</thead>
<tbody><tr><td align="center" valign="top" width="33.33333333333333%" headers="d0e116 ">20001</td>
<td align="center" valign="top" width="33.33333333333333%" headers="d0e118 ">200.00</td>
<td align="center" valign="top" width="33.33333333333333%" headers="d0e120 ">A</td>
</tr>
<tr><td align="center" valign="top" width="33.33333333333333%" headers="d0e116 ">20002</td>
<td align="center" valign="top" width="33.33333333333333%" headers="d0e118 ">350.00</td>
<td align="center" valign="top" width="33.33333333333333%" headers="d0e120 ">A</td>
</tr>
<tr><td align="center" valign="top" width="33.33333333333333%" headers="d0e116 ">20003</td>
<td align="center" valign="top" width="33.33333333333333%" headers="d0e118 ">500.00</td>
<td align="center" valign="top" width="33.33333333333333%" headers="d0e120 ">C</td>
</tr>
</tbody>
</table>
</td></tr></table>
</div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbaforzahftri.htm" title="This topic provides examples of trigger programs written in C, COBOL, and RPG.">Examples: Trigger programs</a></div>
</div>
</div>
</body>
</html>