• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Simplify Complex Conditions

    January 28, 2004 Hey, Ted

    One of the features I like about Open Query File is the %VALUES function, which allows me to determine whether a value is found in a list of other values. For example, the expression CTYPE = %VALUES(45 56) is equivalent to CTYPE = 45 or CTYPE = 56. RPG does not have a similar function. Is there no way to simplify complex conditions?

    –David

    For record selection with SQL, you can use an IN predicate with a set. However, that’s not what you’re asking for in this case.

    One of the nice things about ILE is that you can create your own functions to do all sorts of wild and wonderful things. Here’s how to create an EqAnyNum (equals any number) function that will compare a base value to any of two to eight values.

    Create a source member with the following prototype. (I assume you’ll use source member EQANYNUM in file COPYSRC.)

    D EqAnyNum        pr              n                         
    D  BaseVal                      10i 0 value                 
    D  Val01                        10i 0 value                 
    D  Val02                        10i 0 value                 
    D  Val03                        10i 0 value options(*nopass)
    D  Val04                        10i 0 value options(*nopass)
    D  Val05                        10i 0 value options(*nopass)
    D  Val06                        10i 0 value options(*nopass)
    D  Val07                        10i 0 value options(*nopass)
    D  Val08                        10i 0 value options(*nopass)
    

    Create another source member with the following subprocedure definition. (I assume you’ll use source member EQANYNUM in QRPGLESRC.)

    H nomain
    
    D/copy copysrc,eqanynum
    
    P EqAnyNum        b                   export
    
    D                 pi              n
    D  BaseVal                      10i 0 value
    D  Val01                        10i 0 value
    D  Val02                        10i 0 value
    D  Val03                        10i 0 value options(*nopass)
    D  Val04                        10i 0 value options(*nopass)
    D  Val05                        10i 0 value options(*nopass)
    D  Val06                        10i 0 value options(*nopass)
    D  Val07                        10i 0 value options(*nopass)
    D  Val08                        10i 0 value options(*nopass)
    
    C                   if        %parms >= 2
    C                   if        BaseVal = Val01
    C                   return    *on
    C                   endif
    C                   endif
    C
    C                   if        %parms >= 3
    C                   if        BaseVal = Val02
    C                   return    *on
    C                   endif
    C                   endif
    C
    C                   if        %parms >= 4
    C                   if        BaseVal = Val03
    C                   return    *on
    C                   endif
    C                   endif
    C
    C                   if        %parms >= 5
    C                   if        BaseVal = Val04
    C                   return    *on
    C                   endif
    C                   endif
    C
    C                   if        %parms >= 6
    C                   if        BaseVal = Val05
    C                   return    *on
    C                   endif
    C                   endif
    C
    C                   if        %parms >= 7
    C                   if        BaseVal = Val06
    C                   return    *on
    C                   endif
    C                   endif
    C
    C                   if        %parms >= 8
    C                   if        BaseVal = Val07
    C                   return    *on
    C                   endif
    C                   endif
    C
    C                   if        %parms >= 9
    C                   if        BaseVal = Val08
    C                   return    *on
    C                   endif
    C                   endif
    C
    C                   return    *off
    C
    P                 e
    

    Here’s an example that shows how to call the function. If TRCODE has any of the five values listed in the second through sixth parameters, variable FOUND will be set to the value T; otherwise FOUND will be set to F.

    D TrCode          s              2s 0
    D Found           s              1a
    
    D/copy copysrc,eqanynum
    
    C                   if        EqAnyNum (TrCode: 1:5:7:8:12)
    C                   eval      Found = 'T'
    C                   else
    C                   eval      Found = 'F'
    C                   endif
    
    C                   eval      *inlr = *on
    

    There are several ways to bind the two modules into a program. The easiest is to use the Create RPG Module (CRTRPGMOD) command to make modules of each source member, and combine the two modules into a program using the Create Program (Create Program) command. If desired, create a service program from the module. You may also want to add the module or service program to a binding directory.

    I will leave it to the interested reader to expand the EqAnyNum function to allow more than eight comparison values.

    –Ted

    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

    Bsafe Bolsters OS/400 Security Software with New Logging, Alerts New Domino and Blue Domino: A Little of Both At Lotusphere

    Leave a Reply Cancel reply

Volume 4, Number 2 -- January 28, 2004
THIS ISSUE
SPONSORED BY:

T.L. Ashford
Profound Logic Software
WorksRight Software
Twin Data
SuSE Linux

Table of Contents

  • Application and Data Integration Between Linux and OS/400
  • To Commit or Not to Commit?
  • Simplify Complex Conditions
  • Retrieve the System Name
  • OS/400 Alert: Trials and Betas

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