Journaling on IBM i

This article explains the Journaling concept on IBM i
Journaling in IBM i (AS400), journal, as400, sql, ibm i, crtjrnrcv, CRTJRN, CRTJRN, WRKOBJ , Journal and journal receiver operations, File Operations, Record Updates, Record Written,Commitment control,Begin commitment control, Start a Commit Cycle, Commit Operation, Rollback operation, APYJRNCHG, CHGJRN, DLTJRN, DLTJRNRCV , DSPJRN , DSPJRNRCVA , ENDJRNPF , RCVJRNE , RMVJRNCHG, RTVJRNE, SNDJRNE , WRKJRN, as400 and SQL tricks, Journaling example on ibmi, journaling example on as400, Outfile supoort in DSPJRN command, outfile for journal entries, as400 tutorial, ibmi tutorial,iseries,systemi
Journaling in IBM i (AS400) 

Introduction to Journaling

Journaling is defined as the recording activity of the object and involves the recording of the activity related to files, namely, physical files. When a file is being journaled, activities such as file opens, file closes and data updates are recorded.

Setting up Journaling

Here, we need to follow some steps for setting up Journaling

  • Create journal receivers with the Create Journal Receiver (CRTJRNRCV) command.
  • Create journals with the Create Journal (CRTJRN) command.
  • Start journaling physical files with the Start Journal Physical File (STRJRNPF) command.
  • Create Journal Receiver (CRTJRNRCV)

    Use the Create Journal Receiver (CRTJRNRCV) command to create a journal receiver. The journal receiver is where the journal entries are actually recorded. The journal "connects" the receiver to the file.

                            Create Journal Receiver (CRTJRNRCV)                     
                                                                                   
     Type choices, press Enter.                                                    
                                                                                   
     Journal receiver . . . . . . . . JRNRCV         JRNRCV0001                    
       Library  . . . . . . . . . . .                  EASYCLASS1                  
     ASP number . . . . . . . . . . . ASP            *LIBASP                       
     Journal receiver threshold . . . THRESHOLD      1500000                       
     Text 'description' . . . . . . . TEXT           *BLANK                        
                                                                                   
    

    Run command WRKOBJ JRNRCV0001 on the command line will show us the created journal receiver object of type *JRNRCV.

                                   Work with Objects                               
                                                                                   
     Type options, press Enter.                                                    
       2=Edit authority        3=Copy   4=Delete   5=Display authority   7=Rename  
       8=Display description   13=Change description                               
                                                                                   
     Opt  Object      Type      Library     Attribute   Text                       
          JRNRCV0001  *JRNRCV   EASYCLASS1                                         
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                                   
                                                                             Bottom
     Parameters for options 5, 7 and 13 or command                                 
     ===> wrkobj JRNRCV0001                                                        
     F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F11=Display names and types  
     F12=Cancel   F16=Repeat position to   F17=Position to                                                                                          
    

    Create Journal (CRTJRN)

    Create a journal. Use the Create Journal (CRTJRN) command to create a journal and specify the receiver created in step 1. Although you can journal multiple files to the same journal.

                                Create Journal (CRTJRN)                    
                                                                           
    Type choices, press Enter.                                             
                                                                           
    Journal  . . . . . . . . . . . . JRN            JRN0000001             
      Library  . . . . . . . . . . .                  EASYCLASS1           
    Journal receiver . . . . . . . . JRNRCV         JRNRCV0001             
      Library  . . . . . . . . . . .                  EASYCLASS1           
                                                                           
                                                      *LIBL                
    ASP number . . . . . . . . . . . ASP            *LIBASP                
    Journal message queue  . . . . . MSGQ           QSYSOPR                
      Library  . . . . . . . . . . .                  *LIBL                
    Manage receivers . . . . . . . . MNGRCV         *SYSTEM                
    Delete receivers . . . . . . . . DLTRCV         *NO                    
    Receiver size options  . . . . . RCVSIZOPT      *SYSDFT                
                              + for more values                            
    Minimize entry specific data . . MINENTDTA      *NONE                  
                                                                           
    Journal caching  . . . . . . . . JRNCACHE       *NO                    
                                                                           
    

    Run command WRKOBJ JRN0000001 on the command line will show us the created journal object of type *JRN.

                                  Work with Objects                               
                                                                                  
    Type options, press Enter.                                                    
      2=Edit authority        3=Copy   4=Delete   5=Display authority   7=Rename  
      8=Display description   13=Change description                               
                                                                                  
    Opt  Object      Type      Library     Attribute   Text                       
         JRN0000001  *JRN      EASYCLASS1                                         
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                                  
                                                                            Bottom
    Parameters for options 5, 7 and 13 or command                                 
    ===> WRKOBJ JRN0000001                                                        
    F3=Exit   F4=Prompt   F5=Refresh   F9=Retrieve   F11=Display names and types  
    F12=Cancel   F16=Repeat position to   F17=Position to                         
    

    Start Journal Physical File (STRJRNPF)

    Start journaling the file. This is done by using the Start Journal Physical File (STRJRNPF) command. This is how you associate a file to a journal. Once the association is made, the system will record in the journal receiver a copy of any record added, updated, or deleted from the file. Other activities, such as when the file is opened and closed, can also be recorded in the journal receiver if you choose by selecting the appropriate options on the STRJRNPF command.

                         Start Journal Physical File (STRJRNPF)                    
                                                                                   
     Type choices, press Enter.                                                    
                                                                                   
     Physical file to be journaled  . FILE           INFO                          
       Library  . . . . . . . . . . .                  EASYCLASS1                  
                               + for more values                                   
                                                       *LIBL                       
     Journal  . . . . . . . . . . . . JRN            JRN0000001                    
       Library  . . . . . . . . . . .                  EASYCLASS1                  
     Record images  . . . . . . . . . IMAGES         *BOTH                         
     Journal entries to be omitted  . OMTJRNE        *NONE                         
     Logging level  . . . . . . . . . LOGLVL         *ERRORS                       
                                                                                   
    

    Just run command DSPFD INFO from the command line after starting a journal on file INFO to verify whether the file is journaled. Search with "ourn" in the DSPFD report.

                                                           Display Spooled File       
    File  . . . . . :   QPDSPFD                                                       
    Control . . . . .                                                                 
    Find  . . . . . .   ourn                                                          
    *...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8..
       Keep in memory  . . . . . . . . . . . . . . : KEEPINMEM  *NO                   
       File is currently journaled . . . . . . . . :            Yes                   
       Current or last journal . . . . . . . . . . :            JRN0000001            
         Library . . . . . . . . . . . . . . . . . :            EASYCLASS1            
       Journal images  . . . . . . . . . . . . . . : IMAGES     *BOTH                 
       Journal entries to be omitted . . . . . . . : OMTJRNE    *NONE                 
       Last journal start date/time  . . . . . . . :            04/14/22  07:32:35    
     Access Path Description                                                          
       Access path maintenance . . . . . . . . . . : MAINT      *IMMED                
       Unique key values required  . . . . . . . . : UNIQUE     No                    
       Key order . . . . . . . . . . . . . . . . . :            Not specified         
       Access path journaled . . . . . . . . . . . :            No                    
       Access path . . . . . . . . . . . . . . . . :            Keyed                 
       Constraint Type . . . . . . . . . . . . . . :            NONE                  
       Number of key fields  . . . . . . . . . . . :              1                   
       Record format . . . . . . . . . . . . . . . :            RINFO                 
         Key field . . . . . . . . . . . . . . . . :            EMPID                 
           Sequence  . . . . . . . . . . . . . . . :            Ascending             
           Sign specified  . . . . . . . . . . . . :            UNSIGNED              
    

    Currently, once files are journaled just run the command DSPJRN.

    DSPJRN JRN(JRN0000001)

    You will see the following entries which comprise Code and Type within that Code, Object, etc. Code 'J' means it's a Journal or receiver operation and with the Code J category we have different types such as 'PR' means Previous Journal receiver operation. Then we can notice 2nd entry with Code 'D' which means it's a Database file operation being performed on file INFO and Type 'JF' means Start Journaling for files. The 3rd entry id 'F' which means Database File member operation on file INFO and type 'JM' means Start journaling for the member.

                               Display Journal Entries                          
                                                                                
    Journal  . . . . . . :   JRN0000001      Library  . . . . . . :   EASYCLASS1
    Largest sequence number on this screen  . . . . . . : 00000000000000000003  
    Type options, press Enter.                                                  
      5=Display entire entry                                                    
                                                                                
                                                                                
    Opt    Sequence  Code  Type  Object      Library     Job         Time       
                  1   J     PR                           QPAD065250   7:12:55   
                  2   D     JF   INFO        EASYCLASS1  QPAD065250   7:32:35   
                  3   F     JM   INFO        EASYCLASS1  QPAD065250   7:32:36   
    

    Four basic journal entry categories have different Journal Entry Types on IBM i

    The most common journal entries fall into four basic categories (J, F, R, C)

    Within each category, there are several different journal entry types represented by a two-character entry code (e.g. PR, NR for journal entry J).

    • J (Journal and journal receiver operations)
      • PR(Previous receiver)
      • NR(Next Receiver)
    • F(File Operations)
      • OP(File Open)
      • CL(Close)
    • R(Record Operations)
      • UP & UB(Record Updates)
      • DL(Delete)
      • PT & PX(Record Written)
    • C( Commitment control)
      • BC(Begin commitment control)
      • SC(Start a Commit Cycle)
      • CM(Commit Operation)
      • RB( Rollback operation)

    J (Journal and journal receiver operations), PR(Previous receiver), NR(Next Receiver)

    These include such things as references to the previous receiver (PR) or the next receiver (NR) in a chain.

                               Display Journal Entries                          
                                                                                
    Journal  . . . . . . :   JRN0000001      Library  . . . . . . :   EASYCLASS1
    Largest sequence number on this screen  . . . . . . : 00000000000000000003  
    Type options, press Enter.                                                  
      5=Display entire entry                                                    
                                                                                
                                                                                
    Opt    Sequence  Code  Type  Object      Library     Job         Time       
                  1   J     PR                           QPAD065250   7:12:55   
    

    F(File Operations) OP(File Open), CL(Close)

    This category includes file opens (OP) and file closes (CL).

    Run UPDDTA info command from command line.

    upddta info 

    UPDDTA screen

    WORK WITH DATA IN A FILE                       Mode . . . . :   CHANGE   
    Format . . . . :   RINFO                       File . . . . :   INFO     
                                                                             
    EMPID:      1                                                            
    EMPADDRESS: NOIDA                                                        
    EMPAGE:     26                                                           
    

    Take F3 to exit

                                   End Data Entry               
                                                                
      Number of records processed                               
                                                                
        Added  . . . . . :           0                          
        Changed  . . . . :           0                          
        Deleted  . . . . :           0                          
                                                                
                                                                
                                                                
                                                                
    Type choice, press Enter.                                   
                                                                
      End data entry  . . . . . . .    Y           Y=Yes,  N=No 
    

    Code F and Type OP(File Open) and CL(File Close) entries made into journal. Run the command DSPJRN JRN0000001

                               Display Journal Entries                          
                                                                                
    Journal  . . . . . . :   JRN0000001      Library  . . . . . . :   EASYCLASS1
    Largest sequence number on this screen  . . . . . . : 00000000000000000011  
    Type options, press Enter.                                                  
      5=Display entire entry                                                    
                                                                                
                                                                                
    Opt    Sequence  Code  Type  Object      Library     Job         Time       
                  1   J     PR                           QPAD065250   7:12:55   
                  2   D     JF   INFO        EASYCLASS1  QPAD065250   7:32:35   
                  3   F     JM   INFO        EASYCLASS1  QPAD065250   7:32:36   
                  4   F     OP   INFO        EASYCLASS1  QPAD063250   6:34:53   
                  5   F     OP   INFO        EASYCLASS1  QPAD063250   6:34:53   
                  6   F     CL   INFO        EASYCLASS1  QPAD063250   6:35:40   
                  7   F     CL   INFO        EASYCLASS1  QPAD063250   6:35:40   
    

    R(Record Operations)

    Record updates (UP), deletes (DL), and new records written (PT and PX) all fall into this category.

    Run UPDDTA info command from command line to update one record.

    upddta info 

    UPDDTA screen

    WORK WITH DATA IN A FILE                       Mode . . . . :   CHANGE   
    Format . . . . :   RINFO                       File . . . . :   INFO     
                                                                             
    EMPID:      1                                                            
    EMPADDRESS: NOIDA                                                        
    EMPAGE:     26                                                           
    

    Change EMPADDRESS

    WORK WITH DATA IN A FILE                       Mode . . . . :   CHANGE   
    Format . . . . :   RINFO                       File . . . . :   INFO     
                                                                             
    EMPID:      1                                                            
    EMPADDRESS: NOIDA-CHG                                                        
    EMPAGE:     26                                                           
    

    Take F3 to save and exit

                                   End Data Entry               
                                                                
      Number of records processed                               
                                                                
        Added  . . . . . :           0                          
        Changed  . . . . :           0                          
        Deleted  . . . . :           0                          
                                                                
                                                                
                                                                
                                                                
    Type choice, press Enter.                                   
                                                                
      End data entry  . . . . . . .    Y           Y=Yes,  N=No 
    

    Code R and Type UB(Update-Before Image) and UP(Update-After Image) entries made into journal including OP and CL entries since file was opened and closed during update operation. Run the command DSPJRN JRN0000001

                               Display Journal Entries                          
                                                                                
    Journal  . . . . . . :   JRN0000001      Library  . . . . . . :   EASYCLASS1
    Largest sequence number on this screen  . . . . . . : 00000000000000000024  
    Type options, press Enter.                                                  
      5=Display entire entry                                                    
                                                                                
                                                                                
    Opt    Sequence  Code  Type  Object      Library     Job         Time       
                 20   F     OP   INFO        EASYCLASS1  QPAD063250   6:42:06   
                 21   F     OP   INFO        EASYCLASS1  QPAD063250   6:42:06   
                 22   R     UB   INFO        EASYCLASS1  QPAD063250   6:42:14   
                 23   R     UP   INFO        EASYCLASS1  QPAD063250   6:42:14   
                 24   F     CL   INFO        EASYCLASS1  QPAD063250   6:42:15    
                 25   F     CL   INFO        EASYCLASS1  QPAD063250   6:42:15
    

    Take option 5 on UB and UP entries to see what was the before change and after change image

    Before Image

                                 Display Journal Entry                           
                                                                                 
     Object . . . . . . . :   INFO            Library  . . . . . . :   EASYCLASS1
     Member . . . . . . . :   INFO                                               
     Incomplete data  . . :   No              Minimized entry data :   *NONE     
     Sequence . . . . . . :   22                                                 
     Code . . . . . . . . :   R  - Operation on specific record                  
     Type . . . . . . . . :   UB - Update, before-image                          
                                                                                 
                 Entry specific data                                             
     Column      *...+....1....+....2....+....3....+....4....+....5              
     00001      '1     NOIDA                ?'                                   
     

    After Image

                                Display Journal Entry                           
                                                                                
    Object . . . . . . . :   INFO            Library  . . . . . . :   EASYCLASS1
    Member . . . . . . . :   INFO                                               
    Incomplete data  . . :   No              Minimized entry data :   *NONE     
    Sequence . . . . . . :   23                                                 
    Code . . . . . . . . :   R  - Operation on specific record                  
    Type . . . . . . . . :   UP - Update, after-image                           
                                                                                
                Entry specific data                                             
    Column      *...+....1....+....2....+....3....+....4....+....5              
    00001      '1     NOIDA-CHG            ?'                                   
    

    The same way you can INSERT and DELETE records which will maded respective entries to the journal.

    C( Commitment control) , BC(Begin commitment control),SC(Start a Commit Cycle),CM(Commit Operation), RB( Rollback operation)

    Anything related to commitment control falls into this category. Some examples are beginning commitment control (BC), start a commit cycle (SC), commit operation (CM) and rollback operation (RB).

    Journaling commands on IBM i

    APYJRNCHG: Uses the journal entries to apply changes that have occurred since a database file was saved or some other specified time.

    CHGJRN: Use this command to change the attributes of a journal or to attach new journal receivers to a journal.

    DLTJRN: Use this command to delete a journal.

    DLTJRNRCV: Use this command to delete a journal receiver.

    DSPJRN: This command displays or prints the journal entries that are in the journal receivers associated with the specified journal. This command has outfile support so you can list the journal entries to a database output file for further processing or analysis.

    DSPJRNRCVA: Use this command to display the attributes of a journal receiver.

    ENDJRNPF: This command ends journaling for the specified physical file.

    RCVJRNE: This command allows a specified user program to continuously receive journal entries one at a time as they are written to the journal. The behavior is similar to an exit program.

    RMVJRNCHG: Use this command to remove changes that have occurred to a database file from a specified point in time to some previous point in time (allowed only if before-images were recorded during the time).

    RTVJRNE Use this command to retrieve a journal entry and place it in CL program variables.

    SNDJRNE: Use this command to write user-defined entries to a journal (i.e., journal receiver).

    WRKJRN: This command displays a menu from which you can perform many journal-related functions, such as the system-assisted recovery of journaled files.

    Generating Outfile for Journal Entries

    Outfile support has been provided to the DSPJRN command. Therefore, whatever entries made to the journal can be taken into the outfile for further processing in the program.

    Run the below command to generate outfile named JRNFILE in library QTEMP.

    DSPJRN JRN(JRN0000001)             
           OUTPUT(*OUTFILE)            
           OUTFILE(EASYCLASS1/JRNFILE) 
    

    Below message will appear once the outfile is created. In my case there were 25 Journal entries available and has been exported to the outfile.

    Output file JRNFILE created in library EASYCLASS1.
    Member JRNFILE added to output file JRNFILE in library EASYCLASS1.
    25 entries converted from journal JRN0000001 in EASYCLASS1.
    

    Display outfile records



    Post a Comment

    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain