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




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)


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.