When to use EOF or FOUND in RPGLE?

  • Home
  • /
  • Blog
  • /
  • When to use EOF or FOUND in RPGLE?

October 24, 2020

When to use EOF or FOUND in RPGLE?

By NickLitten

October 24, 2020

rpgle, bif, eof, found

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)
  • 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

  • I’d like to see you emphasize the use of the filename Nick. In the text you always specify it but in the example code it is missing. Personally I always recommend using the file name other than under really unusual conditions. Without it it is far to easy for sloppy maintenance to stick in an extra file read without realizing that it will impact the upcoming EOF test.

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

    Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips