.st0{fill:#FFFFFF;}

When to use EOF or FOUND in RPGLE? 

 October 24, 2020

By  NickLitten

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

  • {"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!

    >