Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Comparing two files and write unmatched fields to output fil

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
bhaskar_kanteti

Active User


Joined: 01 Feb 2007
Posts: 113
Location: India

PostPosted: Mon May 28, 2007 5:09 pm    Post subject: Comparing two files and write unmatched fields to output fil
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    Post subject:
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

Site Director


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

PostPosted: Mon May 28, 2007 5:26 pm    Post subject:
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    Post subject: ur answer
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: 113
Location: India

PostPosted: Tue May 29, 2007 8:49 am    Post subject: comparing files with example
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    Post subject:
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    Post subject:
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: 113
Location: India

PostPosted: Tue May 29, 2007 6:47 pm    Post subject: Re: Comparing two files and write unmatched fields to output
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

Site Director


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

PostPosted: Tue May 29, 2007 9:16 pm    Post subject:
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: 1105
Location: The Netherlands at Hole 19

PostPosted: Tue May 29, 2007 9:29 pm    Post subject:
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: 113
Location: India

PostPosted: Wed May 30, 2007 8:35 am    Post subject: Comparing two files and write unmatched fields to output
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    Post subject:
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    Post subject:
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: 113
Location: India

PostPosted: Mon Jun 04, 2007 4:42 pm    Post subject: THANKS A LOT
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SORTJOIN - Copy Matched and Unmatched... Steve Ironmonger DFSORT/ICETOOL 5 Tue Jan 17, 2017 4:26 pm
No new posts Incorrect output when trying to add n... monica1 PL/I & Assembler 10 Fri Jan 13, 2017 5:02 pm
No new posts Syncsort Help to group fields sudhakarraju SYNCSORT 6 Thu Dec 29, 2016 1:38 am
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 15 Thu Dec 01, 2016 8:28 pm
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us