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



Adam,

That's close to what I was about to suggest. But mine looks like this instead:

P FillArrayAll B
D FillArrayAll PI
D FieldToCheck 50a options(*varsize)
D len 10i 0 value
D CheckValue 50A const
D ArrayValue 50A
D
D
D**********************************************************
/FREE
COUNT = 1;
read input filerec;
dow %subst(FieldToCheck:1:len)<%subst(CheckValue:1:len);
read input filerec;
enddo;
dow not %eof(input)
and %subst(FieldToCheck:1:len)=%subst(CheckValue:1:len)
and COUNT < 9999;
WrkSupp(COUNT) = ArrayValue;
COUNT += 1;
read input filerec;
enddo;
/END-FREE
P FillArrayAll E

You'd call it with something like:

FillArrayAll(filerec.PLCD: %len(filerec.PLCD): 'whatever': whatever);

You don't actually need to use a pointer for the first parameter, since it's passed by REFERENCE... a pointer is passed under the covers anyway. So when the subprocedure references 'FieldToCheck' it actually references the exact same spot in memory as filerec.PLCD. Since that's part of the filerec data structure, it'll reference the data in the data structure, which is what is desired here.

Using %addr(), a pointer, and a based field accomplishes the exact same thing, but requires a little more code and complexity to achieve the same result.

I also used %subst() on CheckValue which Adam didn't -- and that might be a result of me having an imprecise idea of what CheckValue is for. But I did make CheckValue a CONST field since it's address is not important, and that'll let you pass other CONST fields or literals if you desire.

Note that this code (both Adam's and mine) will only work if all fields are fixed-length alphanumeric fields. The results might be screwy, otherwise.

Also, note that the way the code is written, the file has to be sorted by the field you're checking! It reads records as long as the field you're checking against is less than the check value, and that could only be assumed to be correct if the file is sorted by that field (or if it's reading a keyed access path by the field -- which doesn't seem reasonable considering that the procedure is supposed to work on any field.) This seems very strange to me -- and I wonder if that's not a logic error in Don's original code.


Adam Glauser wrote:
Don Wereschuk wrote:
< How is the code inside the procedure supposed to know how long the field
< is that you are passing?

Again I'm not passing actual data since I haven't read the file yet.

Oh, now I think I get what you're trying to do. Maybe you want something more like this:

P FillArrayAll B
D FillArrayAll PI
D FieldToCheck *
D lenFieldToCheck...
D 5P 0 const
D CheckValue 50A
D ArrayValue 50A
D*
DCheckField S 65535A based(FieldToCheck)
D
D

/FREE
COUNT = 1;
read input filerec;
dow %subst(CheckField : 1 : lenFieldToCheck) < CheckValue;
read input filerec;
enddo;
dow not %eof(input) and
%subst(CheckField : 1 : lenFieldToCheck) = CheckValue and
COUNT < 9999;
WrkSupp(COUNT) = ArrayValue;
COUNT += 1;
read input filerec;
enddo;
/END-FREE
P FillArrayAll E

and you would call it like this:
fillArrayAll(%addr(filerec.PLCD) : %size(filerec.PLCD) : 'thisRecordNeedsAction' : 'I want this is my array');

As an aside, you seem to be using a global variable (WrkSupp) inside your subprocedure. This is not a very good practice, and can lead to some really frustrating bugs.

HTH,
Adam


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.