Return to the RPG Tips
An example of a trigger program that we use to update audit stamps for a given file
h Debug(*Yes) Option(*SrcStmt) Indent('| ') Actgrp(*Caller) h Bnddir('DAADITRG') *---------------------------------------------------------------- * Program: DAADITRG - DAADIPD trigger program * Author: Brent Sauser * Date: 08/24/1999 * * Description: * This trigger program will add the create/change user, program * and timestamp to the file based on the trigger event. * * Input: InBuffer - Input buffer of record images and offsets * InBufLen - Input buffer length * * Output: Changes input buffer, which are then written to the file * * Special Instructions: * When adding the trigger to the file, use ALWREPCHG(*YES) * and TRGTIME(*BEFORE) *---------------------------------------------------------------- * Before trigger image d B_RecordP s * d B_Record e ds Extname(DAADIPD ) Prefix(B_) d Based(B_RecordP) * After trigger image d A_RecordP s * d A_Record e ds Extname(DAADIPD ) Prefix(A_) d Based(A_RecordP) d InBuffer ds 32000 d TrgFile 1 10 d TrgEvent 31 31 d B_Offset 49 52i 0 d B_Length 53 56i 0 d A_Offset 65 68i 0 d A_Length 69 72i 0 d InBufLen s 10i 0 d InPSSR s N Inz(*off) /Copy Qcpylesrc,Gettrginfh c *Entry plist c parm InBuffer c parm InBufLen c eval B_RecordP = %addr(InBuffer) + B_Offset c eval A_RecordP = %addr(InBuffer) + A_Offset * Trigger events c select * On insert, do both the created and changed audit stamp c when TrgEvent = '1' c callp GetTrgInf(A_Crtu95:A_Crtp95:A_Crts95) c eval A_Chgu95 = A_Crtu95 c eval A_Chgp95 = A_Crtp95 c eval A_Chgs95 = A_Crts95 * On update, do the changed audit stamp c when TrgEvent = '3' c callp etTrgInf(A_Chgu95:A_Chgp95:A_Chgs95) c endsl c eval *inlr = *on c return *--------------------------------------------------------------------- c *PSSR begsr c if InPSSR = *off c eval InPSSR = *on c dump c endif c endsr '*CANCL' I hope that helps! Eric ______________________________________________ Eric N. Wilson President Doulos Software & Computer Services 2913 N Alder St. Tacoma WA 98407
[report a broken link by clicking here]