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
 

 

To search in a flat file and write into another file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: To search in a flat file and write into another file
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: 788
Location: Chennai, India

PostPosted: Mon Jun 02, 2008 6:40 pm    Post subject:
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    Post subject: Reply to: To search in a flat file and write into another fi
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    Post subject: Reply to: To search in a flat file and write into another fi
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    Post subject:
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    Post subject:
Reply with quote

Are the two files in the same sequence?
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: Mon Jun 02, 2008 9:34 pm    Post subject:
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    Post subject:
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    Post subject: Reply to: To search in a flat file and write into another fi
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    Post subject:
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

Site Director


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

PostPosted: Tue Jun 03, 2008 11:47 pm    Post subject:
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    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 Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Issue with NDM process to transmit ES... chetanambi All Other Mainframe Topics 6 Wed May 03, 2017 10:52 am
No new posts File processing vishwakotin Mainframe Interview Questions 9 Fri Apr 28, 2017 11:38 am
No new posts Occurrence of various strings within ... TS70363 JCL & VSAM 1 Thu Apr 27, 2017 8:18 pm


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