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

To search in a flat file and write into another file


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

New User


Joined: 10 Apr 2008
Posts: 11
Location: chennai

PostPosted: Mon Jun 02, 2008 6:37 pm
Reply with quote

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
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Mon Jun 02, 2008 6:40 pm
Reply with quote

Okay. Please go ahead and write a program!
Back to top
View user's profile Send private message
yogeshwar_ade

Active User


Joined: 31 Aug 2006
Posts: 103
Location: INDIA

PostPosted: Mon Jun 02, 2008 6:48 pm
Reply with quote

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
View user's profile Send private message
aaleya

New User


Joined: 10 Apr 2008
Posts: 11
Location: chennai

PostPosted: Mon Jun 02, 2008 7:00 pm
Reply with quote

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
View user's profile Send private message
Manuneedhi K

Active User


Joined: 07 May 2008
Posts: 115
Location: Chennai

PostPosted: Mon Jun 02, 2008 7:04 pm
Reply with quote

Aaleya,


In your present easytrieve code check what happens when a 'not matched' condition is met.

Thanks
Manu
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Mon Jun 02, 2008 7:06 pm
Reply with quote

Are the two files in the same sequence?
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: Mon Jun 02, 2008 9:34 pm
Reply with quote

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
View user's profile Send private message
Douglas Wilder

Active User


Joined: 28 Nov 2006
Posts: 305
Location: Deerfield IL

PostPosted: Mon Jun 02, 2008 9:53 pm
Reply with quote

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
View user's profile Send private message
aaleya

New User


Joined: 10 Apr 2008
Posts: 11
Location: chennai

PostPosted: Tue Jun 03, 2008 6:54 pm
Reply with quote

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
View user's profile Send private message
Manuneedhi K

Active User


Joined: 07 May 2008
Posts: 115
Location: Chennai

PostPosted: Tue Jun 03, 2008 7:03 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Jun 03, 2008 11:47 pm
Reply with quote

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
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 How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
No new posts Write line by line from two files DFSORT/ICETOOL 7
Search our Forums:

Back to Top