Page 1 of 1

Comparing records in same file

PostPosted: Tue Jun 16, 2015 7:08 pm
by Arunz
Hi,

I am new resource of mainframe. I am having a requirement as follows. Please help me out.

Filein:

0001 76
0001 76
0001 77
0001 40
0002 77
0002 76
0003 78
0003 79
0003 89

Required output is:

0001 76
0001 76
0002 76
0003 78
0003 79
0003 89

requirement is:
We need to match the columns on 1 to 4. based on this when columns 06,02,EQ,C'76' we need to write output only the records having 76. we need to omit all other rows not having 76. If there are no records having 76 we need to write all the records including the duplicates.

Thanks in advance...

Re: Comparing records in same file

PostPosted: Wed Jun 17, 2015 8:03 pm
by Magesh23586
Here is the code for you, Used same inputs in INA and INB, If you are using dataset/File, then give same datset/file name for INA and INB.

//S1   EXEC  PGM=SORT     
//SYSOUT DD SYSOUT=*       
//INA DD *                 
0001 76                   
0001 76                   
0001 77                   
0001 40                   
0002 77                   
0002 76                   
0003 78                   
0003 79                   
0003 89                   
//INB DD *                 
0001 76                   
0001 76                   
0001 77                   
0001 40                   
0002 77                   
0002 76                   
0003 78                   
0003 79                   
0003 89                                                     
//SORTOUT DD SYSOUT=*                                       
//SYSIN    DD *                                             
  OPTION COPY                                               
  JOINKEYS F1=INA,FIELDS=(1,4,A)                             
  JOINKEYS F2=INB,FIELDS=(1,4,A)                             
  REFORMAT FIELDS=(F1:1,9,?)                                 
  JOIN UNPAIRED,F1                                           
  OUTFIL INCLUDE=((10,1,CH,EQ,C'B',AND,6,2,CH,EQ,C'76'),OR, 
                  (10,1,CH,EQ,C'1'))                         
//*                                                         
//JNF2CNTL DD *                                             
  INCLUDE COND=(06,02,CH,EQ,C'76')                           
  SUM FIELDS=NONE                                           
//*                                                         


Regards,
Magesh

Re: Comparing records in same file

PostPosted: Wed Jun 17, 2015 10:26 pm
by BillyBoyo
Maghesh,

The data looks to be in order, but you are sorting the file, twice. OK, you are using SUM on one, but why SORT the other?

Re: Comparing records in same file

PostPosted: Thu Jun 18, 2015 2:33 pm
by Magesh23586
Yes, your are right, we need not require sort for File 1.

Please update the below code.

  JOINKEYS F1=INA,FIELDS=(1,4,A),SORTED,NOSEQCK

Re: Comparing records in same file

PostPosted: Tue Jun 23, 2015 3:35 pm
by Arunz
Hi Maghesh,

Sorry for the late reply. Thanks for your code. But here you are comparing two files. But I am having only one file...

Re: Comparing records in same file

PostPosted: Tue Jun 23, 2015 4:04 pm
by enrico-sorichetti
Used same inputs in INA and INB,


join keys needs two files,
the trick is to use the same/only file for both

Re: Comparing records in same file

PostPosted: Tue Jun 23, 2015 4:45 pm
by Arunz
Got It... Worked as Expected... Thank you so much Maghesh and Enrico :) :)