Read record from multi record format LF using RPGLE

125,585 pts.
Tags:
AS/400 Records
AS400 RPGLE
as400 v5r3
is it possible, read records from multi record format LF using RPGLE.
if it is possible, how to do this... 


Software/Hardware used:
as400 v5r3
ASKED: January 26, 2012  3:05 PM
UPDATED: March 17, 2012  5:21 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

here we can’t change the order of record display. because
It’s taking all of the records in the two files and sorting (ascending or descending) them depend upon records on key fields….

Discuss This Question: 18  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • philpl1jb
    Do you mean multi record format Logical FIle? Phil
    48,575 pointsBadges:
    report
  • pdsathishkumar
    yes, i want to read record from multi record logical file... (here, how to change or edit my question)?
    3,790 pointsBadges:
    report
  • philpl1jb
    No problem using an F-Spec to define the file and native rpg statements - READ, CHAIN etc. When you READ, you will default to getting records from whichever file has the next record based on key. If you want to know what Record you have just acquired you will need to get the record name from a file data structure associated with the F-spec. If you do not want records from one or more Formats use the F spec keyword Exclude. Phil
    48,575 pointsBadges:
    report
  • pdsathishkumar
    i coded this concept, but i am getting the output some what i can't get the accurate output.. i am sharing my code. please find out the logic and help me to correct the logic..
     Ftestjoin  if   e           k disk                          -> my LF, it has two PF(TESTA, TESTB)            
     Froughdsp  cf   e             workstn               -> my display file                    
     C                   dow       *in03=*off                                
     c                   exfmt     tworead                       -> display file record format name            
     C                   read      test1                                  30   -> TESTA record format name
     C                   if        *in30 = *on                               
     C     *loval        setll     test2                            -> TESTB -record format name         
     C                   endif                                               
     C                   dow       *in30=*on                                 
     C                   read      test2                                  40 
     c                   exfmt     tworead                                   
     C                   if        *in40 = *on                               
     C                   leave                                               
     C                   eval      *inlr = *off                              
     C                   endif                                               
     C                   enddo                                               
     C                   enddo                                               
     C                   eval      *inlr = *on                               
    here, i got output, but repeatedly shown second PF records.. how to read both PF at a same time...
    3,790 pointsBadges:
    report
  • pdsathishkumar
    sorry, i typed wrongly in my previous discus message.. if *in40 = *on C leave C eval *inlr = *off please don't consider this line....
    3,790 pointsBadges:
    report
  • philpl1jb
    I am not sure that I understand your objective but below is a simple set of code that reads though the combined file presenting every record, If you want to read the records in the order they are sequenced then read from the file - the access path for file test has a single pointer -- not one for each record. So when you say that you want to read from test2 the file reads forward to the next record of the right record type. When you ask for the next record of any type it's from that point.
    Ftestjoin  if   e           k disk                          -> my LF, it has two PF(TESTA, TESTB)
     Froughdsp  cf   e             workstn               -> my display file
     C                   dow       *in03=*off
     c                   exfmt        tworead                       -> display file record format name
     C                   read        testjoin
     C                   exfmt       tworead                
     C                   Do while not %EOF(testjoin) and not *in03   03 is screen exit key
     C                   read        testjoin
     C                   exfmt       tworead                
     C                   Enddo
     C                   Eval         *inlr = *on
    C                    Return  
    
    48,575 pointsBadges:
    report
  • pdsathishkumar
    Mr. Phil, i got the answer from your code. but first read record from second pf (TESTA) in lf. when second pf will reach the last record, after control will go to read record from first pf (TESTB) in lf... i want to change the order (first read record in first PF, after read second PF) otherwise, can i read record one by one in both PF... is it possible please give me a suggestion...
    3,790 pointsBadges:
    report
  • philpl1jb
    Records are going to appear as if they are sorted based on key, you may need to change the logical to add one additonal key field to the key list of the file you want to be last. We may have said this before but we will say it again. Multi-format logicals are an old approach and would not be an approach I would use for new development since it cannot be used by SQL. Want data from two files, I would use two access paths. Phil
    48,575 pointsBadges:
    report
  • pdsathishkumar
    Mr. Phil, i don't want to change order of record... i want to change the order of file in LF. i want to read record from first PF(testa) in first time. but my code read record from second PF in first.. so i want change that............. is it possible............
    3,790 pointsBadges:
    report
  • philpl1jb
    i don’t want to change order of record… i want to change the order of file in LF -- but the order of data in the logical file isn't based on records it's based on keys. It's taking all of the records in the two files and sorting them on the keys. That requires a change to the keys in the logical file file 1 Key 1.1 Key 1.2 file 2 Key 2.1 Key 2.2 Key 2.3 <-- add another key if key 1.1 = 2.1 and 1.2 = 2.2 the record from file1 will be before record from file2 because key 2.3 > nothing At least that's the way i remember it, you can research it and tell me how it goes. Phil
    48,575 pointsBadges:
    report
  • philpl1jb
    R test1 K KEYFLD1 K KEYFLD2 K *NOKEY R TEST2 K KFLD1 K KFLD2 K KFLD3 If this doesn't work for you show use some sample data in the order you want it marking each rows source and field names.
    48,575 pointsBadges:
    report
  • philpl1jb
    Just show us the samle data and the logical file code.
    48,575 pointsBadges:
    report
  • pdsathishkumar
    It’s taking all of the records in the two files and sorting them on the keys Mr. Phil, your are correct... i understood your point... i got the perfect answer.. i have another one question.. i have 2 field in PF1 and 2 field in PF2.. totally 4 field in LF.. can we read record from 4 fields at a time.....
    3,790 pointsBadges:
    report
  • philpl1jb
    You can use the logical file, do two reads then show screen. Since you want data from both files at the same time, you might be better off with a join logical file. Issue - Join files are not updatable. Phil
    48,575 pointsBadges:
    report
  • pdsathishkumar
    Thank Mr. Phil, i got clear idea about this... i fully learned and research about this... i got perfect answer from your hint.... one more thanks for you...
    3,790 pointsBadges:
    report
  • TomLiotta
    Join files are not updatable. ...until V5R4 with INSTEAD OF triggers. (At least, I think it was V5R4.) Tom
    125,585 pointsBadges:
    report
  • philpl1jb
    What I meant to say was I don't update Join files Tom does.
    48,575 pointsBadges:
    report
  • TomLiotta
    [...] Pdsathishkum and Philpl1jb discuss if reading records from format LF using RPGLE is [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following