OPNQRYF vs. RPG

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

Q: Is it faster to use the Open Query File (OPNQRYF) command to read a file and select a number of records, or to read the file in an RPG program and select the records there? I get the impression that if you use OPNQRYF, you are essentially processing some records twice-once when they are read by OPNQRYF and again when the RPG program using the records processes them. Is this true?

A: It really depends on your application and how you are processing the records. OPNQRYF will beat RPG reads hands-down when you are processing records where the selection is variable. This means that you can build an OPNQRYF request dynamically and execute it-and your RPG program doesn't have to worry about the selection. If you are processing a specific selection all the time, a logical file might be a better approach.

OPNQRYF is faster because it selects the records at the microcode level. No data is "brought" up to the application program level. This saves time. When you read a record in RPG, it must be brought all the way into your program before any decision can be made on whether you need it.

I use OPNQRYF, SQL and dedicated logicals. Which is the best really depends on what I am trying to do. For example, if I have a file with 100,000 records and I need to execute a report based on input criteria from the end user, I probably would use OPNQRYF if record selection is based on fields that are not key fields. If the selection is based on a key field, then it might be faster to use a logical instead.

Here's my general rule of thumb: If the number of records is small-that is, if I know I am only going to read a few records in the RPG program-I will not use OPNQRYF. However, if the number of records in the file is large and my selection is small, I will use OPNQRYF. Each tool provided is valuable. Learn each one and then use it when the application design makes it the most advantageous.

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: