Which %BIF for Chain, Read and other naughty native file IO 

 September 12, 2017

By  NickLitten

I always forget the differences between %EOF, %EQUAL and Not %Found when writing native file I/O in RPG ILE Programs.  Sometimes a file record is %found and sometimes its not. Even after all these years I still scratch my head about which one is which.

I know, I know – I should be using SQL right? SQL does things differently so these problems don’t bite us – but us crusty old time RPG chaps still have a secret soft-spot for good old fashioned chains don’t we?

I tend to copy blocks of code when writing source, it’s all too easy to copy a block of logic doing a subfile readc and change it to a chain without changing the %EOF to a %found. Which is exactly what I’ve been doing today. Of course, this ends up with chains looking for %EOF which compiles just fine. Grrrrr.

Since chain doesn’t necessarily set the file pointer to “end of file” sometimes I execute the NOT %eof( ) logic. Bloody annoying and not easy to spot a simply typo like this.

Must remember:

  • %found is for chains
  • %eof for reads
  • %equal for setll

So, here is a quick little cheat sheet of which built in function to use with which command:

  • 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

One further note – SETLL checking for %found means it positioned before the key but %EQUAL means it found the exact key.


IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Shameless Trekkie, Belligerent Nerd, Englishman Abroad 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 remember: If at first you don't succeed then skydiving probably isn't a hobby you should look into.

Nick Litten

related posts:

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
__CONFIG_colors_palette__{"active_palette":0,"config":{"colors":{"cff50":{"name":"Main Accent","parent":-1},"a344d":{"name":"Accent Transparent","parent":"cff50"}},"gradients":[]},"palettes":[{"name":"Default","value":{"colors":{"cff50":{"val":"var(--tcb-skin-color-0)"},"a344d":{"val":"rgba(46, 138, 229, 0.85)","hsl_parent_dependency":{"h":210,"l":0.54,"s":0.78}}},"gradients":[]},"original":{"colors":{"cff50":{"val":"rgb(0, 178, 255)","hsl":{"h":198,"s":1,"l":0.5}},"a344d":{"val":"rgba(0, 178, 255, 0.85)","hsl_parent_dependency":{"h":198,"s":1,"l":0.5}}},"gradients":[]}}]}__CONFIG_colors_palette__

Get In Touch

Iā€™m always looking for awesome input, feedback and critique!