fhg
Volume 7, Number 10 -- March 14, 2007

Release That Record Lock!

Published: 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


Sponsored By
WORKSRIGHT SOFTWARE

Do you need area code information?
Do you need ZIP Code information?
Do you need ZIP+4 information?
Do you need city name information?
Do you need county information?
Do you need a nearest dealer locator system?

We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

Just call us and we'll arrange for 30 days FREE use of either
ZIP/CITY or PER/ZIP4.

WorksRight Software, Inc.
Phone: 601-856-8337
Fax: 601-856-9432
E-mail: software@worksright.com
Web site: www.worksright.com


Senior Technical Editor: Ted Holt
Technical Editors: Howard Arner, Joe Hertvik, Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Brian Kelly, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

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

 

The Four Hundred
IBM's Plan for an Adjacent, Custom Systems Market

WDSc Version 7.0 Standard Edition Is Missing Two Key Features

Is Upgrading a Silly Waste of Time and Money?

As I See It: The Digital Life

The Linux Beacon
Intel Delivers Low-Power, Quad-Core Xeon Chips

HP Touts its Prowess in Linux and Open Source

Server Makers Have $5.3 Billion Bumper Crop in Q4 in Europe

As I See It: The Digital Life

Four Hundred Stuff
SOA, What's The Big Deal?

Asigra Debuts Remote, Agent-Less Backup for iSeries

Lawson Updates ERP, Unveils SaaS Plans at User Conference

Attachmate Moves SOA Strategy Forward with Veratream 6.5

Big Iron
Putting the z in College Degrees

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
March 10, 2007: Volume 9, Number 10

March 3, 2007: Volume 9, Number 9

February 24, 2007: Volume 9, Number 8

February 17, 2007: Volume 9, Number 7

February 10, 2007: Volume 9, Number 6

February 3, 2007: Volume 9, Number 5

The Windows Observer
Microsoft Lacks Innovation, Fairness in Pricing of Protocols, EC Says

Symantec Gives Vista Security a So-So Grade

Midrange Boxes, Big Iron Drive Server Growth in Q4 2006

HP Ships Virtual Connect I/O for Blades, Adds Blade Workstation

The Unix Guardian
Midrange Boxes, Big Iron Drive Server Growth in Q4 2006

SCO's Unix Sales Continue to Slide, But Red Ink Is Shallower

HP Unix Behemoth Squeaks By IBM Big Iron on TPC Test

Mad Dog 21/21: Paved With Good Intentions

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

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

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
How to collect the object authorities in a PF

Printer override in CLP using QCMDEXC

How to install a network printer in the iSeries?

Referencing the key of current record

MCH5003 creating objects in library





 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement