[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now


How do I create a READ trigger on a Table on the iSeries ?

Posted on 2007-04-10
Medium Priority
Last Modified: 2008-01-09
Hi iSeries buffs !

I have a table - F983051 - with the following columns in it :


as well as a bunch of other columns that are not important.

I have another, custom table, F55983ADT which contains the following information :


Now, I want to create a TRIGGER that inserts data into the F55983ADT table whenever the F983051 is READ.  Obviously the values VRPID, VRVERS, VRENHV would come from the row selected from the F55983ADT table - but the USER, DATE and TIME would be system provided values based on the connection.

I will gift additional points to a very in-depth and conclusive answer.  Thankyou !
Question by:altquark
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18884570
I am note aware of any database that can raise a trigger on READING (SELECT) on a table.

Author Comment

ID: 18884748
If I do "ADDPFTRG" - and click F4 on on EVENT - I see "*READ"
LVL 27

Expert Comment

ID: 18886618

It's unclear what you're asking.

You noted that you prompted ADDPFTRG and saw that you could specify *READ as the trigger event. Well... the ADDPFTRG command is one way to add a trigger to a physical file.

However, you're apparently asking how to _create_ the trigger program. The short answer is that you create it the same way you create almost any program -- you enter source statements and then compile it.

Of course, that's perhaps too obvious to be the answer; so, I'd normally assume you meant something a little different. The twist is that read-only trigger programs are currently restricted in that they must be "external triggers". There is no SQL CREATE TRIGGER statement that supports read-only triggers, AFAIK. That means that the ADDPFTRG command is essentially the only route to getting the trigger program associated with a file (or table).

So, are you looking for an answer about how to create programs under i5/OS?


LVL 14

Accepted Solution

daveslater earned 2000 total points
ID: 18888201
Hi here is an RPGLE program then does the job

H Option(*NODEBUGIO)                                                                            
H DftActGrp(*No)                                                                                
H ActGrp('Trigger')                                                                            
H BNDDIR('MYBNDDIR')                                                                            
FF55983ADT o    e             disk                                                              
 * The following works like an *ENTRY plist:                                                    
D MainLine        pr                  ExtPgm('PGMNAME')                    <<<<<<<<<<<<<<<<<<<<
D   Buf                               likeDS(Parm1)                                            
D   Length                      10I 0                                                          
D MainLine        pi                                                                            
D   Buf                               likeDS(Parm1)                                            
D   Length                      10I 0                                                          
 ** standard specification for all trigger programs                                            
D Parm1           ds                  qualified                                                
D   File                        10A                                         1-10        
D   Library                     10A                                        11-20        
D   Member                      10A                                        21-30        
D   Event                        1A                                        31            
D   Time                         1A                                        32            
D   CommitLock                   1A                                        33            
D                                3A                                        34-36        
D   CCSID                       10I 0                                      37-40        
D   DBRRN                       10I 0                                      41-44        
D                                4A                                        45-48        
D   BOffset                     10I 0                                      49-52        
D   BLen                        10I 0                                      53-56        
D   BNullOffset                 10I 0                                      57-60        
D   BNullLen                    10I 0                                      61-64        
D   AOffset                     10I 0                                      65-68        
D   ALen                        10I 0                                      69-72        
D   ANullOffset                 10I 0                                      73-76        
D   ANullLen                    10I 0                                      77-80        
 **  Constants                                                                          
D BeforeEvent     C                   CONST('2')                                              
D AfterEvent      C                   CONST('1')                                              
D Insert          C                   CONST('1')                                              
D Update          C                   CONST('3')                                              
D Delete          C                   CONST('2')                                              
D Read            C                   CONST('4')                                              
 ** standard work fields                                                                      
D Dtdate          S               D   Inz(*sys)                                                
 *  Grab external definitions for the file                                                
 *  so that we can load the "before" and "After"                                              
 *  buffers into them without manually coding all of                                          
 *  the fields in the file.                                                                    
D ptr_Before      s               *                                                            
D Orig          e ds                  ExtName(F983051   )                                      
D                                     based(ptr_Before)                                        
D                                     qualified                                                
D ptr_After       s               *                                                            
D New           e ds                  ExtName(F983051   )                                      
D                                     based(ptr_After)                                          
D                                     qualified                                                
 * Prototypes for subprocedures in this program                                                
D ReadEvent       Pr                                                                            
D LoopToFree      s               n   Inz(*on)                                                  
D Dtdate          s               d   Inz(*sys)                                                
Dpsds            sds                                                                            
D P#USER                254    263                                                              
   If Buf.event = Read ;                                                                        
      ptr_Before = %addr(Buf) + Buf.BOffset ;                                                  
   else  ;                                                                                      
      return ;                                                                                  
   endif ;                                                                                      
  VRPID   = orig.VRPID  ;                                                            
  VRVERS  = orig.VRVERS ;                                                            
  VRENHV  = orig.VRENHV ;                                                            
  VRUSER  = P#USER ;                                                            
  VRDATE  = Dtdate ;                                                            
  write record ;                                                                

I did not compile the pgm as I do not have the files.

you then use the ADDPFTRG to add this program to the database

where you see <<<<<<<<<<<<< you put the program name here

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question