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.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
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.
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.
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
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).
I corrected the SYNCSORT syntax ..and run it, it's giving correct result ..
I even tried with COBOL also with reference of "Sticky" and corrected logic some places..also got desired result