|
DB2 Example: Before Update Trigger
*========================================================*
* This program is intended to illustrate a before update *
* trigger specified with ALWREPCHG(*YES) where the *
* trigger will update the buffer image of the record *
* prior to the update. *
* *
* The capability to update the before trigger image *
* is only supported on V3R2 and V3R7. *
* *
* *
* CRTBNDRPG PGM(CORPDATA/TRG01) SRCFILE(MJASRC/RPG) *
* DFTACTGRP(*NO) ACTGRP(*CALLER) *
* DBGVIEW(*SOURCE) ALWNULL(*YES) *
* USRPRF(*OWNER) *
* *
* ADDPFTRG FILE(CORPDATA/EMPLOYEE) *
* TRGTIME(*BEFORE) TRGEVENT(*UPDATE) *
* PGM(CORPDATA/TRG01) ALWREPCHG(*YES) *
* *
* *
*========================================================*
*
*========================================================*
* Definition of the structure passed as the first *
* parameter from database to the trigger program. *
* The include is used so that any additional fields *
* in the interface template in the future will be *
* brought into the program if it is recompiled. *
* *
* The includes in the QSYSINC library must be on *
* your system to compile this program. Option 13 of *
* the OS/400 install will install them. *
* *
*========================================================*
D/COPY QSYSINC/QRPGLESRC,TRGBUF
*
*========================================================*
* This is an overlay used to set addressability *
* to the various sections of the interface buffer *
* such as the before and after record images. *
*========================================================*
D INTARR S 1A BASED(INTPTR) DIM(32767)
D INTPTR S *
*
*========================================================*
* Definition of the trigger buffer length passed as *
* the second parameter from database to the trigger *
* program. *
*========================================================*
D PARM2 DS
D LENG 1 4B 0
*
*========================================================*
* These pointers are used to point to the before *
* and after images. The before and after images *
* are passed in the first parameter structure. *
*========================================================*
D BIMAGE S *
D AIMAGE S *
*
*========================================================*
* These based structures provide the subfields of *
* the record images. Externally defined data *
* structures are used so a recompile of the *
* program will always pick up the latest field *
* defintions. *
*========================================================*
D BEMP E DS EXTNAME(EMPLOYEE)
D BASED(BIMAGE)
D PREFIX(B)
D AEMP E DS EXTNAME(EMPLOYEE)
D BASED(AIMAGE)
D PREFIX(A)
*
C *ENTRY PLIST
C QDBTB PARM QDBTB
C PARM2 PARM PARM2
*========================================================*
* Set the basing pointers for the interface *
* structure and the before and after images *
*========================================================*
C EVAL INTPTR = %ADDR(QDBTB)
C EVAL BIMAGE = %ADDR(INTARR(QDBORO+1))
C EVAL AIMAGE = %ADDR(INTARR(QDBNRO+1))
*
*========================================================*
* Change the value of SALARY so it is used instead of *
* the value specified by the application program. *
*========================================================*
C AEMPNO IFEQ '111111'
C* EVAL ASALARY = ASALARY + 1000
C ENDIF
*
C RETURN
|