|
// chk(i) gets '1' if arr(i) is blanks, '0' otherwise
chk = (arr = *blanks);
On 2011/7/14 10:04 AM, Robert Munday wrote:
elements.
I need to test an array to determine if there are any non-blank
In fixed format I recall that I could test the whole array. Thatseems
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 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.