trigger on source physical file

Hello friends,
I have read somwhere that it is possible to write trigger on source physical file .
if it is ..then is it possible to write before delete of any member of source physical file i want to take backup of that member in other library ?? how can i write trigger and
how can i backup that member before deletion
(option 4 ) ??
thanks n waiting..
Who is Participating?

AFAIK, it won't work. Further, I believe it will stop most editors, such as SEU, from being able to update source members. Finally, if it _did_ work, I believe it wouldn't give the result you wanted because the trigger would fire for each individual source line; a source member with 500 lines would cause the trigger to execute 500 times every time an editor saved a member that was being edited. Easiest test is to create a temporary PF-SRC file, put a source member into it, add the PF trigger and try updating the member.

Editors don't generally do "database" operations in the normal sense. These aren't regular physical files; they have the PF-SRC attribute and they act differently. Members are commonly loaded into memory all at once, source changes happen against the copy in memory, then the entire member is rewritten. This is what allows sequence number to be maintained throughout the entire member even if you insert/delete only a single line.

Unfortunately, the only things I can think of to help you (except for creating or buying a change management product) are (1) after-the-fact procedures that get notified too late or (2) network exit programs that wouldn't work for local editors such as SEU.

You know, a home-grown CM product might not be as difficult as you might worry about. Start by considering which issues need to be overcome. I'm pretty sure we can supply solutions for each issue.


you use the following command to add the trigger to thev data base


and the program looks somthing like

 **                                                                **          
 **  Function: Program call via OS/400 on any data base activity   **          
 **            relating to file plp04U. Tis program is run         **          
 **            prior to the databse beng updated.                  **          
 **                                                                **          
 **            Use the ADDPFTRG or RMVPFTRG to attach this         **          
 **            program to the database.                            **          
 **                                                                **          
 **                                                                **          
D src           E DS                  EXTNAME(QRPGLESRC)                        
D PARM1           DS                                                            
 * File name                                                                    
D  FNAME                  1     10                                              
 * Library name                                                                
D  LNAME                 11     20                                              
 * Member name                                              
D  MNAME                 21     30                          
 * Trigger event  1=Insert 2=delete 3=change                
D  TEVEN                 31     31                          
 * Trigger time   1=after 2=before                          
D  TTIME                 32     32                          
 * Commit lock level                                        
D  CMTLCK                33     33                          
 * Reserved                                                  
D  FILL1                 34     36                          
 * CCSID                                                    
D  CCSID                 37     40B 0                        
 * Reserved                                                  
D  FILL2                 41     48                          
 * Offset to the original record                            
D  OLDOFF                49     52B 0                        
 * Length of the original record                            
D  OLDLEN                53     56B 0                        
 * Offset to the original record null byte map              
D  ONOFF                 57     60B 0                        
0051.00  * Length of the null byte map                                                      
0052.00 D  NNLEN                 77     80B 0                                              
0053.00  * MAXLEN                                                                          
0054.00 D  MAXLEN              8000   8000                                                  
0055.00  ********************************************************************              
0056.00 D PARM2           DS                                                                
0057.00 D  LENG                   1      4B 0                                              
0064.00  ********************************************************************              
0065.00 C     *ENTRY        PLIST                                                          
0066.00 C                   PARM                    PARM1                                  
0067.00 C                   PARM                    PARM2                                  
0068.00 C                   EVAL      SRC   =%SUBST(parm1:OLDOFF+1:OLDLEN)                  
0069.00 C                   EVAL      *INLR=*ON                                            
0070.00 C                   RETURN                                                          

This will log all records that are added to the source file, there is an after image

0068.00 C                   EVAL      SRC   =%SUBST(parm1:NEWOFF+1:NEWLEN)                  

raj28Author Commented:
Hi daveslater,
I have tried using the following code but it's not working . I have written a before delete trigger on srcpf (srcfile) in which i'm calling rpgle pgm(delpgmrpg ) . I also set a breakpoint in rpgle pgm but it doesn't stop when i'm deleting using option 4.  

I have written rpglr pgm like this -

D Buffer          DS         32767                                    
D  TrgEvent              31     31                                    
D  TrgTime               32     32                                    
D  OldOff                49     52B 0                                
D  OldLen                53     56B 0                                
D  NewOff                65     68B 0                                
D  NewLen                69     72B 0                                
 * Total Buffer length                                                
D BufLen          DS                                                  
D  Leng                   1      4B 0                                
D Start           s              5P 0                                
D filen         E DS                  EXTNAME(SRCFILE)                
C     *entry        Plist  
C     Buffer        Parm                    Buffer      
C     BufLen        Parm                    BufLen      
C                   Select                              
C                   When      TrgEvent = '2'            
C                   Exsr      CheckDelete                
C                   Endsl                                
c                   call      'DELPGMCL'                
c                   parm                    filen        
C                   Return                              
C     CheckDelete   Begsr                                
C                   Exsr      GetOldFields              
C                   Endsr                                
C     GetOldFields  Begsr                                          
 * "Before" image                                                  
C                   Eval      Start = OldOff + 1                    
C                   Eval      filen = %subst(Buffer:Start:OldLen)  
C                   Endsr                                          

The code in CL pgm (delpgmcl) is like this -      
PGM (&FILENAME)                                              
             DCL        VAR(&FILENAME) TYPE(*CHAR) LEN(10)  
             CPYSRCF    FROMFILE(RAJLIB/SRCFILE) +          

waiting ....

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

for that what you need is the QIBM_QZDA_INIT format ZDAI0100 exit point

raj28Author Commented:
hello daveslater,
I couldn't understood how ir works in my program ..(i.e how can i debug that rpgle pgm  using this )
pls explain me in detail ( steps )..

thanks n waiting
Hi Raj
The above program will not work as an exit point program. I will generate an example later on today and post it.



You'll probably have a problem using a trigger program because they react at a record level. If you open a member in SEU, make a change to one source line, then save the member, every single source record is deleted and every line is rewritten to the member... except... SEU doesn't do a record delete; it does a clear-member operation and that's not allowed when the file has a *DELETE trigger. Good thing, too, because a *DELETE trigger would fire for every individual source line.

I imagine most source editors work similarly, though I haven't looked. They load the entire member and rewrite the entire member which generates the clear-member.

I'm not really sure what you need. There are a few after-the-fact notifications such as audit journal entries, but they arrive too late. By the time any program reacts, the member is already cleared -- gone.

I suspect what you need is source control -- apply proper authorities/security to your source and disallow deletions (source changes) except through controlled interfaces. The interfaces will be in charge of automated backups.

What OS/400 VRM?

raj28Author Commented:
Hi tliotta ,
Do u mean that  *DELETE trigger on source physical file will not work in my case ?? our version is V4R4 .
Hi Raj28, Tom
I generated an exit point program on the
 QIBM_QZDA_NDB1 format ZDAD0100      
I thought this would work but when I came to try it - nothing. Bang goes my idea.


raj28Author Commented:
Hi tliotta,
I also agree with you. Thnaks for your responses .
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.