Chk1 1S 0
Chk6 1S 0
If ( %scan(%char(chk1) : '1|7|8|9') > 0 ) and %char(chk6) <> ' '
Can't it handled numeric values like this?
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of John Yeung
Sent: Wednesday, November 02, 2011 2:05 PM
To: RPG programming on the IBM i / System i
Subject: Re: Nested IF, OR and AND in /free
On Wed, Nov 2, 2011 at 11:53 AM, DeLong, Eric <EDeLong@xxxxxxxxxxxxxxx> wrote:
While not EXACTLY an "in list" function, for the example below, there is a hack...
If ( %scan(chk1 : '1|7|8|9') > 0 ) and chk6 <> ' '
Nice! The pipes serve both to make it clearer *and* to make it more
flexible (compared to solutions based on %check, for example). In
this form, it even *looks* a bit like "if myvar in (val1, val2,
val3)".
I appreciate the concerns some may have that this is on the "clever"
side, but I think it's just part of learning a language more fully.
Once learned, a neat and compact idiom like this can be faster to read
than a more verbose and cluttered one. (Though nicer still would be
for IBM to add direct support for an in-values construct. Even if you
like this %scan trick, it doesn't work for numeric values.)
John
As an Amazon Associate we earn from qualifying purchases.