• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Boolean Variables: Underused and Unappreciated

    May 16, 2012 Ted Holt

    Boolean variables can have only two values: true and false. In CL, they are known as logical variables. In RPG, they’re called indicator variables. They’re not essential; I got by without them for years. But they are useful. Let’s take a closer look at Boolean variables.

    Let me share a story with you. Some years ago, a certain factory started faxing requirements reports to their suppliers. The suppliers liked the reports, but some of them asked if they might receive the requirements electronically in a spreadsheet format. The IT department added a one-digit code to the database.

    • 1=send by fax
    • 2=place a CSV file on an FTP server

    The new electronic format was a hit, but wouldn’t you know it? Some suppliers asked to receive their reports in both formats. The IT department added another code value.

    • 3=both fax and CSV file on FTP server

    Over time, new options were added to send a PDF file by email, to send a CSV file by email, and various combinations of transmission methods.

    • 4=email PDF
    • 5=email PDF and place CSV file on FTP server
    • 6=email CSV
    • 7=email PDF and email CSV

    The result was that the RPG program that created the requirements report and file was full of logical expressions like these:

        if option = 1 or option = 3;
    
        if option >= 1 and option <= 3;
    
        if option = 4 or option = 5 or option = 7;
    

    This type of code is difficult to modify when a new transmission option is added, because the meaning of each option is not readily apparent. Use Boolean variables to clarify the conditions, like this:

    D SendByFax         s                n
    D PutOnFTPSvr       s                n
    D EmailPDF          s                n
    D EmailCSV          s                n
    
     /free
        SendByFax = (option = 1 or option = 3);
        PutOnFTPSvr = (option = 2 or option = 3 or option = 5);
        EmailPDF = (option = 4 or option = 5 or option = 7);
        EmailCSV = (option = 6 or option = 7);
       
        if SendByFax;
    
        if SendByFax or PutOnFTPSvr;
    
        if EmailPDF;
    

    Now, instead of adding expressions like this one:

    option = 8 or option = 9
    

    to one or more conditions, you can do this sort of thing instead:

    D SendTelepathically...
    D                   s                n
    
     /free
        SendTelepathically = (option = 8 or option = 9);
        EmailCSV = (option = 6 or option = 7 or option = 9);
    
        if EmailPDF or SendTelepathically;
    

    This style of code is self-documenting, because the emphasis has shifted from mechanics to intention.

    Some say that beginning a Boolean variable with a verb, or embedding a verb in the variable name, makes the intent even clearer. For example, this indicator variable begins with the verb Is:

    D IsEDICust         s                n
    
     /free
         IsEDICust = (Customer.EDICode = '1');
    

    If you’re not in the habit of using Boolean variables, I challenge to look at something you wrote but haven’t worked on in a while. Chances are, you will see plenty of conditions that have to be deciphered, and that could be improved by a judicious use of Boolean variables.



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    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

    BCD:  Live Webinar May 23: Transform Green Screens into Rich Mobile Web Apps with Presto 4
    PowerTech:  FREE 2012 State of IBM i Security webinar. Wednesday, May 30. Register NOW!
    Tributary Systems:  Storage Director, a disk-to-disk-to-tape solution. Download the case study.

    IT Jungle Store Top Book Picks

    BACK IN STOCK: Easy Steps to Internet Programming for System i: List Price, $49.95

    The iSeries Express Web Implementer's Guide: List Price, $49.95
    The iSeries Pocket Database Guide: List Price, $59
    The iSeries Pocket SQL Guide: List Price, $59
    The iSeries Pocket WebFacing Primer: List Price, $39
    Migrating to WebSphere Express for iSeries: List Price, $49
    Getting Started with WebSphere Express for iSeries: List Price, $49
    The All-Everything Operating System: List Price, $35
    The Best Joomla! Tutorial Ever!: List Price, $19.95

    Symtrax Launches New Template Design Tool IBM i And AIX Shops Pay A Hefty Premium Over PowerLinux Buyers

    Leave a Reply Cancel reply

Volume 12, Number 14 -- May 16, 2012
THIS ISSUE SPONSORED BY:

WorksRight Software
ProData Computer Services
CNX

Table of Contents

  • Boolean Variables: Underused and Unappreciated
  • Generic Processing, Continued
  • Preventing Your System from Restarting After a Full System Backup

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