RPGLE %eof, %equal, %found – whats the difference?

ILE RPG – has wonderful built in functions to replace the smelly old *indicator techniques in old RPG3. The modern generation of RPGLE %eof, %equal, %found %BIFS let us accurately and clearly handle native file IO.

The trouble is; using the wrong built in function can be easy to do and sometimes not easy to spot an obvious error. It’s not as annoying as coding an indicator on the wrong column in old style RPG3 or RPG400, but it’s still thoroughly frustrating when you stare at a CHAIN statement and cant figure out why its not working. Only to realise that you should have checked for %FOUND rather than %EOF  🙂

RPGLE %eof, %equal, %found

So whats the difference between (hint this code is wrong!):

Chain (keyfields) filename;
If Not %eof( filename );
--- do something ---
EndIF;

and Code (hint this code is correct!):

Chain (keyfields) filename;
If %Found( filename )
--- do something ---
EndIF;

And why would you use one over the other?

Answer:

if you are using CHAIN then use %FOUND if your using READ then use %EOF

  • Chain – %Found
  • Check – %Found
  • CheckR – %Found
  • Delete – %Found
  • LookUp – %Equal, %Found
  • Read – %Eof
  • ReadC – %Eof
  • ReadE – %Eof
  • ReadP – %Eof
  • ReadPE – %Eof
  • Scan – %Found
  • SetGT – %Found
  • SetLL – %Equal, %Found
  • Write (subfile only) – %Eof

and there you have it

(0 votes) 0/10