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

AS400

Oct 07

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

Follow

About the Author

IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Alpha Nerd and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and in the words of the most interesting man in the world: Stay thirsty my friend.