Page 1 of 1

Remove dupilcates using DFSORT

PostPosted: Sat Jan 29, 2011 11:09 pm
by msnirmal1487
hi,
i have the data like the following example,

1    ab   u   
2    cd   1   â€¦.
3    cd   2   â€¦.
4    cd   3   â€¦.
5    cd   4   â€¦.
6    ab   v   
7    cd   1   â€¦.
8    cd   2   â€¦.
9    cd   3   â€¦.
10   cd   4   â€¦.
11   ab   w   
12   cd   1   â€¦.
13   cd   2   â€¦.
14   cd   3   â€¦.
15   cd   4   â€¦.
16   cd   2   â€¦.
17   cd   2   â€¦.
18   cd   3   â€¦.
19   cd   4   â€¦.
20   ab   x   
21   cd   1   â€¦.
22   cd   2   â€¦.
23   cd   3   â€¦.
24   cd   4   â€¦.


Please Note: the numbers in front are added by me for reference. the DOTS are data and the rest is the key.

I need to remove the duplicate records for the group of records from record number 11 to record number 19.

To acheive this,
    1.im grouping the records from record numbers 11 and 20 by adding a flag "1" to the end of all these records using When Group statment.
    2.removing the flag form record number 20 using include condition.
    3.creating two seperate files (a) records with out flag (b)records with flag in last field.(in 2 SORT steps)
    4.removing the duplicates from the (b) file.
    5.merging the (a) file and file from previous step.

So now it takes me 6 sort steps to complete the task and also the records from record numbers 11 to 19 are pushed to the end of the file.

It would be great if any of u could tell me if there is a simple way to do this.

Regards,
Nirmal.

Re: Remove dupilcates using DFSORT

PostPosted: Mon Jan 31, 2011 10:55 pm
by skolusu
msnirmal1487,

Unless I am mistaken, it is a simple request and you complicated it. Use the following DFSORT JCL which will give you the desired results. I assumed that your input is FB recfm and lrecl of 80, every group starts with AB in first 2 positions.

//STEP0100 EXEC PGM=SORT                                           
//SYSOUT   DD SYSOUT=*                                             
//SORTIN   DD *                                                   
AB   U                                                             
CD   1    .                                                       
CD   2    .                                                       
CD   3    .                                                       
CD   4    .                                                       
AB   V                                                             
CD   1    .                                                       
CD   2    .                                                       
CD   3    .                                                       
CD   4    .                                                       
AB   W                                                             
CD   1    .                                                       
CD   2    .                                                       
CD   3    .                                                       
CD   4    .                                                       
CD   2    .                                                       
CD   2    .                                                       
CD   3    .                                                       
CD   4    .                                                       
AB   X                                                             
CD   1    .                                                       
CD   2    .                                                       
CD   3    .                                                       
CD   4    .                                                       
//SORTOUT  DD SYSOUT=*                                             
//SYSIN    DD *                                                   
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'AB'),PUSH=(81:ID=8))
  SORT FIELDS=(81,8,CH,A,1,6,CH,A),EQUALS                         
  SUM FIELDS=NONE                                                 
  OUTREC BUILD=(1,80)                                             
//*



The output of this job is
AB   U     
CD   1    .
CD   2    .
CD   3    .
CD   4    .
AB   V     
CD   1    .
CD   2    .
CD   3    .
CD   4    .
AB   W     
CD   1    .
CD   2    .
CD   3    .
CD   4    .
AB   X     
CD   1    .
CD   2    .
CD   3    .
CD   4    .

Re: Remove dupilcates using DFSORT

PostPosted: Fri Feb 04, 2011 11:13 am
by msnirmal1487
Hi skolusu,

Thanks for the JCL :) It has worked perfectly well:)
Can you please give ur advice on a similar requirement for VB file.

Regards,
Nirmal.

Re: Remove dupilcates using DFSORT

PostPosted: Fri Feb 04, 2011 10:19 pm
by skolusu
msnirmal1487 ,

For VB files you canNOT add the group key at the end which will make all the records of same lrecl and ruining the whole concept of Variable block. You need to add the group key right after the RDW and then remove it later like shown below.

//SYSIN    DD *                                             
  INREC IFTHEN=(WHEN=INIT,BUILD=(1,4,8X,5)),                 
  IFTHEN=(WHEN=GROUP,BEGIN=(13,2,CH,EQ,C'AB'),PUSH=(5:ID=8))
  SORT FIELDS=(5,8,CH,A,13,6,CH,A),EQUALS                   
  SUM FIELDS=NONE                                           
  OUTREC BUILD=(1,4,13)                                     
//*