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

Compare two files and write using COBOL


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

New User


Joined: 24 Mar 2012
Posts: 17
Location: pune

PostPosted: Wed Mar 28, 2012 11:16 am
Reply with quote

Hi,

I have below requirements..
There are 2 seq files..having comparing filed say of 5 places(numeric)...but it start for first file is from 350 and for 2nd file from 410..
i.e

file 1

12345
22222
14852
78965

file2
12345
78965
98745
56987

so I need 3 output file having:

output1: Present only in first file i.e

22222
14852

output2: Present only in second file i.e

98745
56987

output3:Present in both file i.e

12345
78965

I have gone through the attachement that Dick has attached, but seems my requirement is somethin different.

Could you please suggest some logic for above requiremet.

Regards,
-Ravi
Back to top
View user's profile Send private message
xknight

Active User


Joined: 22 Jan 2008
Posts: 117
Location: Liberty city

PostPosted: Wed Mar 28, 2012 11:41 am
Reply with quote

Hello Ravi,

You have posted this already in DFSORT section, have you tried the solution given by Skolusu.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Mar 28, 2012 12:33 pm
Reply with quote

I also don't understand why you haven't tried Skolusu's solution.

To keep your output in the original input order, you need to include a sequence number on the records, so that they can be re-sorted on that after the match.

Having previously shown data that was fixed and starting in column 1, we now know something more, but need to know the recfm and lrecl (which are presumably all the same).

I dont' know why you can't see it with the two-file match. Key low on file one, output to file one-output only, low on two, output to two-output only, match on key, output to match.

DFSORT uses an indicator, specified by the ?, to indicate the above, with value of 1, 2 or B appropriately.

The reformat statement appends the records, because that is how you get one record from each file on the same output from the join.
Back to top
View user's profile Send private message
Ravi Kirti

New User


Joined: 24 Mar 2012
Posts: 17
Location: pune

PostPosted: Wed Mar 28, 2012 4:56 pm
Reply with quote

Hi,

I tried the provided solution but getting error.

[
SYNCSORT LICENSED FOR CPU SERIAL NUMBER 41BA6, MODEL 2817 602
SYSIN :
OPTION COPY
JOINKEYS F1=INA,FIELDS=(10,5,A)
*
JOINKEYS F2=INB,FIELDS=(20,5,A)
*
JOIN UNPAIRED
REFORMAT FIELDS=(F1:1,80,F2:1,80,?)
*

OUTFIL FNAMES=ONLYF1,BUILD=(01,80),INCLUDE=(161,1,CH,EQ,C'1')
OUTFIL FNAMES=ONLYF2,BUILD=(81,80),INCLUDE=(161,1,CH,EQ,C'2')
OUTFIL FNAMES=BOTH,BUILD=(1,80),SAVE
WER268A JOINKEYS STATEMENT: SYNTAX ERROR
WER268A JOINKEYS STATEMENT: SYNTAX ERROR
WER268A REFORMAT STATEMENT: SYNTAX ERROR
WER211B SYNCSMF CALLED BY SYNCSORT; RC=0000
]

As an alternative I was asked to do using COBOL. I have planned to do it with below logic:

1. First I will sort both the files.
2.Then in Procedure Division -

PERFORM 000-OPEN.
PERFORM 100-PROCESS THRU 100-PROCESS-EXIT
UNTILL END-INF1 AND END-INF2.
(Where END-INF will be declare as PIC X(2) VALUE '10')
PERFORM 200-CLOSE-FILE THRU 200-CLOSE-FILE-EXIT.
************************** 000-OPEN.
will perform opening the 2 files in INPUT mode and 3 output file in OUTPUT mode.
000-OPEN-EXIT.
**
100-PROCESS.
**
will perform READ operation for 2 input files, then will compare first record from both files.

IF INF1(REC-1) = INF2(REC-1)
WRITE OUTF3 (For matching Records)
READ INF1 AND INF2.
ELSE
IF INF1(REC-1) > INF2(REC-1)
WRITE OUTF2. (All non- matched record from input file-2)
READ OUTF2.
ELSE
IF INF1(REC-1) < INF2(REC-1)
WRITE OUTF1 (All non- matched record from input file-1)
READ F1
END-IF
END-IF
END-IF.
**

But problem is that both file does not have equal number of records.

So if say records from file-1 finished during comparison, how can we write file for file2.

Thanks!
Ravi
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 792
Location: Pennsylvania

PostPosted: Wed Mar 28, 2012 5:19 pm
Reply with quote

So you get one Syntax Error and you are already throwing it all away and going with Cobol?

Use your brain man!

Get out the Syncsort manual and look at the syntax for Joinkeys.

Fix the syntax and try again.

I often get many syntax errors before I get it right. I don't quit after one.

I also don't flounder on the dock asking for help. I Jump in the water and swim.

The solution provided is logically correct and syntactically correct for Dfsort. Just a few minor changes and you are good to go.

But in order for this to happen, YOU have to use YOUR brain.
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: Thu Mar 29, 2012 9:00 pm
Reply with quote

Hello,

You should be aware that you are using Syncsort - not DFSORT.

At a glance, i suspect your code will not work for all conditions. It will work for many and if improperly tested, may give the impression that it is working correctly. . .

At the top of the COBOL part of the forum is a "Sticky" that contains tested code to do what you intend to do (match/merge 2 files).
Back to top
View user's profile Send private message
Ravi Kirti

New User


Joined: 24 Mar 2012
Posts: 17
Location: pune

PostPosted: Fri Mar 30, 2012 11:38 am
Reply with quote

I corrected the SYNCSORT syntax ..and run it, it's giving correct result icon_smile.gif ..
I even tried with COBOL also with reference of "Sticky" and corrected logic some places..also got desired result icon_smile.gif

Thanks you all for your suggestions and help!

-Ravi
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 Replace each space in cobol string wi... COBOL Programming 2
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Compare only first records of the fil... SYNCSORT 7
Search our Forums:

Back to Top