Tips and Techniques: A Hidden Performance Issue

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

One of the most intriguing aspects of writing code for clients that have huge/enormous databases is that you get to test the performance of RPG IV features. One feature that continues to annoy me is the fact that a character return value from a procedure that is VARYING sucks from a performance perspective.




For example:

     D ToUpper         PR         32766A   Varying    
     D  inString                  32766A   VALUE Varying  

Seems logical, right? If you convert a character string to uppercase, you want to return the same size/length value to the caller, so the following would be a valid call to TOUPPER:

     D CompName        S             25A   Inz('The Spacecraft Co.')
    
     C                   eval      CompName = ToUpper(CompName)

Obviously, this converts the COMPNAME field to all uppercase letters. But what we don't see is that that the long 32K return value is causing a performance issue. Even through it is varying, the system still returns the entire 32K of data and throws away the extra bytes, a waste of resources.

When the load is light or when TOUPPER is called only once or perhaps a few times per transaction, then this overhead isn't important. But when you call TOUPPER hundreds, thousands, or perhaps millions of times, there could be problems.

To resolve this problem, you need to avoid returning a value and instead pass an additional parameter that is updated.

For example:

     D ToUpper         PR            10I 0
     D  InString                  32766A   Const Varying 
     D  OutString                 32766A   OPTIONS(*VARSIZE)

The second parameter now becomes the target of the conversion, and the OPTIONS(*VARSIZE) allows you to pass a parameter whose length is 1 to 32766 bytes. You simply use %LEN(InString) inside the subprocedure to determine how much data was actually passed to your subprocedure. Then, be sure to "touch" only that many characters in the OUTSTRING parameter.

One problem that arises using this technique, however, is that you can no longer use a VARYING field to receive the output, and this does present restriction. One solution is to have two subprocedures, one that supports fixed-length output and a second one that supports varying-length fields.

For example:

     D ToUpperV        PR            10I 0
     D  InString                  32766A   Const Varying       
     D  OutString                 32766A   VARYING OPTIONS(*VARSIZE)

Bob Cozzi has been programming in RPG since 1978. Since then, he has written many articles and several books, including The Modern RPG Language--the most widely used RPG reference manual in the world. Bob is also a very popular speaker at industry events such as RPG World and is the author of his own Web site and of the RPG ToolKit, an add-on library for RPG IV programmers.

BOB COZZI

Bob Cozzi is a programmer/consultant, writer/author, and software developer. His popular RPG xTools add-on subprocedure library for RPG IV is fast becoming a standard with RPG developers. His book The Modern RPG Language has been the most widely used RPG programming book for more than a decade. He, along with others, speaks at and produces the highly popular RPG World conference for RPG programmers.


MC Press books written by Robert Cozzi available now on the MC Press Bookstore.

RPG TnT RPG TnT
Get this jam-packed resource of quick, easy-to-implement RPG tips!
List Price $65.00

Now On Sale

The Modern RPG IV Language The Modern RPG IV Language
Cozzi on everything RPG! What more could you want?
List Price $99.95

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: