1,195 pts.
 SETLL and READ
Hi,
I have the following problem: I need to make SETLL and READE for several LF based on 1 PF by
selection. Is it any smart way to do it without to duplicate the READE and
%eof() for each LF?

Thank you.


Software/Hardware used:
OS V5.3 / RPGLE AS/400
ASKED: May 18, 2011  11:49 AM GMT
UPDATED: May 20, 2011  1:47:16 AM GMT
1,000 pts.
  Help
 Approved Answer - Chosen by YuVa47 (Question Asker)

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.
ANSWERED:  May 19, 2011  1:45 PM (GMT)  by Bigmac46   1,000 pts.

 
Other Answers:
Hi,
When you are using Different LFs of the same file in one program, There will be a problem of duplication while compiling.

To avoid this we can use RENAME & PREFIX Keyword at the time of LF Declaration in F - Spec.

And You can use SETLL & READE paralally on different LFs without duplicates.

RENAME: we use this keyword for renaming the Record format of that particular file.
PREFIX: By using this keyword we can give the prefix for the field names in File.

Eg: We have TEST(Physical File) and 4 Logical files on the same TEST1, TEST2, TEST3 & TEST4 and considering all 5 having the same record format TESTR.

We can use these keywords like this.
FTEST1 UF A E K DISK PreFix(T1_)
F ReName(TESTR:TESTR1)

FTEST2 UF A E K DISK PreFix(T2_)
F ReName(TESTR:TESTR2)

By using the new record formats we can access the same PF paralally.

You can distinguish the fields of the logical files based on PreFix.
Like, T1_Field for TEST1 & T2_Field for TEST2.

Pradeep.
Last Wiki Answer Submitted:  May 18, 2011  12:30 AM (GMT)  by  Deepu9321   3,355 pts.
To see other answers submitted to the Answer Wiki View Answer History.
Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _




 

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.

 2,790 pts.

 

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

 66,990 pts.

 

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

 70 pts.

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.

 1,000 pts.

 

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.

 1,195 pts.

 

Thank you Bigmac46, I’ll give your suggestion a try :)

 1,195 pts.

 

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

 66,990 pts.