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



Y'all

It's my vacation and I'm thinking odd things about RPG I/O. In particular, I'm trying to work out just READE really works.

The documentation says it "retrieves the next sequential record ... if the key of the record matches the search argument".

Now I've never thought really deeply about this, but I'm thinking that, in essence, it sets %eof if the NEXT record in key order does not match the search argument - I have tried this and believe I confirmed this. It doesn't jump to a matching record farther along, even if it exists.

Here is some sample data and code to demonstrate this.

F1 F2 F3
1 1 1
1 1 2
1 1 3
1 2 1
1 2 2
1 2 3
1 3 1
1 3 2
1 3 3
2 1 1
2 1 2
2 1 3
2 2 1
2 2 2
2 2 3
2 3 1
2 3 2
2 3 3
3 1 1

Ftestreade IF E K DISK

d kDS ds likerec(testreader : *key)
d iDS ds likerec(testreader : *input)
/free
kDS.f1 = 1;
kDS.f2 = 2;
kDS.f3 = 1;
chain %kds(kDS) testreade iDS;
dsply %found(testreade);
reade %kds(kds : 2) testreade iDS;
dsply %eof(testreade);
kDS.f1 = 2;
reade %kds(kds : 2) testreade iDS;
dsply %eof(testreade);
*inlr = *on;
/end-free

The CHAIN finds the record with values 1, 2, 1 - since it exists.
The 1st READE finds a record, since the NEXT record has key 1, 2.
The 2nd READE sets %eof because, although a record exists with key 2, 2 - it isn't the NEXT record in key sequence.

As I say, I've never tried this - there may not even be a reason to do so, but I've done some curious things in my life. At any rate, it seems that the behavior is, in essence, to READ the next record and check for equality - not that it actually does it that way, it is just how it seems to come out.

Comments are welcome. I know I might be over-simplifying things, but the way things work down low may differ from what is the perceived result.

Happy New Year, y'all!
Vern

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.