TechTip: Wresting Your Files Away from SQL Pseudo-Close

SQL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Sometimes you want to do something simple and you can't because SQL has your file; this tip provides the fix.

SQL is a powerful tool that provides fast access to your data. In order to stay fast, though, it does a few things under the covers that don't always coexist nicely with the rest of the operating system. Today's tip focuses on a specific case, the pseudo-closed cursor.

 

The operating system pseudo-closes a cursor (or more specifically, an open data path or ODP) when it determines that such action would benefit performance. It does this in a rather clever way: if the same program opens the same ODP twice, then the second close is a pseudo-close. I think this is a pretty reasonable compromise. The first open doesn't leave the ODP open; it's the second one that triggers that behavior. So why do this at all? Because extra ODPs have a couple of negative effects. First is the overhead of the ODP itself, and second is the fact that this tends to lock the file in such a way that you can't do certain operating system functions. It's this second problem that we're going to address here.

 

Many commands require exclusive access to a file. Examples include CLRPFM and CRTDUPOBJ. If you've ever tried to execute one of these commands only to find a lock on the file and then use WRKOBJLCK to find that a QZDASOINIT job has your file locked, then you've run into the pseudo-close. You won't be able to clear or duplicate your file without using an alternate technique. Alternates do exist; you can use DELETE FROM MYFILE in SQL with no WHERE clause to clear a file or you can execute a CPYF with CRTFILE(*YES) to duplicate a file and then clear it with CLRPFM. But these other solutions can be a bit clumsy, and even if they weren't, they still don't help when you've got to run a program that executes one of those commands.

 

The good news is that it's relatively easy to get rid of those locks. All you need to do is force those cursors to be closed by using the ALCOBJ command. The CONFLICT keyword is a relatively recent addition to the command, and its sole purpose is to resolve those holds. The syntax is simple. Here's an example:

 

ALCOBJ OBJ((MYLIB/MYFILE *FILE *EXCL)) CONFLICT(*RQSRLS)

 

This will attempt to place an exclusive lock on the file MYFILE in MYLIB. If any pseudo-closed cursors exist, the operating system will hard-close them, making the file available for lock. You can then proceed on to whatever command it was that you needed to perform. Remember that this will only remove locks from pseudo-closes. It won't magically break locks from other jobs; that would be a potentially disastrous action. But if the only problem is that you have some locks because SQL is caching some cursors, then you can fix that. WARNING: remember to remove the lock using the DLCOBJ command; otherwise, other people won't be able to use the file!

 

I hope this provides an easy resolution to an annoying problem for some of you.

 

Joe Pluta

Joe Pluta is the founder and chief architect of Pluta Brothers Design, Inc. He has been extending the IBM midrange since the days of the IBM System/3. Joe uses WebSphere extensively, especially as the base for PSC/400, the only product that can move your legacy systems to the Web using simple green-screen commands. He has written several books, including Developing Web 2.0 Applications with EGL for IBM i, E-Deployment: The Fastest Path to the Web, Eclipse: Step by Step, and WDSC: Step by Step. Joe performs onsite mentoring and speaks at user groups around the country. You can reach him at This email address is being protected from spambots. You need JavaScript enabled to view it..


MC Press books written by Joe Pluta available now on the MC Press Bookstore.

Developing Web 2.0 Applications with EGL for IBM i Developing Web 2.0 Applications with EGL for IBM i
Joe Pluta introduces you to EGL Rich UI and IBM’s Rational Developer for the IBM i platform.
List Price $39.95

Now On Sale

WDSC: Step by Step WDSC: Step by Step
Discover incredibly powerful WDSC with this easy-to-understand yet thorough introduction.
List Price $74.95

Now On Sale

Eclipse: Step by Step Eclipse: Step by Step
Quickly get up to speed and productivity using Eclipse.
List Price $59.00

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: