Newsletters   Subscriptions  Forums  Store  Media Kit  About Us  Contact  Search   Home 
fhg
Volume 4, Number 2 -- January 28, 2004

Simplify Complex Conditions


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

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
E-mail: software@worksright.com
Web site: www.worksright.com


Editors: Howard Arner, Joe Hertvik, Ted Holt,
Shannon O'Donnell, Kevin Vandever
Managing Editor: Shannon Pastore
Contributing Editors: Raymond Everhart, G. Wayne Hawks,
Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

THIS ISSUE
SPONSORED BY:

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


BACK ISSUES

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



Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, 50 Park Terrace East, Suite 8F, New York, NY 10034
Privacy Statement