ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Cobol Trigger Buffer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cobol Trigger Buffer

    Dear all,

    I have problema related to Cobol triggers, I will explain so you can understand the problema.

    We are adapting a core banking from and old version to the newest, said core has the same tables that it used to but these, have change in both size and number of fields.

    We are having trouble setting up the buffer on these programs, here is an example:

    The table FDBLOP shown in the picture has 223 fields and 2060 size in the old version, the new one has 649 fields and a register size of 8969.

    Old:
    Formato Campos Longit Identificador
    LOGREC 223 2069 400BB60D2C5C6

    New:
    Formato Campos Longit Identificador
    LOGREC 649 8969 22D0E2A46B6AE

    The BUFFER in the Cobol ILE Trigger is defined as follows:

    OLD VERSION
    03 RECORD-JUNK.
    05 OLD-RECORD PIC X(8969).
    05 OLD-NULL-MAP PIC X(223).
    05 FILLER PIC X(5).
    05 NEW-RECORD PIC X(8969).
    05 NEW-NULL-MAP PIC X(223).

    NEW VERSION
    03 RECORD-JUNK.
    05 OLD-RECORD PIC X(8969).
    05 OLD-NULL-MAP PIC X(223).
    05 FILLER PIC X(14).
    05 NEW-RECORD PIC X(8969).
    05 NEW-NULL-MAP PIC X(223).

    We had a lot of trouble to figure out that the FILLER between both registers must be change, we can?t understand why this is happening and neither we can find information in the IBM documentation.

    Could anybody help us in this matter?

    Best regards,
    Thanks

  • #2
    The way this originally appears to have been coded is no good practice and (as you have discovered) almost certain to cause problems every time the file is updated. If you "speak" RPG you may get some ideas on how best to handle it from this: http://ibmsystemsmag.com/CMSTemplate...Trigger-Happy-

    The _exact_ same technique should be used for COBOL. Place the before and after record images in the Linkage section so they can be based on a pointer. These will map to the OldRecord and NewRecord strucures in the RPG. Set the pointer for the record images using COBOL's SET ADDRESS OF (I think that's right). Never, never, ever code the records directly in the buffer as your example does.

    It is late now but I will try to code a COBOL example for you tomorrow if you need it.

    Comment


    • #3
      Here is an example using the LINKAGE Section. The contents of the copybook QSYSINC-QCBLLESRC is not shown here...

      Code:
             working-storage section.                                     
             01  New-Pointer usage is pointer.         
             01  Old-Pointer usage is pointer.         
      
      
             linkage section.                                                
      
                           copy TRGBUF           in QSYSINC-QCBLLESRC.       
      
            *--->                                              Trigger Buffer
            *--->                                             length (unused)
             01  QBD-TRIGGER-PARM2.                                          
                 03  QDB-TRIGGER-LEN          pic  x(02).                    
      
            *---------------------------------------------------------------*
            *          Copy of the an Integration Control/Log file          *
            *---------------------------------------------------------------*
      
             01  OLDrecd.                                                 
               03  Old-Entry.                                             
                           copy ddr-I55002       of F55002                
                           prefix by 'OLD-'.                              
               03  Old-Offset.                                            
                 05  Offset-Old-Rec       pic s9(08)              binary.
      
             01  NEWrecd.                                                 
               03  New-Entry.                                             
                           copy ddr-I55002       of F55002                
                           prefix by 'NEW-'.                              
               03  New-Offset.                                            
                 05  Offset-New-Rec       pic s9(08)              binary.
      
      
      
             procedure division                                              
                          using QDB-TRIGGER-BUFFER                           
                                QBD-TRIGGER-PARM2                            
                 .                                                           
             000-Main Section.                                               
             000-Begin.                                                      
            *---------------------------------------------------------------*
            * First, set a pointer to the address of the NEW record layout  *
            * in the linkage area. All INSERTS and UPDATES utilize the NEW  *
            * record buffer, which represents the database record before it *
            * has been physically committed by the database manager.        *
            *---------------------------------------------------------------*
      
                 set New-Pointer to address of QDB-TRIGGER-BUFFER            
                 set New-Pointer up by NEW-RECORD-OFFSET                     
                 set address of NEWrecd to New-Pointer                   
      
            *---------------------------------------------------------------*
            * If this trigger was a result of an UPDATE or INSERT then we   *
            * set a pointer to access the OLD record buffer because we need *
            * to access the image BEFORE it was changed/added.              *
            *                                                               *
            * Trigger-Event tells us under which circumstances it was fired *
            *                                                               *
            *                  1 = Insert     3 = Update                    *
            *                  2 = Delete     4 = Read                      *
            *---------------------------------------------------------------*
      
                 if TRIGGER-EVENT = '2'                                      
                 or TRIGGER-EVENT = '3'                                      
                     set Old-Pointer to address of QDB-TRIGGER-BUFFER        
                     set Old-Pointer up by OLD-RECORD-OFFSET                 
                     set address of OLDrecd to Old-Pointer       
                 end-if
      This program captures adds, changes and deletes and performs different logic based on the scenario.

      Comment


      • #4
        Thanks for posting that Terry.

        That's exactly the way I would have coded it. Well - except I don't much like the names in the QSYSINC and in the past have used my own Copy book for the fixed portion of the buffer definition.

        Comment


        • #5
          Agreed...I don't like the copybook names either! At a minimum, IBM should have prefixed them with something generic.

          To be honest, I use their copybook in the event changes occur in the future...hoping it will reduce any conversion time...just in case.

          Comment


          • #6
            Originally posted by Terry Wincheste View Post
            Agreed...I don't like the copybook names either! At a minimum, IBM should have prefixed them with something generic.

            To be honest, I use their copybook in the event changes occur in the future...hoping it will reduce any conversion time...just in case.
            I also copy and rename their copybook fields, but I keep IBMs original field name as a comment next to the new field name to make it easier for those future changes.

            Comment


            • #7
              Originally posted by JonBoy View Post
              The way this originally appears to have been coded is no good practice and (as you have discovered) almost certain to cause problems every time the file is updated. If you "speak" RPG you may get some ideas on how best to handle it from this: http://ibmsystemsmag.com/CMSTemplate...Trigger-Happy-

              The _exact_ same technique should be used for COBOL. Place the before and after record images in the Linkage section so they can be based on a pointer. These will map to the OldRecord and NewRecord strucures in the RPG. Set the pointer for the record images using COBOL's SET ADDRESS OF (I think that's right). Never, never, ever code the records directly in the buffer as your example does.

              It is late now but I will try to code a COBOL example for you tomorrow if you need it.
              thank you, they are programs developed with a very old philosophy. You have helped me to understand a little the dimension of the problem.thanks!!

              Comment


              • #8
                Originally posted by Terry Wincheste View Post
                Here is an example using the LINKAGE Section. The contents of the copybook QSYSINC-QCBLLESRC is not shown here...

                Code:
                working-storage section.
                01 New-Pointer usage is pointer.
                01 Old-Pointer usage is pointer.
                
                
                linkage section.
                
                copy TRGBUF in QSYSINC-QCBLLESRC.
                
                *---> Trigger Buffer
                *---> length (unused)
                01 QBD-TRIGGER-PARM2.
                03 QDB-TRIGGER-LEN pic x(02).
                
                *---------------------------------------------------------------*
                * Copy of the an Integration Control/Log file *
                *---------------------------------------------------------------*
                
                01 OLDrecd.
                03 Old-Entry.
                copy ddr-I55002 of F55002
                prefix by 'OLD-'.
                03 Old-Offset.
                05 Offset-Old-Rec pic s9(08) binary.
                
                01 NEWrecd.
                03 New-Entry.
                copy ddr-I55002 of F55002
                prefix by 'NEW-'.
                03 New-Offset.
                05 Offset-New-Rec pic s9(08) binary.
                
                
                
                procedure division
                using QDB-TRIGGER-BUFFER
                QBD-TRIGGER-PARM2
                .
                000-Main Section.
                000-Begin.
                *---------------------------------------------------------------*
                * First, set a pointer to the address of the NEW record layout *
                * in the linkage area. All INSERTS and UPDATES utilize the NEW *
                * record buffer, which represents the database record before it *
                * has been physically committed by the database manager. *
                *---------------------------------------------------------------*
                
                set New-Pointer to address of QDB-TRIGGER-BUFFER
                set New-Pointer up by NEW-RECORD-OFFSET
                set address of NEWrecd to New-Pointer
                
                *---------------------------------------------------------------*
                * If this trigger was a result of an UPDATE or INSERT then we *
                * set a pointer to access the OLD record buffer because we need *
                * to access the image BEFORE it was changed/added. *
                * *
                * Trigger-Event tells us under which circumstances it was fired *
                * *
                * 1 = Insert 3 = Update *
                * 2 = Delete 4 = Read *
                *---------------------------------------------------------------*
                
                if TRIGGER-EVENT = '2'
                or TRIGGER-EVENT = '3'
                set Old-Pointer to address of QDB-TRIGGER-BUFFER
                set Old-Pointer up by OLD-RECORD-OFFSET
                set address of OLDrecd to Old-Pointer
                end-if
                This program captures adds, changes and deletes and performs different logic based on the scenario.
                Thank you! It has guided me a lot to solve my problem!

                Comment

                Working...
                X