Return to the RPG Tips
Database Trigger Programs
>Hi All! > >When creating a trigger program (in RPG/ILE) there is a variable length >section that contains the before and after image of the record that is >changed. I know how to access them with the offsets. > >My question is: How is the length of the data structure (for the first >parameter of the trigger program) calculated? I always have to make the >data area ridiculously large, then go into debug mode to see where it ends. >Is there a way to do this programmatically? Any thoughts are appreciated. > If you declare a data structure that is mapped by the external description of the file and based on a pointer, then there is no physical allocation of memory, just a pointer-based map of the data that can be positioned to the before and/or after image area and used to access the data directly from the buffers for the trigger without concern over allocating large spaces to read the data. Attached is a sample of what I describe... R. Bruce Hoffman, Jr. -- IBM Certified Specialist - AS/400 Administrator -- IBM Certified Specialist - RPG IV Developer - ------=_NextPart_000_000B_01C001E4.83C2D910 Content-Type: application/octet-stream; name="trigger.rpgle" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="trigger.rpgle" * --------------------------------------------------------------- * Standard ILE RPG IV specs for DB2/400 trigger program. * * Author: R. Bruce Hoffman, Jr. * * Built for V3R2. * * Reviewed for V3R7. * Revised for V4R1. * Revised for V4R2. * * --------------------------------------------------------------- H extbinint H COPYRIGHT('Copyright (C) 1999, R. Bruce Hoffman, Jr.') * Externally described table name. D fileName c const('FILENAME') * Pointer based data structures for the input buffer. D newPoint s * D oldPoint s * * Map data structure for before and after images of the record * in the buffer from the external description for the file. D newFile e ds based(newPoint) D extname(fileName) D prefix(n_) D oldFile e ds based(oldPoint) D extname(fileName) D prefix(o_) * First parameter of trigger call. Trigger buffer header information. D trigParm ds D file 10a D library 10a D member 10a D trigEvent 1a D trigTime 1a D commitLock 1a D skip3 3a D ccsid 10i 0 D currrn 10i 0 D skip4 4a D oldrecoff 10i 0 D oldreclen 10i 0 D oldnuloff 10i 0 D oldnullen 10i 0 D newrecoff 10i 0 D newreclen 10i 0 D newnuloff 10i 0 D newnullen 10i 0 D skip16 16a * Second parameter of trigger call. Ignored by program. D bufferLen s 10i 0 * Constants used for trigger verification: triggering event, * trigger time and commitment lock levels. D triggerEventInsert... D c const('1') D triggerEventDelete... D c const('2') D triggerEventUpdate... D c const('3') D triggerTimeAfter... D c const('1') D triggerTimeBefore... D c const('2') D commit_none... D c const('0') D commit_changes... D c const('1') D commit_cursorStability... D c const('2') D commit_all... D c const('3') * Trigger entry parameter list. C *entry plist C parm trigParm C parm bufferLen * Verify file, library and/or member names. C if file <> fileName C eval *inH9 = *on C return C endif * Verify Trigger event and time. C if trigEvent <> triggerEventInsert C eval *inH8 = *on C return C endif C if trigTime <> triggerTimeAfter C eval *inH7 = *on C return C endif * Address the data structures to the appropriate locations in the * trigger buffer. C eval oldPoint = %addr(trigParm) + oldrecoff C eval newPoint = %addr(trigParm) + newrecoff * When done, leave program. C return
[report a broken link by clicking here]