[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index] [Date Index] [Thread Index]
[SQR-USERS Info] [SQRUG Home Page]

Re: compare 2 flat files.



Ravi,
   First of all... what is the desired outcome of this exercise? Do you
need to compare 2 files that have a common key such as SSN? If so both
files should be sorted, the keys need to be compared and subsequent
reads (and writes) can be executed based on your compares... Keep in
mind once EOF is reached in File 2 (as per your explanation) you need to
also write ALL remaining records from File 1... If you're doing a
straight text comparison you may be better off using Chris's suggestion
utilizing a tool for precisely that purpose... Unix is well suited for
these operations... Syncsort in MVS is my personal favorite... Depending
on the degree of complexity you can use the standard syncsort
conditions/parameters OR you can code a kick-ass exit routine in
assembler makes SQR look like child's play! Also, some editors, such as
SPF/PC 4.0 have utility functions to compare two files... I use this to
compare different versions of SQR programs to see what changes have been
made... This should work for what you have in mind...

                                                       -Tony DeLia


Danielle Logan wrote:
>
> Ravi-
>
> The first thing I noticed was that your program will never enter the second
> while loop because 2 will never
> equal 1. The second is that after the first time you find a line that doesn't
> match, it's possible that all subsequent lines will not match.
>         File 1                  File 2
>         hello                   hello
>         I                               world
>         am                              I
>         fine                            am
>                                         fine
>
> You are comparing not only the content of the lines, but their position. This
> may be what you want, but if not, my suggestion would be to read file 2 into an
> array and then do your string compare.
>
> -Danielle Logan
>
> *******************************************************************************************
> hi everybody,
>     i am opening file 1 and 2 for reading and file 3 for writing.  i
> wanted to compare first two files, record wise (line wise) and write the
> records which are not in file 2 in file 3.
>     the code i am using is as follows :
>
> while 1 = 1
>    read 1 into $rec1:50
>
>    while 2 = 1
>       read 2 into $rec2:50
>       if $rec1 = $rec2
>          break
>       else
>          write 3 from $rec1
>       end-if
>       if #end-file = 1
>          break
>       end-if
>    end-while
>
>    if #end-file = 1
>       break
>    end-if
>
> end-while
>
> please let me if i can do what i wanted to do by modifying the code
> above.
> thanx in advance.
>
> ravi c gaddam.
>
>     ---------------------------------------------------------------
>
>                    Name: ATTRIBS.BND
>     Part 1.2       Type: unspecified type (application/octet-stream)
>                Encoding: Base64

--
Tony DeLia
AnswerThink Consulting Group
PeopleSoft Solutions Practice - Delphi Partners
tdelia@erols.com