AS/400 compare files

620 pts.
Tags:
AS/400
Logical Files
SQL
I want to compare two files without using SQL and logical file. I have written a code but I didn't get exact out put. Please look into the below code and help me guys.
File:test1
Keyfield=accid

ACCID   ACCNAME
1   siva
2   hari
3   vinayaka

File:test2
no key field here
ACCID   ACCNAME
1   hari
2   anjaneya
4   lakshmi
5   sarswathi
2   babu

hoption(*nodebugio)
ftest1     uf   e           k disk
ftest2     uf   e             disk    prefix(s)

c     ACCID         setll     test1
c                   read      test1
c     *start        setll     test2
c                   read      test2
c                   dou       %eof(test1)
c                   dou       %eof(test2)
c                   if        accid=saccid
c     ACCID         dsply
c     ACCNAME       dsply
c                   else
c     ACCID         dsply
c     saccid        dsply
c                   endif
c                   read      test1
c                   read      test2
c                   enddo
c                   enddo
c                   seton                                        lr
0

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Discuss This Question: 8  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.
  • philpl1jb

    Not sure what you are trying to find.  Write us a specification.

    Show us the expected output.




    54,090 pointsBadges:
    report
  • ToddN2000
    It looks like you are just matching on file ID. Int the example you show the names are different for ID = 1.

    In your test2 file you have 2 records with an ID = 2.

    Like Philpl1jb said show us your specs and out put. It seems a little confusing.
    132,840 pointsBadges:
    report
  • chowas400
    Hi Philp1jb/Todd,

    Thanks for your response .

    Actually i'm looking for matching records like sql. please correct the above code ..

    expected out put is like sql :
    select a.accid,a.accname,b.accid,b.accname from test1 as a,
    test2 as b  where a.accid=b.accid 


    ACCID   ACCNAME     ACCID   ACCNAME 
        1   siva                          1   hari    
        2   hari                          2   anjaneya
        2   hari                          2   babu    
    *******  End of data  ********    


    620 pointsBadges:
    report
  • ToddN2000
    Your DOU and the last READ for test1 need to be moved outside of those of the test2 DOU and read. Try that to start with and report back.
    132,840 pointsBadges:
    report
  • hunshabbir7
    Following psudo code might help you.
    Read test1
    dow not %EOF()
    
    setll *start test2
    read test2;
    dow not %EOF()
    
    if accid = saccid;
       dsply accid
       dsply accname;
       dsply saccid;
       dsply saccname;
    leave;
    endif;
    
    read test2
    enddo;
    
    read test1
    enddo

    2,900 pointsBadges:
    report
  • philpl1jb

    Remove the "leave;"

    It would cause you to miss the second match

     2   hari                          2   babu    

    Phil

    54,090 pointsBadges:
    report
  • chowas400
    Thank you so much all...
    Now i got exact out put.
    620 pointsBadges:
    report
  • hunshabbir7
    Sorry for mistake, you are right. I didn't test it.
    2,900 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.

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

Following

Share this item with your network: