• 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
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    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

  • 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
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

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