• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Stuff I Didn’t Publish This Year

    December 13, 2006 Hey, Ted

    This is regarding your recent posting titled “Quick Query over a Database File” that was published on August 23, 2006. This is truly a useless utility. There already is a RUNQRY command. Why would you post this as something that someone might be interested in? I use to wait anxiously for the next Four Hundred Guru e-mail and get really good things out of it, but this and some of the other ones posted are really not Guru material in my opinion. Next time maybe you can show them something like this: RUNQRY and press F4.

    –Greg

    Greg is absolutely right. That tip and some of the others that I have published are not of Guru caliber. So why would I publish such things? I’ll answer that question in a minute, but first I’d like to share with you some things I didn’t publish.

    1. Swapping Values

    Did you know that it is possible to swap the values of two similarly-defined variables without a temporary holding variable? This code fragment illustrates that technique.

    D Var1            s              8a 
    D Var2            s              8a 
                                      
     /free                              
         Var1 = 'ARE GOOD';             
         Var2 = 'MY GOATS';             
                                        
         Var1 = %bitxor(Var1: Var2);    
         Var2 = %bitxor(Var1: Var2);    
         Var1 = %bitxor(Var1: Var2);    
    

    Believe it or not, after this code runs, Var1 has the value “MY GOATS” and Var2 has the value “ARE GOOD”. Do you know why it works? Here’s a hint: Given three strings–two original strings and their exclusive or–you can derive any of the three strings from the other two.

    I think we could consider this variable-swapping tip an advanced technique, since beginning business programmers normally don’t learn about bit-twiddling. In fact, I doubt many intermediate or advanced RPG programmers know this technique. By that criterion, I propose that this technique qualifies for Guru status.

    But I never published it because I can’t find any practical value in this tip. If you saw this code fragment, would it be obvious to you that the two variables were exchanging values? If there were no explanatory comment, could you figure out what was going on? I couldn’t.

    I believe it is better to avoid such “clever” code and use a temporary swapping variable. I think that using a swapping variable would be easier to understand, and to be on the safe side, I’d comment it anyway.

    D Var1            s              8a 
    D Var2            s              8a 
    D Temp            s              8a
                                      
     /free                              
         Var1 = 'ARE GOOD';             
         Var2 = 'MY GOATS';             
    
         // swap the values of Var1 and Var2 
         Temp = Var1;    
         Var1 = Var2;    
         Var2 = Temp;    
    

    2. Another Way to Derive the Exclusive Or

    This bit-twiddling reminds me of another piece of abstruse information. Did you know that you can derive an exclusive or by using other bit operations? It’s true. Here’s the formula.

    A XOR B = NOT (A AND B) AND (A OR B)
    

    Therefore the following assignment statements are equivalent to one another:

    C = %bitxor(A:B);                               
    
    C = %bitand(%bitnot(%bitand(A:B)): %bitor(A:B));
    

    I suppose this is an example of the kinds of facts all gurus should know, and that all aspiring gurus would want to know. It might come in handy if I were working in a language that didn’t support an exclusive or operation. But since RPG, OPNQRYF, and SQL have exclusive or functions, where’s the need for this technique?

    3. Ignoring Extra Blanks in SQL Commands

    Did you happen to know that SQL doesn’t mind extra spaces around qualification delimiters? In the following example, the period is used to qualify column field names in the SELECT clause, and the slash qualifies the file name in the FROM clause.

    select c.order, c.Warehouse, c.Line,
           c.comment, c.destination                 
      from mylib/SomeFile as c
    

    Here’s the same code with extra blanks.

    select c.order, c .Warehouse, c. Line,
           c  . comment, c   .    destination 
      from mylib   /             SomeFile as c
    

    I’ve never run this as a tip, because I couldn’t figure out what difference it made. Is this knowledge useful?

    4. Roman Numerals

    How about a routine to build Roman numerals? Do you suppose such routines merit Guru status? I wrote the logic for this routine in pseudocode on a scrap of paper one day while watching one of my sons receive swimming instructions for Boy Scouts. The only practical value I’ve found for this routine is practical jokes. Email someone a report with all numerals–even the run date and page number–expressed in Roman format, then wait for your phone to ring. “Are you sure you wanted Arabic numerals?” you ask the caller. “I could have sworn you said you wanted the report in Roman numerals.”

    I also developed the algorithm to convert Roman numerals to Arabic while waiting to meet my dad in a store one day. The resulting subprocedure is in the code referred to by the last link. Am I getting anywhere near Guru level yet?

    5. Have Computer, Will Sudoku

    Does it take a guru to write a program that solves Sudoku puzzles? I wrote such a program when I got stuck while trying to solve a Sudoku puzzle. I wondered if perhaps the puzzle had more than one solution, so I decided to write a program to find out. I also wondered if RPG were able to handle the challenge, so I decided to write the program in RPG.

    My program has some academic interest in that it has two subprocedures–DoDigit and Try–that call one another. That is, DoDigit calls Try, which calls DoDigit, which calls Try, which calls DoDigit, which calls Try, and so on, down to 163 levels of call stack. It prints all possible solutions to a puzzle. I never published the program, because I doubt that employers are clamoring for Sudoku-solving computer programs.

    6. Linked Lists

    During an odd moment I pondered the question, “Is it possible to implement linked lists in RPG?” After all, I had found linked lists to be useful in Pascal programs back in the olden days when I was younger and pursuing my computer science degree. Here is an exploratory program I wrote to pursue that idea. I concluded that it is possible to write RPG code to implement linked lists, but it is not practical. I leave it to the interested reader to develop the idea farther.

    Answering Greg’s Question

    Enough of that esoteric stuff. Why did I publish the QF command? For one reason: Based on e-mail I had received from readers of this newsletter, I thought some of you would find it useful. I get e-mail from people who are out there on the leading edge, but the overwhelming bulk of it comes from people who are trying to solve everyday problems. Among the questions I was asked recently are “What is a prototype?” and “How do I get the code you published from my PC to the iSeries?”

    I answer some of these requests by providing a link to a site that answers the question at hand. I answer others with a short explanation and maybe some sample code. For every question I answer, there are many that I never answer. It’s not that I’m important, but that I’m busy trying to make a living and raise a family. I just don’t have much time.

    During 2007, I hope to address the needs of iSeries professionals of all skill levels. I will do my best to provide a good mix of practical tips. I invite anyone whose finds little or nothing of value in these pages to send me some tips that they deem of value. If we think they are of value, we’ll publish them.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    CYBRA:  No source code changes required with CYBRA's MarkMagic Auto-ID software
    SafeData:  Specializing in providing data backup and disaster recovery solutions
    COMMON:  Join us at the Spring 2007 conference, April 29 – May 3, in Anaheim, California

    Phishing, Zero-Days Top Symantec’s Security List Let’s Be Frank

    Leave a Reply Cancel reply

Volume 6, Number 44 -- December 13, 2006
THIS ISSUE SPONSORED BY:

ProData Computer Services
SEQUEL
Twin Data

Table of Contents

  • Stuff I Didn’t Publish This Year
  • The System i and Office 2007
  • Admin Alert: More Information on Fixed Storage and WRKSYSACT

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25
  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle