• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Release That Record Lock!

    March 14, 2007 Dear Professional

    Have you ever changed your password, then forgot what you changed it to? No, of course you haven’t. But I have, and on more than one occasion! Have you ever revoked your own authority to an object? It seems to me I’ve done that, too. When I do such things, I lock myself out of some resource. Recently, I was asked to work on a program that had locked itself out of a database record. I’ve seen one program lock another program out of a record many times, but I can’t ever remember a program locking itself out of a record. Anyway, there’s a lesson in this experience we can all benefit from.

    Here’s the situation. An RPG program accessed one physical file through three access paths–the physical file itself and two logical files that were built over the physical file. The program screeched to a halt when a record that had been read and locked for update through one access path was requested to be read for update through another access path. The system generated error message CPF5032 (Record 2 member CUSMASLC already locked to this job.)

    I wrote a short demo program to illustrate this situation.

    *** CusMas is a physical file keyed on company number & customer number.
    FCusMas    uf   e           k disk    rename(CusMasMA: CusMas1)   
    F                                     infds(infds1)    
    F
    *** CusMasLC is a logical file keyed on customer name.
    FCusMasLC  uf   e           k disk    rename(CusMasRC: CusMas2)   
    F                                     infds(infds2)               
    
    D SearchComp      s              2p 0                             
    D SearchCus       s              8p 0                             
                                
    D infds1          ds                                              
    D Stat1             *status                                       
    D infds2          ds                                              
    D Stat2             *status                                       
                                                                     
    C     Search        klist                                         
    C                   kfld                    SearchComp            
    C                   kfld                    SearchCus             
    C                                                                 
    C                   eval      SearchComp = 1                      
    C                   eval      SearchCus = 302                     
    C                                                                 
    C                   eval      *inlr = *on                         
    C                                                                 
    C     Search        chain     CusMas1
    C                   if        %found and CusCl ='27'
    C                   eval      Terrn = 5             
    C                   update    CusMas1               
    C                   endif                           
    C      
    C* imagine a lot of calculation specs here
    C                                             
    C     CusNm         chain     CusMas2               
    C                   if        %found                
    C                   eval      DCode = 3             
    C                   update    CusMas2               
    C                   endif                           
    C                                                   
    C                   return
    

    CUSMAS is a physical file containing customer information. CUSMASLC is a logical file that accesses CUSMAS by customer name. The first chain succeeds, but the IF that follows the chain fails because customer 302 in company 1 does not have a class code of 27. The UPDATE does not happen, which means that customer 302’s record remains locked.

    Imagine a lot of calculations taking place, until finally the second chain attempts to retrieve the same record by customer name. The record exists, of course, but it is locked. After the time-out period, the system sends CPF5032. By the way, if another program tried to access the locked record, it would error out with message RNQ1218 (Unable to allocate a record in file CUSMAS (R C G D F).)

    It’s not hard to see the proper solution, which is to unlock the record if the condition fails.

    C     Search        chain     CusMas1
    C                   if        %found and CusCl ='27'
    C                   eval      Terrn = 5             
    C                   update    CusMas1               
    C                   else
    C                   unlock    CusMas
    C                   endif                           
    

    (I wonder: “If the solution is obvious and so easy to implement, why didn’t the programmer code the unlock in the first place?”)

    Those of you who have had your morning coffee are wondering: “What if the chain fails? There’s nothing to unlock.” And the answer is that the unlock doesn’t blow up. Suppose the update is buried within two or more levels of nested logic.

    C     Search        chain     CusMas1               
    C                   if        %found and CusCl ='27'
    C     RepKey        chain     RepMas                
    C                   if        %found and Terr = 'W' 
    C                   eval      Terrn = 5             
    C                   update    CusMas1               
    C                   endif                           
    C                   endif                           
    C                   unlock    CusMas                
    

    Rather than code an unlock operation for each level, one unlock suffices for all.

    Anyway, I try hard to develop and adhere to good programming practice. Here’s a rule of thumb that’s worth keeping in mind: If you embed an update or delete operation within a condition, be sure to release the lock if the condition doesn’t pan out.

    –Ted



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Guild Companies:  Search OS/400 titles in our bookstore
    LXI:  Disk to disk backup with centralized control
    COMMON:  Join us at the 2007 conference, April 29 – May 3, in Anaheim, California

    IT Jungle Store Top Book Picks

    The System i Pocket RPG & RPG IV Guide: List Price, $69.95
    The iSeries Pocket Database Guide: List Price, $59.00
    The iSeries Pocket Developers' Guide: List Price, $59.00
    The iSeries Pocket SQL Guide: List Price, $59.00
    The iSeries Pocket Query Guide: List Price, $49.00
    The iSeries Pocket WebFacing Primer: List Price, $39.00
    Migrating to WebSphere Express for iSeries: List Price, $49.00
    iSeries Express Web Implementer's Guide: List Price, $59.00
    Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95
    Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
    Getting Started with WebSphere Express for iSeries: List Price, $49.00
    WebFacing Application Design and Development Guide: List Price, $55.00
    Can the AS/400 Survive IBM?: List Price, $49.00
    The All-Everything Machine: List Price, $29.95
    Chip Wars: List Price, $29.95

    Capgemini Picks looksoftware to Modernize i5/OS Banking Software SOA, What’s The Big Deal?

    Leave a Reply Cancel reply

Volume 7, Number 10 -- March 14, 2007
THIS ISSUE SPONSORED BY:

WorksRight Software
COMMON
Guild Companies

Table of Contents

  • Release That Record Lock!
  • Giving RSE a Split Personality
  • Admin Alert: The Better Way to Send Break Messages to Active Users in i5/OS

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • The Power11 Transistor Count Discrepancies Explained – Sort Of
  • Is Your IBM i HA/DR Actually Tested – Or Just Installed?
  • Big Blue Delivers IBM i Customer Requests In ACS Update
  • New DbToo SDK Hooks RPG And Db2 For i To External Services
  • IBM i PTF Guide, Volume 27, Number 33
  • Tool Aims To Streamline Git Integration For Old School IBM i Devs
  • IBM To Add Full System Replication And FlashCopy To PowerHA
  • Guru: Decoding Base64 ASCII
  • The Price Tweaking Continues For Power Systems
  • IBM i PTF Guide, Volume 27, Numbers 31 And 32

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle