View previous topic :: View next topic
|
Author |
Message |
aaleya
New User
Joined: 10 Apr 2008 Posts: 11 Location: chennai
|
|
|
|
Hi,
I want to compare two files and write the output into third file. Basically i have a reference file A and another file B. I want to pick one record from B, search in A and if this record is present in B then write into another file C. I f the record is not present it will skip the record and read the next record from A. This process will continue till end of file is encountered. Could someone please help me with this.
Thanks! |
|
Back to top |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
Okay. Please go ahead and write a program! |
|
Back to top |
|
|
yogeshwar_ade
Active User
Joined: 31 Aug 2006 Posts: 103 Location: INDIA
|
|
|
|
Rather than writing code in COBOL, it will be good to write using SORT/DFSORT.
You will find many posts in DFSORT/SORT for this query.
Correct me if I am wrong.
Yogeshwar |
|
Back to top |
|
|
aaleya
New User
Joined: 10 Apr 2008 Posts: 11 Location: chennai
|
|
|
|
I have tried using a easytreive code. But its not working. The code i used is :
FILE INPUT1
IN1-REC 1 150 A
IN1-KEY 62 61 A
FILE INPUT2
IN2-REC 1 150 A
IN2-KEY 65 61 A
FILE OUTPUT
OUT-REC 1 150 A
JOB INPUT(INPUT1 KEY (IN1-KEY)
INPUT2 KEY (IN2-KEY))
MOVE SPACES TO OUT-REC.
IF MATCHED
OUT-REC = IN2-REC
PUT OUTPUT
GO TO JOB
END-IF
But the output I am getting is incorrect.
Thanks! |
|
Back to top |
|
|
Manuneedhi K
Active User
Joined: 07 May 2008 Posts: 115 Location: Chennai
|
|
|
|
Aaleya,
In your present easytrieve code check what happens when a 'not matched' condition is met.
Thanks
Manu |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Are the two files in the same sequence? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
What you want is the "classic" 2-file match/merge.
Near the top of this COBOL forum is a "Sticky" containing working sample code of a 2-file matcxh/merge. The sample code will do just what you want.
Download the sample code, review it, and post any questions here. |
|
Back to top |
|
|
Douglas Wilder
Active User
Joined: 28 Nov 2006 Posts: 305 Location: Deerfield IL
|
|
|
|
Your code looks good to me other than you do not need the "GO TO JOB".
You say "But the output I am getting is incorrect. " What is your input, what results are you getting, and what results would you like to get? |
|
Back to top |
|
|
aaleya
New User
Joined: 10 Apr 2008 Posts: 11 Location: chennai
|
|
|
|
Hi,
My input reference file contains say set of names. The second file also contains names. Now the reference file refers all valid names. We are matching records from the 2nd file with the reference file. If the name matches ie present in both the files, it should write the matching record of 2nd file into a third file. The invalid name records will be skipped this way.
But my code is not working properly. Even if there is a matching record found in the reference file, its not moving any records from the 2nd file.
Could someone help with this?
Thanks! |
|
Back to top |
|
|
Manuneedhi K
Active User
Joined: 07 May 2008 Posts: 115 Location: Chennai
|
|
|
|
Please give more details like what Douglas had mentioned. "What is your input, what results are you getting, and what results would you like to get?" |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Did you download and review the sample match/merge code mentioned above?
If you haven't, do so now.
When you have reviewed the code, please reply here if there is something you do not understand.
Keep in mind that prior to processing the "match", both files need to be sorted in name sequence - that will be the "key" for matching. |
|
Back to top |
|
|
|