× 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.



So it works like an if statement on each element testing for blanks with a true false result. Where do you get these gems?

Thank you Vern and Barbara!

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of Vern Hamberg
Sent: Friday, July 15, 2011 8:39 AM
To: RPG programming on the IBM i / System i
Subject: Re: Testing An Array


Here, chk is an indicator array. The expression in parentheses is a test
- results in either true or false and is assigned to chk, which ends up
either *on or *off (true or false). Apparently, when you specify only
the array names without an index, it processes each element in turn.
Very cool!

HTH
Vern

On 7/15/2011 6:49 AM, Bill Meecham wrote:
chk = (arr = *blanks);

Why does that work?


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of Barbara Morris
Sent: Thursday, July 14, 2011 6:17 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: Re: Testing An Array


On 2011/7/14 10:04 AM, Robert Munday wrote:
I need to test an array to determine if there are any non-blank elements.
In fixed format I recall that I could test the whole array. That seems
not to work in /Free format.

Here's another way to do this. It's a bit more code than some of the
other solutions, but the advantage is that it works for any type of
array, since the comparison is done on the array elements themselves
rather than on the bytes of the whole array.

D arr s 5a dim(4)
D chk s n dim(%elem(arr))
D p s 10i 0
/free
// set up the array data
arr = *blanks;
arr(3) = 'a';

// chk(i) gets '1' if arr(i) is blanks, '0' otherwise
chk = (arr = *blanks);

// look for a '0' in the chk array
p = %lookup('0' : chk);
if p<> 0;
dsply ('element ' + %char(p) + ' is not blank');
endif;

*inlr = '1';

The chk array could be arbitrarily large.

D chk s n dim(1000)
...
p = %lookup('0' : chk : 1 : %elem(arr));
--
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.