Solved

trigger on source physical file

Posted on 2004-04-21
13
1,083 Views
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..
0
Comment
Question by:raj28
[X]
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
  • 5
  • 4
  • 2
13 Comments
 
LVL 14

Expert Comment

by:daveslater
ID: 10886437
Hi

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

ADDPFTRG FILE(DSLIBEE/QRPGLESRC) TRGTIME(*BEFORE) TRGEVENT(*INSERT) PGM(DSLIBEE/SRCTRG)

and the program looks somthing like



h                                                                              
 ********************************************************************          
 **                                                                **          
 **  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)                  

Dave
0
 

Author Comment

by:raj28
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                                                        
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) +          
             TOFILE(PARAGLIB/QCLSRC) FROMMBR(&FILENAME)      
ENDPGM                                                      
                                   

waiting ....

0
 
LVL 14

Expert Comment

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

http://publib.boulder.ibm.com/iseries/v5r2/ic2924/index.htm?info/rzaik/rzaik719.htm

Dave
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 14

Expert Comment

by:daveslater
ID: 10890383
0
 

Author Comment

by:raj28
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
0
 
LVL 14

Expert Comment

by:daveslater
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.

Regards

Dave
0
 
LVL 27

Expert Comment

by:tliotta
ID: 10905324
raj28:

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?

Tom
0
 

Author Comment

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

Expert Comment

by:daveslater
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.

Dave

0
 
LVL 27

Accepted Solution

by:
tliotta earned 250 total points
ID: 10921112
raj28:

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.

Tom
0
 

Author Comment

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Check out this step-by-step guide for asking an anonymous question on Experts Exchange.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Suggested Courses

751 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