• 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
    Midrange Dynamics North America

    Git up to speed with MDChange!

    Git can be lightning-fast when dealing with just a few hundred items in a repository. But when dealing with tens of thousands of items, transaction wait times can take minutes.

    MDChange offers an elegant solution that enables you to work efficiently any size Git repository while making your Git experience seamless and highly responsive.

    Learn more.

    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

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

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