When to use EOF or FOUND in RPGLE?

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

October 24, 2020

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

%EOF(filename)

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

%FOUND(filename)

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)

NickLitten


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:

  • 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

    Select;
    When %Error;

    When %Eof;

    Other;

    EndSl;

    • 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"}

    Start your
    7-day free trial

    Take This Course with ALL ACCESS

    Unlock your Learning Potential with instant access to every course and all new courses as they are released.
     [ For Serious Software Developers only ]

    IBM i Training For Technology Experts

    New!

    Successfully Work Remote 

     $ 129.00  $59.00

    By adding new skills in information technology, employers will be confident that you have the necessary skills and tools needed to successfully work remotely

    >

    Snug CBD

     20% Discount

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