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



Hi Scott,

>>Chain does not set the value of %EOF  (it doesn't turn it on or off)

Are you sure?
I found the following extract in the RPGIV Reference:
The following operations, if successful, set %EOF(filename) off.
If the operation is not successful, %EOF(filename) is not changed.
%EOF with no parameter is not changed by these operations.
1. CHAIN (Random Retrieval from a File) on page 573
2. OPEN (Open File for Processing) on page 694
3. SETGT (Set Greater Than) on page 738
4. SETLL (Set Lower Limit)" on page 742

Birgitta

-----Ursprungliche Nachricht-----
Von: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]Im Auftrag von Scott Klement
Gesendet: Donnerstag, 18. August 2005 18:54
An: RPG programming on the AS400 / iSeries
Betreff: Re: How to properly use %EOF() bif?



Chain does not set the value of %EOF  (it doesn't turn it on or off)
therefore in your example code, once %EOF gets turned on, it'll never be
turned off since you'll never enter the DOW loop.

There's really no reason to use DOW in the scenario that you're using.
You'll never get to the loop at all if the CHAIN didn't find a record, so
you can use DOU instead:

FOR COUNT=1 TO %Elem(keyARRAY);
    key4file=keyARRAY(COUNT);
    chain key4file KEYEDFILE;
    if %Found();
       dou %Eof();
          register();
          reade key4file KEYEDFILE;
       ENDDO;
    endIf;
endFor;

The reason that this will work is that the condition for "Dou" isn't
checked until the end of the loop -- that means that DOU doesn't look at
the value of %EOF until after the READE, and therefore your problem is
solved.


> The problem is that loop was good just for the first iteration. On second
> iteration, when program successfuly chained to new record with new key,
> %EOF() bif in line 05 returned result that refered to last READE operation
> but not CHAIN. I used this approach because I thought that CHAIN is some
> combination of SETLL+READ but obviosly I was wrong.

You can use SETLL and READ (or READE) so that they work the same as a
CHAIN would work, but you can also use them differently. When used
properly, they'll have the same effect on the database. However, they
don't set the same BIFs (or the same resulting indicators, in older RPG)



> 01 FOR COUNT=1 TO %Elem(keyARRAY);
> 02  key4file=keyARRAY(COUNT);
> 03  setll key4file KEYEDFILE;
> 04  if %Equal();
> 05    read KEYEDFILE;
> 06    dow NOT %Eof();
> 07         register();
> 08         reade key4file KEYEDFILE;
> 09    ENDDO;
> 10  endif;
> 11 endFor;

That'll work because now the READ is always just before the %EOF check, so
%EOF is always set when you hit the DOW statement.

Another way to code it is:

FOR COUNT=1 TO %Elem(keyARRAY);
    setll key4file(COUNT) KEYEDFILE;
    reade key4file(COUNT) KEYEDFILE;
    dow not %EOF;
       register();
       reade key4file KEYEDFILE;
    ENDDO;
endFor;

If the record is found, SETLL will position the file correctly, and READE
will work. If it's not found, SETLL will fail and so will READE...  so
this method saves you having to check two different conditions. (%EQUAL
and %EOF, or %FOUND and %EOF in the case of CHAIN)

--
This is the RPG programming on the AS400 / iSeries (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.