×
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.
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));
As an Amazon Associate we earn from qualifying purchases.