IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Comparing two files and write unmatched fields to output fil


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
bhaskar_kanteti

Active User


Joined: 01 Feb 2007
Posts: 123
Location: Hyderabad

PostPosted: Mon May 28, 2007 5:09 pm
Reply with quote

Hi All,

I had a query in cobol.

I had two input files. Each input file will have 200 fields. These input files will use the same copy book. It is something like comparing the new file with yesterday's file.
Now i need to compare these two input files and which ever field doesn't match should only be written to output file.

Can any one help me how to do this logic.

i heard that there is some logic like comma seperator. I dont know exactly. If any one knows help me in this.

Regards,
Bhaskar.
Back to top
View user's profile Send private message
krisprems

Active Member


Joined: 27 Nov 2006
Posts: 649
Location: India

PostPosted: Mon May 28, 2007 5:20 pm
Reply with quote

bhaskar_kanteti

give an example of i/p and o/p.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon May 28, 2007 5:26 pm
Reply with quote

Hello,

Comma separation (or any other delimiter) will not be part of your solution (unless the files are already delimited - which is doubtful).

In addition to comparing all of the fields to identify which have different values, you will also need to accomodate adds and deletes (which means there can be unmatched records in either file.
Back to top
View user's profile Send private message
Imrankhan

New User


Joined: 28 May 2007
Posts: 6
Location: Chennai

PostPosted: Mon May 28, 2007 5:56 pm
Reply with quote

Hi Bhaskar,
plz follow these steps to compare 2 seq files:
1. sort 2 files with ur primary key. let primary keys be I1, I2
2. next read these 2 files;
read i1 (till end of file)
read i2 (till end of file)

3. process if I1 = i2
next sentence
else if I1 < I2
write unmatched records into output file
read I1(here key with lowest value should be read)
else if I1 > I2
write o/p file
read I2

this logic will definetly work cos i already done similar seq file comparison
Back to top
View user's profile Send private message
bhaskar_kanteti

Active User


Joined: 01 Feb 2007
Posts: 123
Location: Hyderabad

PostPosted: Tue May 29, 2007 8:49 am
Reply with quote

The question is
I had two input files. Each input file will have 200 fields. These input files will use the same copy book. It is something like comparing the new file with yesterday's file.

Now i need to compare these two input files and when there is a mismatch in any of the field then write that particular filed from New File to output.

Suppose from the file below if NEW-FIELD-3 doesnot mattch with HIS-FIELD-3 then write only NEW-FIELD-3 to OF-FIELD-3

here is the FILE FORMAT.

Help me in this regard.

INPUT FILE 1:
NEW-FIELD-1 PIC X(10)
NEW-FIELD-2 PIC X(5)
NEW-FIELD-3 PIC X(4)
NEW-FIELD-4 PIC 9(3)
NEW-FIELD-5 PIC 9(8)
.
.
.
NEW-FIELD-200 PIC 9(12)


INPUT FILE 2:
HIS-FIELD-1 PIC X(10)
HIS-FIELD-2 PIC X(5)
HIS-FIELD-3 PIC X(4)
HIS-FIELD-4 PIC 9(3)
HIS-FIELD-5 PIC 9(8)
.
.
.
HIS-FIELD-200 PIC 9(12)


OUTPUT FILE:
OUT-FIELD-1 PIC X(10)
OUT-FIELD-2 PIC X(5)
OUT-FIELD-3 PIC X(4)
OUT-FIELD-4 PIC 9(3)
OUT-FIELD-5 PIC 9(8)
.
.
.
OUT-FIELD-200 PIC 9(12)
Back to top
View user's profile Send private message
jaspal

New User


Joined: 22 May 2007
Posts: 68
Location: mumbai

PostPosted: Tue May 29, 2007 10:24 am
Reply with quote

hi Bhaskar

why r u writing a cobol code go for ezytrieve,it will solve ur problem .
and it is easy
Back to top
View user's profile Send private message
pingte

Active User


Joined: 03 Dec 2005
Posts: 120
Location: india

PostPosted: Tue May 29, 2007 11:16 am
Reply with quote

hi,
to implement ur compare logic in cobol program u can follow this logic.
Step1:
in FD section declare copybook of old file as it is. then declare the copybook of new file (which is same as old file) with Replacing option (replacing option is used to differentiate between 2 files.. no impact on logic) also declare the record structure for o/p file
Step 2:
Open old and new file in i/p mode. open o/p file in Output mode
Read the old file till end of file.
for every record in old file read the new file (till EOF).
If record is found then move 'Y' to EOF flag for new file.
Else Write to o/p file.

Hope this helps.
Back to top
View user's profile Send private message
bhaskar_kanteti

Active User


Joined: 01 Feb 2007
Posts: 123
Location: Hyderabad

PostPosted: Tue May 29, 2007 6:47 pm
Reply with quote

i think i should explain bit more clear.

First Input File:
-----------------
field-1 field-2 field-3 field-4 field-5 ..... field-200
210-----210------230-----320-----abc...........23.09 <--record1 of new i/p
110-----320------540-----230-----dlk............12.98 <--record2 of new i/p
and so on.....many number of records

Second Input File:
--------------------
field-1 field-2 field-3 field-4 field-5 ..... field-200
200-----110------230-----320-----xyz...........21.54 <--record1 of hist i/p
110-----520------540-----110-----xyz...........12.98 <--record2 of hist i/p
and so on.....many number of records

Output File:
-------------
field-1 field-2 field-3 field-4 field-5 ..... field-200
210------210----- -------- --------abc----------23.09
(this is the output by comparing record1 of new i/p with record1 of hist i/p)
----------320----- --------230-----dlk-----------
(this is the output by comparing record2 of new i/p with record2 of hist i/p)

hope this explanation is clear.
i cant go for any other option except cobol program.
kindly help me if any one know the logic for this.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue May 29, 2007 9:16 pm
Reply with quote

Hello,

If i correctly understand your requirement, the logic will not be complicated, but will be rather lengthy.

First, you need to set up the code to "match" both files by their "key" - your example does not show what the key might be. You have not said what should happen when there are entries in one file that are not in the other (i.e. adds and deletes).

Next your program needs to look at each field of the matched records (one by one) to see if the "new" field has the same value as the "old" field.

The output should be built one field at a time as the comparisons are made.
Back to top
View user's profile Send private message
Bitneuker

CICS Moderator


Joined: 07 Nov 2005
Posts: 1104
Location: The Netherlands at Hole 19

PostPosted: Tue May 29, 2007 9:29 pm
Reply with quote

I refuse to keep posting our wonderfull balance line solution. Done so several times icon_wink.gif
Back to top
View user's profile Send private message
bhaskar_kanteti

Active User


Joined: 01 Feb 2007
Posts: 123
Location: Hyderabad

PostPosted: Wed May 30, 2007 8:35 am
Reply with quote

Hi,

In this both the new and hist files will have a key. If that key matches then only we will check for the rest of the fields and which ever is found mismatch we will write to output file from the new file. If the key doesn't match then ignore.

Can you tell me how to process this logic.

First Input File:
-----------------
key field-1 field-1 field-3 field-4 field-5 .......... field-200
aa --210-----210------230-----320-----abc...........23.09<-recd1 of new i/p
bb --110-----320------540-----230-----dlk............12.98<-recd2 of new i/p
and so on.....many number of records

Second Input File:
--------------------
key field-1 field-2 field-3 field-4 field-5 ........... field-200
aa --200-----110------230-----320-----xyz...........21.54<-recd1 of hist i/p
bb --110-----520------540-----110-----xyz...........12.98<-recd2 of hist i/p
and so on.....many number of records

Output File:
-------------
key field-1 field-2 field-3 field-4 field-5 ..... field-200
aa ---210------210----- -------- --------abc----------23.09
(this is the output by comparing record1 of new i/p with record1 of hist i/p)
bb --- ---------320----- --------230-----dlk-----------
(this is the output by comparing record2 of new i/p with record2 of hist i/p)

hope this explanation is clear.
Back to top
View user's profile Send private message
pingte

Active User


Joined: 03 Dec 2005
Posts: 120
Location: india

PostPosted: Wed May 30, 2007 9:47 am
Reply with quote

as i have said read file 1(old file) first .. take the record in cpybook layout..where u will know the fields defined...

when u read the second file(new file), for each record.. or based on key..
put record in same copybook layout (with replacing clause).. and compare it old record fields..

if non-matching fields are found put them into o/p record layout.

hope the xplanation is clear this time icon_idea.gif
Back to top
View user's profile Send private message
Naresh Kumar Reddy P

New User


Joined: 24 May 2007
Posts: 8
Location: Bangalore

PostPosted: Wed May 30, 2007 4:13 pm
Reply with quote

Bhaskar,

1. Define a working storage table with 200 occurences and store the lengths of all your input 200 fields. Say it is defined as Field-Len(200)

2. Read File-new & File-old.

3. Perform step-4 until EOF reaches for either File-old or File-new

4. If key-new = key-old
initialize i, output-rec and move 1 to A
perform comare-para until i=200
write output-rec
else if key-new < key-old
write output-rec from new-rec
read File-new
else read File-old.

5. If File-new reaches EOF, end the process.
else read File-new and the write to output until File-new reaches EOF

Comare-para:
If (new-rec(A:Field-len(i)) = (old-rec(A:Field-len(i))
add Field-len(i) to A
add 1 to i
else
move new-rec(A:Field-len(i)) to output-rec(A:Field-len(i))
add 1 to i
End-if.

I'm sure this logic will definitely work. Let us know if you have any issues.

Thanks
Reddy
Back to top
View user's profile Send private message
bhaskar_kanteti

Active User


Joined: 01 Feb 2007
Posts: 123
Location: Hyderabad

PostPosted: Mon Jun 04, 2007 4:42 pm
Reply with quote

THANK YOU SO MUCH NARESH KUMAR REDDY.........
THANKS FOR YOUR CLEAR EXPLANATION...........

THANK YOU SO MUCH...........
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 3
No new posts TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Compare only first records of the fil... SYNCSORT 7
Search our Forums:

Back to Top