RPGIV @ Work

A unique site for RPG and System i Lovers

Welcome!

Hi, this site will provide all what you need in System i and RPG developments.

My Name is Chamara Withanachchi, System i Expert and RPG Developer. And in the field for last 11 years.

I hope you will find lot of valuable information from this site

Trigger Example Print E-mail
User Rating: / 0
PoorBest 
Written by Chamara Withanachchi   
                                                                                 
      *------------------------------------------------------------------------- 
      *                                                                          
      *         Application      :  Savings                                      
      *         Program Id       :  TAP002TRG                                    
      *                                                                          
      *         Title            :  Trigger the Account Master                   
      *         Description      :  This Program to be attached to TAP00201      
      *                             (Account Master) and record all Account      
      *                             Status change activities.                    
      *                                                                          
      *         Author           :  Chamara Withanachchi                         
      *         Date             :  2010/10/30                                   
      *         Version          :  V 1.0.0                                      
      *                                                                          
      *------------------------------------------------------------------------- 
      * N O T E S                                                                
      *------------------------------------------------------------------------- 
      *                                                                          
      *-------------------------------------------------------------------------
      *         MODIFICATIONS  :-                                               
      *                                                                         
      *         Reference No     :                                              
      *         Description      :                                              
      *         Modified By      :                                              
      *         Date             :                                              
      *         Version          :                                              
      *-------------------------------------------------------------------------
                                                                                
     FSTAP00201 O    E             Disk    ExtFile('FISDTF/STAP00201')          
                                                                                
      **********************************************************************    
      * Data Structure Definitions                                         *    
      **********************************************************************    
                                                                                
      *  Program status information data structure .....                        
     D                SDS                                                       
     D  S@PGM            *PROC                                                  
     D  Device               244    253                                                           
     D  S@USER               254    263                                                           
                                                                                                  
      *--------------------------------------------------------------------*                      
      * Parm_01 is the first parameter passed into the trigger program by  *                      
      * OS/400 when the trigger is activated.                              *                      
      *--------------------------------------------------------------------*                      
     DParm_01          DS                                                       Incoming Parameter
      * Static Section = 96 bytes                                                                 
     D  File_Name              1     10                                         Physical File Name
     D  Lib_Name              11     20                                         File Library      
     D  Mbr_Name              21     30                                         Member Name       
     D  Trg_Event             31     31                                         Trigger Event     
      *     1=Insert New Record                                                                   
      *     2=Delete Existing Record                                                              
      *     3=Update Existing Record                                                              
     D  Trg_Time              32     32                                         Trigger Time      
      *     1=After Record Added/Deleted/Updated                                                  
      *     2=Before Record Added/Deleted/Updated                                                 
     D  Commit_Lck            33     33                                         Commit Lock Level 
     D  Reserved              34     36                                         Not Used          
     D  CCSID                 37     40B 0                                      CCSID             
     D  RRN                   41     44B 0                                      Relative Rcd Nbr  
     D  Filler_01             45     48                                         Not Used          
     D  Old_Offset            49     52B 0                                      Offset to Org Rcd 
     D  Old_RcdLen            53     56B 0                                      Length of Org Rcd 
     D  Old_NBMOff            57     60B 0                                      NullByteMap Offset
     D  Old_NBMLen            61     64B 0                                      NullByteMap Length
     D  New_Offset            65     68B 0                                      Offset to New Rcd 
     D  New_RcdLen            69     72B 0                                      Length of New Rcd 
     D  New_NBMOff            73     76B 0                                      NullByteMap Offset
     D  New_NBMLen            77     80B 0                                      NullByteMap Length
     D  Filler_02             81     96                                         NullByteMap Length
                                                                                                  
      *--------------------------------------------------------------------*                      
      * Variable Section                                                                          
      * This section contains the old and new record images as well as the                        
      * old and new null-byte maps. The offset values point into the entire                       
      * buffer which is addressed as a zero-based structure. Therefore, the                       
      * offset values should be reduced by 95 (to allow for the 96 bytes                          
      * used in the static section) when pointing to the 'Data' buffer.                           
      *--------------------------------------------------------------------*                      
     D  Data                       8192                                                           
                                                                                                  
      *--------------------------------------------------------------------*                      
      * Parm_02 is the second parameter passed into the trigger program by *                      
      * OS/400 when the trigger is activated. This data structure contains *                      
      * only one subfield representing the length of the entire buffer de- *                      
      * fined in the first parameter (Parm_01).                            *                      
      *--------------------------------------------------------------------*                      
     DParm_02          DS                                                       Incoming Parameter
     D  Buffer_Len                    4B 0                                      Trig Buffer Length
                                                                                                  
      *--------------------------------------------------------------------*                      
      * Old_ORDDTL is a data structure defining the layout of the original *                      
      * record. It will be used to hold the contents of the order detail   *                      
      * record retrieved from the Data field in Parm_01. A prefix of O_ is *                      
      * added to each of the field names to avoid conflicting with the new *                       
      * data record.                                                       *                       
      *--------------------------------------------------------------------*                       
     DOld_TAP002     E DS                  ExtName(TAP00201)                    Original Rcd Layout
     D                                     Prefix(O_)                                              
                                                                                                   
      *--------------------------------------------------------------------*                       
      * New_ORDDTL is a data structure defining the layout of the modified *                       
      * record. It will be used to hold the contents of the order detail   *                       
      * record retrieved from the Data field in Parm_01. A prefix of N_ is *                       
      * added to each of the field names to avoid conflicting with the old *                       
      * data record.                                                       *                       
      *--------------------------------------------------------------------*                       
     DNew_TAP002     E DS                  ExtName(TAP00201)                    Original Rcd Layout
     D                                     Prefix(N_)                                              
                                                                                                   
      **********************************************************************                       
      * Program Constants and Work Variable Definitions                    *                       
      **********************************************************************                       
     DInsert           S                   LIKE(Trg_Event) INZ('1')          
     DDelete           S                   LIKE(Trg_Event) INZ('2')          
     DUpdate           S                   LIKE(Trg_Event) INZ('3')          
                                                                             
     DAfter            S                   LIKE(Trg_Time ) INZ('1')          
     DBefore           S                   LIKE(Trg_Time ) INZ('2')          
                                                                             
      ********************************************************************** 
      * Main Line Program Logic                                            * 
      ********************************************************************** 
                                                                             
     C     *Entry        PList                                               
     C                   Parm                    Parm_01                     
     C                   Parm                    Parm_02                     
                                                                             
      * Determine if this is an INSERT, DELETE, UPDATE (with same key        
      * fields) or UPDATE (with different key fields).                       
                                                                             
     C                   Select                                              
                                                                                                     
     C                   When      Trg_Event = Insert                                                
                                                                                                     
     C                   When      Trg_Event = Delete                                                
                                                                                                     
     C                   When      Trg_Event = Update                                                
     C                   Eval      Old_TAP002 = %subst(Data: Old_Offset-95:                          
     C                                                 Old_RcdLen)                                   
     C                   Eval      New_TAP002 = %subst(Data: New_Offset-95:                          
     C                                                 New_RcdLen)                                   
                                                                                                     
      * The following logic checks to see if the status of account is change                         
      * other than old record image and the new record image. If so, A new                           
      * Will be writes in to STAP00201 file.                                                         
     C                   If        (O_DMSTAT <> N_DMSTAT)                                            
     C                   Exsr      SB_WriteStat                                                      
     C                   EndIf                                                  If Old <> New Status 
                                                                                                     
     C                   EndSL                                                  Select               
                                                                               
     C                   Eval      *INLR = *ON                                 
                                                                               
      *--------------------------------------------------------------------*   
      * SB_WriteStat is a subroutine that will add records to STAP00201    *   
      * File for status changes                                            *   
      *--------------------------------------------------------------------*   
     C     SB_WriteStat  BegSR                                                 
                                                                               
     C                   Eval      SDMBK = O_DMBK                              
     C                   Eval      SDMTYP = O_DMTYP                            
     C                   Eval      SDMACCT = O_DMACCT                          
     C                   Eval      SDMSHRT = O_DMSHRT                          
     C                   Eval      SODMSTAT = O_DMSTAT                         
     C                   Eval      SNDMSTAT = N_DMSTAT                         
     C                   Eval      SUSER = S@USER                              
     C                   Eval      SDATE = %Char(%Date() : *ISO0)              
     C                   Eval      STIME = %Char(%Time() : *ISO0)              
     C                   Write     STAP0021                                    
                                
     C                   EndSR  

Use

 ADDPFTRG 

to add a trigger to a PF


User Comments

Please login or register to add comments

<Previous   Next>