
Good explanation, but I still thinking this is not exactly what YuVa47 wanted.
Yuva, tell me if I wrong but you want to write some code and use it for the read loop regardless of the values selected, is this right?
Have you tried to do it with SQLRPGLE ?, I think you can define a cursor and set the key values you need in every user selection.
If you don’t know about SQLRPGLE here is a good reference.
Hope this help you.

There’s seldom a reason to have a different LF in a single program unless the key-lists are different. Different LF names plus different key-list structures makes re-use of the same SETLL/READE instructions effectively impossible. When combined with the requirement for RENAMEs of record formats, I don’t see much chance.
I suppose you could use the _Ropen(), _Rlocate() and _Rreadk() C library functions; but I suspect that a SELECT group that simply breaks the SETLLs and READEs into their own WHEN clauses would be much easier.
Tom

Do all the LF are having the different sets of keys. If yes then you need to set and read the different logical files.

you might look at
Fmyfile PF IF A E K DISK EXTFILE(WRKFILE) USROPN
F EXTMBR(FIRST1)
D WORKFILE S 21A INZ(’*LIBL/yourfile’)
D FIRST1 S 10A INZ(’*FIRST’)
D load1 S 21A INZ(’*LIBL/file2′)
D load2 S 21A INZ(’*LIBL/file2′)
D load3 S 21A INZ(’*LIBL/file3′)
D load4 S 21A INZ(’*LIBL/file4′)
D load5 S 21A INZ(’*LIBL/file5′)
If condition
close workfile
eval WRKFILE = load2 (etc)
open workfile
user setll workfile
then same subfile load is used for all sorts.
I am using this to control which of 6 logicals is open, used, closed based sort needed.
In My case all logicals have the same first key based on user and other keys as needed to get correct view.
IF keys for logicals do not have the same keys for setll,/read or reade this will not help as all keys will need to match up at those lines.

Thank you all for the answers.
@Pradep - great answer and I agree with Mariodlg
@Mariodlg - yes, SQLRPGLE was an option, but I wanted to make it in RPGLE only. You almost guessed correctly, I wanted to read, but according to the selection criteria.
@Tom - the LFs have different key-lists and the record formats are renamed. I know that I need to have different SETLL and READE and actually I wanted to find out, if is possible to use the %eof() without the file name within the parentheses, so I could have only 1 test, but what I understanding is not possible.

Thank you Bigmac46, I’ll give your suggestion a try ![]()

if is possible to use the %eof() without the file name within the parentheses, so I could have only 1 test
The %eof() BIF doesn’t need to include a name. However, according to the ILE RPG Reference, if no name is supplied, then the EOF condition refers to the last subfile to reach EOF. Full-procedural files and primary and secondary files need a filename for %eof().
The approved answer works fine in current releases. Naturally, the extra OPENs and CLOSEs are an issue though only minor ones.
If you don’t need to use key-lists, there shouldn’t be any big problem. The inclusion of SETLL in the question took things in a wrong direction — you won’t use SETLL in this case apparently. The key structures won’t matter since you won’t actually reference them in your code.
Tom


















