Return to the RPG Tips
Here's a trigger program and a copy member that it uses:
*** Compile options h dftactgrp(*no) actgrp(*caller) bnddir('STARRBIND') h option(*srcstmt : *noshowcpy : *nodebugio) ******************************************************************** * Program : xxxxxxxxxX * Date : xx/xx/xxxx * Programmer : xxx * Description : Trigger program for XXXXXXXXXX * Compilation : * Modifications : ******************************************************************** /copy qrpglesrc,trg_buffer d sds d userid 254 263 *** CHANGE 'filename' below to the actual physical file name. *** Will not need new_record for delete triggers or old_record *** for insert triggers d old_recordp s * d old_record e ds extname(xxxxxxxx) prefix(old_) d based(old_recordp) d new_recordp s * d new_record e ds extname(xxxxxxxx) prefix(new_) d based(new_recordp) c *entry plist c parm trgbuf c eval old_recordp = %addr(trgbuf) + tbooff c eval new_recordp = %addr(trgbuf) + tbnoff *** INSERT TRIGGER PROGRAM CODE HERE. THE FIELD NAMES ARE PREFIXED *** WITH OLD_ FOR THE BEFORE RECORD AND NEW_ FOR THE AFTER RECORD. ********** SAMPLE CODE FOR UPDATING USER/DATE/TIME OF UPDATE c********** select c********** when (tbevnt = INSERT) or (tbevnt = UPDATE) c********** eval new_user = userid c********** time new_usrtim c********** other c********** endsl c return Copy member *** TRIGGER BUFFER Copy Member *** Constants d AFTER c '1' d BEFORE c '2' d DELETE c '2' d INSERT c '1' d UPDATE c '3' *** Buffer data structure d TRGBUF ds 32000 *** FILE NAME d TBFILE 10 *** LIBRARY NAME d TBLIB 10 *** MEMBER NAME d TBMBR 10 *** TRIGGER EVENT (1=INSERT, 2=DELETE, 3=UPDATE) d TBEVNT 1 *** TRIGGER TIME (1=AFTER, 2=BEFORE) d TBTIME 1 *** TRIGGER COMMIT LEVEL d TBCOMT 1 *** FILLER d TBFIL1 3 *** CCSID d TBCCSI 8B 0 *** FILLER d TBFIL2 8 *** OLD RECORD OFFSET d TBOOFF 8B 0 *** OLD RECORD LENGTH d TBOLEN 8B 0 *** OLD RECORD NULL BYTE MAP OFFSET d TBOMPO 8B 0 *** OLD RECORD NULL BYTE MAP LENGTH d TBOMPL 8B 0 *** NEW RECORD OFFSET d TBNOFF 8B 0 *** NEW RECORD LENGTH d TBNLEN 8B 0 *** NEW RECORD NULL BYTE MAP OFFSET d TBNMPO 8B 0 *** NEW RECORD NULL BYTE MAP LENGTH d TBNMPL 8B 0 *** FILLER d TBFIL3 16
[report a broken link by clicking here]