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

COBOL match file algorithm


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

New User


Joined: 07 Mar 2007
Posts: 40
Location: India

PostPosted: Sat Jul 16, 2011 10:25 am
Reply with quote

Hi All,
I have a match file requirement where my files can be in the below format

File 1
field1 field2
111 AAA
222 AAA
222 AAA
333 AAA
444 BBB
555 BBB
666 BBB
666 BBB

File 2
Field1 Field2
222 AAA
222 AAA
555 BBB
888 BBB

Many combinations of this files can exist
basically i should read all the records of file 1 with the same field1 and field2 combination and then process the file 2 records one by one which has the same combination

Processed until one of the file is read completely

Can any one help me with the algorithm for this requirement?
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: Sat Jul 16, 2011 10:30 am
Reply with quote

Hello,

At the top of this COBOL part of the forum is a "Sticky" with working code to do nearly what you want.

With only a little modification, you can do what you want using this (unless i misunderstand what you want to do).
Back to top
View user's profile Send private message
Deepthy Jose P

New User


Joined: 07 Mar 2007
Posts: 40
Location: India

PostPosted: Sat Jul 16, 2011 10:42 am
Reply with quote

Thanks Dick,
I read the sticky, but it seems to be a normal file compare, my requirement is a bit different as i have to read the same "key"(not a unique one but same field1 and field2 combinations) from file 1 and then from file2 find the same combination records one by one
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: Sat Jul 16, 2011 10:47 am
Reply with quote

Hello,

Suggest you more closely look at your requirement and the posted code. From what you have posted so far, the sample code should be able to get very close. . .

You need to explain why you believe the simple solution will not work for your case.

You (or someone) has arbitrarily made a "processing requirement" that may complicate the implementation. Why can the 2 "keys" not be concatenated and treated as one and then the files matched?
Back to top
View user's profile Send private message
Deepthy Jose P

New User


Joined: 07 Mar 2007
Posts: 40
Location: India

PostPosted: Sat Jul 16, 2011 10:57 am
Reply with quote

File 1 has another field which has some specific text values for which we have to analyse multiple fields values from file 2 (could be in any order) and then write the file 2 record as output if a match is found

Let me give an example

File 1

field1 field2 field 3
111 aaa text1
111 aaa text2
111 aaa text3

file 2

field1 field2 field 3 to field n
111 aaa records matching to text 3
111 aaa records matching to text 1


basically the files cannot be sorted to have it as a sequentiall search so we have to read all teh records from file 1 for 111 and aaa and set the flags for the text1 text 2 and text 3 and then read one by one record from file 2 and look for whether all the field values(field3 to field n) corresponds to any of the text 1 text2 or text 3 conditions
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: Sat Jul 16, 2011 11:08 am
Reply with quote

Hello,

Suggest you take a bit of time and post some "close to real" data and the output wanted from the sample data. Real-world data is easier for many to relate to than alphabet-soup and "textn" values. I also believe that your "file 2" looks like some kind of output rather than the second input.

When posting this new data, please use the "Code" tag to preserve alignment and improve readability. Use Preview to see your post as it will appear to the forum and Submit when the post appears as you want.

If i understand at all, there should be 3 files and there is no reason for anyone here to "figure it out".
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sat Jul 16, 2011 1:27 pm
Reply with quote

Deepthy Jose P,

1. you never reread files.

2. you always presort the files in the matching sequence.

3. learn to pose you questions with all the requriements.
stop trying to sandbag us with
'well there is another requirement which justifies my approach'
in a subsequent post.

4. if this is a school assignment to learn how to use COBOL Internal Tables,
say so,
because otherwise this is just a two file match merge,
no matter what 'big' words you misuse to describe you situation.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sat Jul 16, 2011 2:02 pm
Reply with quote

As dbz says, pre-sort the files. If you need them back in the original order afterwards, add a sequence number. After your processing, sort on the sequence number and strip it off.

With duplicates on both files, I use what I call a "sideways" match. Look at what you have written, you already have it - as long as the files are sorted.
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 2
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
Search our Forums:

Back to Top