× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hmm, one of the first problems that comes to mind with the %char bif is zero. What if you wanted to test for 0 in your list? I think %char(0) returns a zero length string...

Do you need to accommodate negative values? If so, I'd suggest %editc(chk1 : 'J') and test for values padded with space (positive) or a "-".

If ( %scan(%editc(chk1 : 'J') : '1 |7 |8 |9 ' would test for positive integers listed.

-Eric

-----Original Message-----
From: rpg400-l-bounces+edelong=sallybeauty.com@xxxxxxxxxxxx [mailto:rpg400-l-bounces+edelong=sallybeauty.com@xxxxxxxxxxxx] On Behalf Of Bill Hopkins
Sent: Wednesday, November 02, 2011 1:19 PM
To: RPG programming on the IBM i / System i
Subject: RE: Nested IF, OR and AND in /free

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
--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.

--
This is the RPG programming on the IBM i / System i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.