When to use EOF or FOUND in RPGLE? 

 October 24, 2020

By  NickLitten

Built-In Functions in RPGLE – %EOF & %FOUND


This built-in function is used to detect end-of file, beginning of file, or subfile full conditions while performing a file operation. Rather than using indicators, we should use %EOF to check if the end of file is reached.

%EOF returns ‘1‘ if end-of file, beginning of file, or subfile full condition is found ; otherwise, it returns ‘0’.

READ, READC and READE return %EOF=*ON if the end of file is reached.

READP and READPE return %EOF=*ON if the beginning of file is reached.

WRITE operation returns %EOF=*ON if the WRITE operation to a subfile detail record returned a subfile-full condition.

If %EOF=*ON and we perform CHAIN operation, then CHAIN operation on successful search sets %EOF=*OFF.

  • OPEN, SETGT, SETLL on successful operations, sets %EOF=*OFF.
eof error bif


The format of this built in function is: %FOUND{(file_name)}

%FOUND returns ‘1’ if the recent operation finds a relevant/matching record; yet it is not necessary that there will be exact match.

 If the match is not found then it returns ‘0’.

The operations that set %FOUND are:

File operations:

  • CHAIN (Random Retrieval from a File)
  • SETGT (Set Greater Than)
  • SETLL (Set Lower Limit)

String operations:

  • CHECK (Check Characters)
  • CHECKR (Check Reverse)
  • SCAN (Scan String)

Note: Built-in function %SCAN does not change the value of %FOUND.

Search operations:

  • LOOKUP (Look Up a Table or Array Element)


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:

Swap Homes and Travel the World – Join Home Exchange
Surf the Web Securely with OPEN DNS
IBM i Software Change Management – CMS vs ALM – What’s in a Name?
Want to learn CL Programming?
  • Second time in a row that I see examples from you with DoU for database processing.
    If you want to promote clean structural programming, please provide examples with DoW.
    In addition, while not recommended that way, the If, Else, If can be better coded as

    When %Error;

    When %Eof;



    • It’s your second time in a row because it’s the same image I think 🙂

      I prefer DoW not %EOF() logic for the majority of my code, but this particular example is from converting someone else’s code from RPG3 to RPGLE – hence the DoU.

      I take your point on Select groups – it’s a viable alternative to If, Elseif, groups. Both do the same thing. Most javascript programmers I work with prefer elseif -so I tend to use examples that are clearer to other language programmers.

      Thanks for feedback

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Get In Touch

    I’m always looking for awesome input, feedback and critique!


    Snug CBD

     20% Discount

    I have partnered with SNUG CBD givING you Organic CBD
    20% discount code "NL20"