Req:compare 2 files and write it to match and nomatch

In this Mainframe Forum - You can post your queries on DFSORT, ICETOOL , SyncSort & JCL Utilities

Moderators: Frank Yaeger, Moderator Group

Post Reply
deepu
Member
Posts: 15
Joined: Fri Apr 24, 2009 10:40 am

Req:compare 2 files and write it to match and nomatch

Post by deepu » Mon Apr 27, 2009 11:14 am

Hi,

Here is my requirement....

I have 2 input files of 5200 length. A 7 byte key is used to compare both the files, if there is a match than it needs to be written to match file but while writing to match file i need few fields from infile1 and all other fields from infile2.

If there is no match than write to no match output file.

Is it possible to do it in sort...i know it can be easily done using COBOL pgm but just want to know in sort/icetool/iceman/EZTRIEVE....

Can someone help me.... :?:

Thanks in advance,
Deepu

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

matching file using SORT

Post by Natarajan » Mon Apr 27, 2009 12:30 pm

Option 1) Use syncsort as shown below.

Code: Select all

//STEP001 EXEC PGM=SORT 
//TOOLMSG DD SYSOUT=* 
//DFSMSG DD SYSOUT=* 
//SORTJNF1 DD * 
1234567sdfsadfasdf
1244567 adsfsafasd
1254567asfdsadad 
//SORTJNF2 DD * 
1234567wewreeter 
1254576werwerewr 
1265567werwrewrwerw 
//SORTOUT DD SYSOUT=* 
//SYSPRINT DD SYSOUT=* 
//SYSOUT DD SYSOUT=* 
//SYSIN DD * 
JOINKEYS FILES=F1,FIELDS=(1,7,A) 
JOINKEYS FILES=F2,FIELDS=(1,7,A) 
REFORMAT FIELDS=(F1:1,5200,F2:10,3) 
SORT FIELDS=COPY 
Using REFORMAT , you can define your output layout.

Option 2) Use DFSORT - SPLICE
Option 3) Use easytrieve IF MATCHED condition.
It is easy compare than COBOL program.
Natarajan
Chennai

deepu
Member
Posts: 15
Joined: Fri Apr 24, 2009 10:40 am

Post by deepu » Mon Apr 27, 2009 4:53 pm

Thank you very much for the quck reply Natarajan...

Is it possible for you to elaborate your concept a bit...can you plz explain..
//SORTJNF1 DD *
1234567sdfsadfasdf
1244567 adsfsafasd
1254567asfdsadad
//SORTJNF2 DD *
1234567wewreeter
1254576werwerewr
1265567werwrewrwerw

what the above statements will do....and i believe here i should specify my input files..

correct me if i am wrong...

Thank you..

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Mon Apr 27, 2009 5:00 pm

SORTJNF1 is the input file 1
SORTJNF2 is input file2
JOINKEYS FILES=F1,FIELDS=(1,7,A) <-- specify key of file 1
JOINKEYS FILES=F2,FIELDS=(1,7,A) <-- specify key of file 2
REFORMAT FIELDS=(F1:1,5200,F2:10,3) <-- specify what fields needs to be move
moved to output file from each file..
Natarajan
Chennai

deepu
Member
Posts: 15
Joined: Fri Apr 24, 2009 10:40 am

Post by deepu » Mon Apr 27, 2009 5:28 pm

Great!!!!!...it works...thanks a lot.. :wink: ...

Now if i want to eliminate the dups...what was the option??

It's very helpful and intresting to learn about SORT!!! magic... :)

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Mon Apr 27, 2009 7:42 pm

Use SUM FIELDS=NONE
Natarajan
Chennai

deepu
Member
Posts: 15
Joined: Fri Apr 24, 2009 10:40 am

Post by deepu » Tue Apr 28, 2009 11:58 am

SUM FIELDS = NONE is not working to remove dups...my SYSIN is...

//SYSIN DD *
JOINKEYS FILES=F1,FIELDS=(43,7,A)
JOINKEYS FILES=F2,FIELDS=(43,7,A)
REFORMAT FIELDS=(F1:1,5,43,7,F2:58,4)
SORT FIELDS=COPY
SUM FIELDS=NONE
/*

it's not eliminating the DUPS.....and one more is to write the un matched records to an unmatch file which was not mentioned previously...

Thanks in Advance,
deepu.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Tue Apr 28, 2009 3:04 pm

Below code write the matched records to one file & records only on FILE 1 on to another file.

Code: Select all

//SORT1    EXEC PGM=SORT                                
//SORTOF01 DD DSN=xxxx.xxx.OUT  <-- give required space, dcb parameters                  
//SORTOF02 DD DSN=yyyy.yyy.out, <-- give required space, dcb parameters
//SORTJNF1 DD DSN=DEV.FILE1,DISP=SHR
//SORTJNF2 DD DSN=DEV.FILE1,DISP=SHR
//SYSOUT   DD SYSOUT=*                                  
//SYSIN    DD *                                      
  JOINKEYS FILES=F1,FIELDS=&#40;1,7,A&#41;                     
  JOINKEYS FILES=F2,FIELDS=&#40;1,7,A&#41;                     
  JOIN UNPAIRED,F1
  REFORMAT FIELDS=&#40;F1&#58;1,5200,F2&#58;1,5200&#41;,FILL=X'FF'
  OUTFIL FILES=01,INCLUDE=&#40;5201,1,BI,EQ,X'FF'&#41;,
  OUTREC=&#40;1,5200&#41;
  OUTFIL FILES=02,INCLUDE=&#40;5201,1,BI,NE,X'FF'&#41;
  SORT FIELDS=COPY

Regarding duplicates, have another step before the main step and remove the duplicates on input files.
Natarajan
Chennai

maheshvamsi
Active Member
Posts: 52
Joined: Wed Mar 25, 2009 11:56 pm
Location: Banglore

Post by maheshvamsi » Tue Apr 28, 2009 3:10 pm

Try to use below code for eleminating duplicates.

//SYSIN DD *
JOINKEYS FILES=F1,FIELDS=(43,7,A)
JOINKEYS FILES=F2,FIELDS=(43,7,A)
REFORMAT FIELDS=(F1:1,5,43,7,F2:58,4)
SORT FIELDS=(43,7,ch,a)
SUM FIELDS=NONE
/*

I assumed key is starting from 43 to (43+7).

When you are using SOrt fields =copy, it wont consider key, it will copy everything.

For eliminating duplicates, we need more information like record length of file & some sample data.
Thanks

MaheshVamsi

deepu
Member
Posts: 15
Joined: Fri Apr 24, 2009 10:40 am

Post by deepu » Tue Apr 28, 2009 3:26 pm

It's working..:-)...Thank you for the clarifiation....

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others