TechTip: Deleting All Records That Match a Key

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

Q: Help! I am trying to remove indicators in my program, but I am having a problem with a particular loop in which I perform a CHAIN and READE to delete records. I've been trying to use BIFs to solve the problem, but I still can't figure out how to make it work.

 

c     MyKey         chain     MyFile                             90 
c                   dow       *IN90 = *OFF
c                   delete    MyRecord
c     MyKey         reade     MyFile                                 90
c                   enddo                       


I can use the %FOUND BIF to replace the indicator for the CHAIN and the %EOF BIF to replace the indicator for the READE, but I get an odd complex DOW statement:

c                   dow       %FOUND(MyFile) or NOT %EOF(MyFile)


This seems too complicated and looks as if it might even work incorrectly. Is there a better way?

A: There are actually two ways around this particular problem. My favorite is to use the keyed delete capability of RPG:

c                   dou       not %FOUND(MyFile)
c     MyKey         delete    MyFile
c                   enddo                       


It's simple and straightforward, and it uses fewer lines of code than the original. I like it.

A second technique uses SQL, but for that, you need to know the name of the key fields in the file and the names of the fields to match from the program. Let's say the fields in the file are DbKey1 and DbKey2, and the program fields are MyKey1 and MyKey2. You could use an embedded SQL statement like the following to delete all the matching records:

C/Exec SQL 
C+ DELETE FROM KFRPL01 where DbKey1 = :MyKey1 and DbKey2 = :MyKey2
C/End-exec 


Those are two ways to perform an indicator-free delete of all records matching a specific key.

Joe Pluta is the founder and chief architect of Pluta Brothers Design, Inc., which offers PSC/400, the only product that can move your legacy systems to the Web using simple green-screen commands. He has been working in the field since the 1970s and has made a career of extending the IBM midrange, starting back in the days of the IBM System/3. Joe is also the author of two books, E-Deployment: The Fastest Path to the Web and Eclipse: Step by Step, as well as "Weaving WebSphere," a monthly column in MC Mag Online. You can reach him at This email address is being protected from spambots. You need JavaScript enabled to view it..

 

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: