Go Premium for a chance to win a PS4. Enter to Win


trigger on source physical file

Posted on 2004-04-21
Medium Priority
Last Modified: 2007-12-19
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..
Question by:raj28
  • 5
  • 4
  • 2
LVL 14

Expert Comment

ID: 10886437

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)                  


Author Comment

ID: 10888642
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 ....

LVL 14

Expert Comment

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


NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

LVL 14

Expert Comment

ID: 10890383

Author Comment

ID: 10896824
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
LVL 14

Expert Comment

ID: 10897142
Hi Raj
The above program will not work as an exit point program. I will generate an example later on today and post it.


LVL 27

Expert Comment

ID: 10905324

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?


Author Comment

ID: 10905823
Hi tliotta ,
Do u mean that  *DELETE trigger on source physical file will not work in my case ?? our version is V4R4 .
LVL 14

Expert Comment

ID: 10916424
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.


LVL 27

Accepted Solution

tliotta earned 1000 total points
ID: 10921112

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.


Author Comment

ID: 10924954
Hi tliotta,
I also agree with you. Thnaks for your responses .

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Did you know there are services out there that can turn an Instagram feed into an RSS feed? I found some interesting exclusive Instagram content which I wanted to follow without signing up for yet another social media account. RSS to the rescue!
Ranking ecommerce websites is a vital process. You need to have a strong SEO (Search Engine Optimization) strategy. If you don’t have one, you are losing out on brand impressions, clicks and sales. Check this guide on how to improve website traffic …
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

782 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