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

Common records from two input files wrtie to output file


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

New User


Joined: 26 May 2006
Posts: 7
Location: india

PostPosted: Fri Apr 20, 2007 9:57 pm
Reply with quote

Hi,
i have two input files and i have to write those records to the output files which are similar in both input files.
can anybody help me?
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: Fri Apr 20, 2007 10:30 pm
Reply with quote

Hello,

You need to post some details.

Show some sample data from your input files and what you want the output(s) to be from that input.
Back to top
View user's profile Send private message
mitaljalu

New User


Joined: 26 May 2006
Posts: 7
Location: india

PostPosted: Sun Apr 22, 2007 1:59 pm
Reply with quote

data can be anything like

INPUT FILES
File-1 File-2
1abc 8ghi
2def 9pqr
8ghi 5xyz
4lrn 1abc

Suppose above two files are there and have two common records 8ghi and 1abc , so output file should contains only these two records

OUTPUT FILE
File-3
1abc
8ghi
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: Sun Apr 22, 2007 9:01 pm
Reply with quote

Hello,

Are you trying to match the entire record or is what you've shown the "key" for the records? How many records are in the files? What is the length of each file (lrecl)?

You also need to decide what to do with "duplicates" in either file whether they be duplicate keys or entire records.

Regardless of the above answers, the process is usually:

First, you need to get both files into the same sequence (easiest way is to run a sort for each file.

Next, match the 2 sorted files against each other, discarding all of the non-matching records depending on what business rulles (other than matching) need to be implemented, you could also do what you want with your sort product.

Please spend a little time creating a more complete example.
Back to top
View user's profile Send private message
cvadlamudi

New User


Joined: 19 Apr 2007
Posts: 68
Location: India

PostPosted: Mon Apr 23, 2007 9:59 am
Reply with quote

Hi,

If u want to go with cobol u can go as per dick scherrer and also there is an option using JCL with SPLICE in ICETOOL.
Back to top
View user's profile Send private message
Shrimathi Krishnan

New User


Joined: 19 Apr 2007
Posts: 39
Location: Chennai

PostPosted: Mon Apr 23, 2007 1:46 pm
Reply with quote

can u please explain me wat us ICETOOL and how we can use it.. wat is SPLICE in ICETOOL
Back to top
View user's profile Send private message
ashwinreddy

Active User


Joined: 16 Sep 2004
Posts: 106
Location: Hyderabad

PostPosted: Mon Apr 23, 2007 2:30 pm
Reply with quote

Hi,

If you want to just compare the two files then best method is to use the Sort in JCL as dick mentioned.

Else if your requirement is to compare the two files in cobol then you can do that by taking two group level working stoage variables as file1 and file2

Read both files and save the record in working storage variables(file1 and file2), compare both the variables keeping one constant and varing the other until end of the file.

And when match found write into other file.

And some one asked about the ICETOOL

ibmmainframes.com/viewtopic.php?t=1348

If you ask me then the solution which dick has suggested is best one, rather than going for cobol program.

Cheers
Ashwin
Back to top
View user's profile Send private message
vkphani

New User


Joined: 29 Oct 2003
Posts: 29

PostPosted: Mon Apr 23, 2007 3:22 pm
Reply with quote

The below JCL will solve your problem.

Code:
//S1       EXEC PGM=ICETOOL
//OUT1     DD SYSOUT=*
//OUT2     DD SYSOUT=*
//TOOLMSG  DD SYSOUT=*
//DFSMSG   DD SYSOUT=*
//CON      DD *
1ABC
2DEF
8GHI
4LRN
8GHI
9PQR
5XYZ
1ABC
//TOOLIN   DD *
  SELECT FROM(CON) TO(OUT1) ON(1,4,CH) ALLDUPS USING(CTL3)
/*
//CTL3CNTL DD *
  OUTFIL FNAMES=(OUT1,OUT2),SPLIT
/*


Concatenate your two input files in the DD statement CON.
Back to top
View user's profile Send private message
Vinit Bhushan

New User


Joined: 17 Apr 2007
Posts: 4
Location: Gurgaon

PostPosted: Mon Apr 23, 2007 3:42 pm
Reply with quote

Hi Mital How are You?
This JCL may also Help.

//STEP10 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=&SYSCLS
//DFSMSG DD SYSOUT=&SYSCLS
//IN1 DD DSN=,DISP=SHR
//IN2 DD DSN=,DISP=SHR
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(1,1)),
// DISP=(MOD,PASS)
//OUT12 DD DSN=,DISP=SHR
//OUT1 DD DSN=,DISP=SHR
//OUT2 DD DSN=,DISP=SHR
//TOOLIN DD DSN=DISP=SHR
//CTL1CNTL DD DSN=,DISP=SHR
//CTL2CNTL DD DSN=,DISP=SHR
Back to top
View user's profile Send private message
mitaljalu

New User


Joined: 26 May 2006
Posts: 7
Location: india

PostPosted: Mon Apr 23, 2007 11:18 pm
Reply with quote

Thanks to all. i have done.
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 Apr 24, 2007 1:11 am
Reply with quote

That's good news icon_smile.gif

It may help others to see how you implemented your solution.

Which solution did you use?
Back to top
View user's profile Send private message
munikumar
Currently Banned

New User


Joined: 18 Apr 2007
Posts: 24
Location: India

PostPosted: Tue Apr 24, 2007 12:53 pm
Reply with quote

Another way is using SORT.
Code:
//STEP EXEC PGM=SORT
//SORTIN DD DSN=A.DSN,DISP=SHR
//          DD DSN=B.DSN,DISP=SHR
//SORTOUT DD DSN=C.DSN,
//                  DISP=(NEW,CATLG,DELETE),
//                  UNIT=,
//                  SPACE=,   
//                  DCB=
//SORTXSUM DD DSN=D.DSN,
//                  DISP=(NEW,CATLG,DELETE),
//                  UNIT=,
//                  SPACE=,   
//                  DCB=
//SYSIN DD *
  SORT FIELDS=(1,4,CH,A)
  SUM FIELDS=NONE,XSUM
/*
//

XSUM will get all the matched records from file1 & file2 and writes into SORTXSUM file.

Note: This SORTXSUM file will now have duplicates only. (Loosely speaking)

A.DSN B.DSN
------- --------
1abc 8ghi
2def 9pqr
8ghi 5xyz
4lrn 1abc

D.DSN
--------
1abc
8ghi
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 Apr 24, 2007 7:16 pm
Reply with quote

Thank you for posting your solution icon_smile.gif
Back to top
View user's profile Send private message
mitaljalu

New User


Joined: 26 May 2006
Posts: 7
Location: india

PostPosted: Mon Apr 30, 2007 4:25 pm
Reply with quote

Hi Dick,

I uesed first solution. Sort both the files and just compare records of both files.

Even i have also tested other solution that is using ICETOOL
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 0
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts TRIM everything from input, output co... DFSORT/ICETOOL 1
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
Search our Forums:

Back to Top