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
 

 

Compare two files and write using COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Compare two files and write using COBOL
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    Post subject:
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Wed Mar 28, 2012 12:33 pm    Post subject: Reply to: Compare two files and write three files using COBO
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    Post subject: Reply to: Compare two files and write three files using COBO
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 numer of records.

So if say records from file-1 finished during comparision, 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: 671
Location: Pennsylvania

PostPosted: Wed Mar 28, 2012 5:19 pm    Post subject:
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

Site Director


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

PostPosted: Thu Mar 29, 2012 9:00 pm    Post subject:
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    Post subject: Reply to: Compare two files and write three files using COBO
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    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 Read two inputs and write into output... murali.andaluri DFSORT/ICETOOL 6 Wed Jul 26, 2017 7:35 pm
No new posts Write out NODUPS but just from one file Jay Villaverde DFSORT/ICETOOL 8 Fri Jul 14, 2017 12:44 am
No new posts XML Parse for COBOL 5.2 Bhanu Praveen COBOL Programming 1 Sat Jul 08, 2017 8:58 pm
No new posts How to write Specific Fields from Mul... Padhu SYNCSORT 6 Thu Jul 06, 2017 10:26 am
No new posts Dynamic output file creation in cobol... smileheal COBOL Programming 7 Thu Jun 15, 2017 10:53 pm


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