Guild Companies, Inc.  
 
Midrange Guru - Tech Tips
OS/400 Edition
Volume 2, Number 4 - January 18, 2002

Avoiding Record Locks in RPG

Hey, Ted:

Some of our users are in the habit of using file maintenance programs to look up information. We've provided them with inquiry screens, but old habits die hard.

This practice causes problems for other jobs that update the locked records. The programs freeze for a minute or two and then send an error message.

How can we keep an RPG program from freezing up when it tries to randomly read a record that is locked by another job? -- Andy

That is a very good question, Andy. I assume you're already checking to make sure that the record was found. You can add a similar check for an error condition. Code an indicator in the LO resulting indicator position.

The following RPG code illustrates this technique:

FCUSTOMERUF  E           K        DISK
F                                              KINFDS INFO

I           SDS
I                                       91 170 ERRMSG
IINFO        DS
I                                     *STATUS  FSTAT

 **                                             HILOEQ
C           CUSKEY    CHAINCUSTREC              4142
C                     SELEC
C           *IN42     WHEQ *ON
  .... put record-locked logic here
C           *IN41     WHEQ *ON
  .... put record-not-found logic here

If the record is locked, the system turns on indicator 42 and loads an error message into positions 91 through 170 of the program status data structure. The message looks like this:

Record 5 in use by job 185008/SMITH/SMITHJOB.

Also, the system will place the value 01218 in the *STATUS subfield (positions 11 through 15) of the file information data structure.

If you're using RPG IV, you can throw away the indicators. Use the E operation extender on the chain op code to tell RPG to signal an error, and follow with a test for the %ERROR and %STATUS built-in functions. Here's an example:

FCUSTOMER  UF   E             DISK
DSDS             SDS 
D ERRMSG                 91    170 
C     CUSKEY        CHAIN(E)  CUSTREC
C                   SELECT
C* Error retrieving record
C                   WHEN      %ERROR
C* Record lock error
C                   IF        %STATUS = 1218
C                   ENDIF
C                   WHEN      %FOUND
C                   UPDATE    CUSTREC
C                   OTHER
C                   ENDSL

The delay time is an attribute of the database file. The default is 60 seconds. Use the Maximum Record Wait Time (WAITRCD) parameter of the Create Physical File (CRTPF), Change Physical File (CHGPF), or Override with Database File (OVRDBF) commands to adjust this value. If you do not want the job to wait for the record to become available, specify WAITRCD(*IMMED), as this override command illustrates:

OVRDBF     FILE(CUSTOMER) WAITRCD(*IMMED)

I want to thank Barbara Morris of IBM Toronto for her assistance in working up this tip.

-- Ted

Sponsored By
LANSA

LANSA INTEGRATOR SPEEDS DEVELOPMENT & PERFORMANCE OF JAVA

LANSA Partner MDC replaced its hand-written Java remote system integration programs with LANSA Integrator and gained a tenfold increase in performance. InsureIT uses LANSA Integrator to offer XML Java services between heterogeneous insurer & broker systems.

Find out more at http://www.lansa.com/press/20122.htm

THIS ISSUE
SPONSORED BY:
WorksRight Software
LANSA
BACK ISSUES
TABLE OF CONTENTS
Determine WebSphere Service Pack Level
Avoiding Record Locks in RPG
Reader Feedback and Insights
  Newsletters | Subscribe | Advertise | About Us | Contact | Search | Home  
  Last Updated: 1/14/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.