MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SORT JOIN with duplicates

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
pawan.konduru
Beginner


Joined: 07 Oct 2014
Posts: 8
Topics: 4
Location: HYDERABAD

PostPosted: Tue Oct 01, 2019 2:22 pm    Post subject: SORT JOIN with duplicates Reply with quote

Hi,
Need some help in getting the below my output while joining two files, which has duplicates.

File-1:
Code:

AAAA 0011
AAAA 2002
AAAA 2012
AAAA 2012
AAAA 9999
BBBB 0011
BBBB 2002
BBBB 9999
CCCC 0011
CCCC 2012
CCCC 9999
DDDD 0011
DDDD 9999

here this above is having Segmented data where POS:5 to 4 bytes having 0011 is the starting segment and 9999 is the ending segment, and records in between 0011 and 9999 are details segments this may be more than one.


FILE-2
Code:

AAAA 0004
AAAA 0006
BBBB 0008
CCCC 0010
CCCC 0013


here in File-2 has KEY (1:4) to match with file-1 (1:4) and Value (6:4) which will be unique

I need to append the value from file-2 in File-1 for each record in File1. below is the SORT i used,

Code:

//SYSIN    DD *                           
   JOINKEYS FILE=F1,FIELDS=(1,4,A)         
   JOINKEYS FILE=F2,FIELDS=(1,4,A)         
   REFORMAT FIELDS=(F1:1,9,F2:6,9)         
   JOIN UNPAIRED,F1                       
   OPTION COPY                             
   OUTFIL FNAMES=MATCHED                   


Output I got is:
Code:

AAAA 00110004
AAAA 00110006
AAAA 20020004
AAAA 20020006
AAAA 20120004
AAAA 20120006
AAAA 20120004
AAAA 20120006
AAAA 99990004
AAAA 99990006
BBBB 00110008
BBBB 20020008
BBBB 99990008
CCCC 00110010
CCCC 00110013
CCCC 20120010
CCCC 20120013
CCCC 99990010
CCCC 99990013 
DDDD 0011     
DDDD 9999     


here I need the output where my Segments should be as is and the group should repeat and append second value from the file-2
It is working if there is no duplicates in File-2, ex key record BBBB. The issue is if Duplicates in File-2,

JCL step I Ran

Code:

//STEP01 EXEC PGM=DFSORT,COND=(0,NE)                 
//*                                                   
//SORTJNF1 DD *                                       
AAAA 0011                                             
AAAA 2002                                             
AAAA 2012                                             
AAAA 2012                                             
AAAA 9999                                             
BBBB 0011                                             
BBBB 2002                                             
BBBB 9999                                             
CCCC 0011                                             
CCCC 2012                                             
CCCC 9999                                             
DDDD 0011                                             
DDDD 9999                                             
//SORTJNF2 DD *                                       
AAAA 0004                                             
AAAA 0006                                             
BBBB 0008                                             
CCCC 0010                                             
CCCC 0013                                             
//MATCHED  DD DSN=&SYSUID..TEST.MATCH,                 
//         DISP=(,CATLG,DELETE),UNIT=SYSDA,           
//         SPACE=(CYL,(50,50),RLSE),                   
//         DCB=(RECFM=FB,LRECL=,BLKSIZE=0)             
//SRTMSG   DD SYSOUT=*                                 
//SYSOUT   DD SYSOUT=*                                 
//SYSIN    DD *                                       
   JOINKEYS FILE=F1,FIELDS=(1,4,A)                     
   JOINKEYS FILE=F2,FIELDS=(1,4,A)                     
   REFORMAT FIELDS=(F1:1,9,F2:6,9)                     
   JOIN UNPAIRED,F1                                   
   OPTION COPY                                         
   OUTFIL FNAMES=MATCHED                               
//*                                                   



My output should be as below,

Code:

AAAA 00110004
AAAA 20020004
AAAA 20120004
AAAA 20120004
AAAA 99990004
AAAA 00110006
AAAA 20020006
AAAA 20120006
AAAA 20120006
AAAA 99990006
BBBB 00110008
BBBB 20020008
BBBB 99990008
CCCC 00110010
CCCC 20120010
CCCC 99990010
CCCC 00110013
CCCC 20120013
CCCC 99990013
DDDD 0011
DDDD 9999




It would be very thankful, if any help on this.
_________________
Pawan K
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed Oct 02, 2019 11:12 pm    Post subject: Reply with quote

pawan.konduru,

If you need to retain the grouping, then you need to tag it using when=group and then perform a sort on the main task,

I assumed your input is already sorted on the key. Here is an Untested version.

Code:

//STEP0200 EXEC PGM=SORT                                   
//SYSOUT   DD SYSOUT=*                                     
//INA      DD *                                             
AAAA 0011                                                   
AAAA 2002                                                   
AAAA 2012                                                   
AAAA 2012                                                   
AAAA 9999                                                   
BBBB 0011                                                   
BBBB 2002                                                   
BBBB 9999                                                   
CCCC 0011                                                   
CCCC 2012                                                   
CCCC 9999                                                   
DDDD 0011                                                   
DDDD 9999                                                   
//INB      DD *                                             
AAAA 0004                                                   
AAAA 0006                                                   
BBBB 0008                                                   
CCCC 0010                                                   
CCCC 0013                                                   
//SORTOUT  DD SYSOUT=*                                     
//SYSIN    DD *                                             
  JOINKEYS F1=INA,FIELDS=(1,4,A),SORTED,NOSEQCK             
  JOINKEYS F2=INB,FIELDS=(1,4,A),SORTED,NOSEQCK             
  JOIN UNPAIRED,F1                                         
  REFORMAT FIELDS=(F1:1,88,F2:81,3,6,4)                     
  SORT FIELDS=(81,11,CH,A),EQUALS                           
  OUTREC BUILD=(1,10,92,4,15,65)                           
/*                                                         
//JNF1CNTL DD *                                             
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(6,4,CH,EQ,C'0011'),       
                             END=(6,4,CH,EQ,C'9999'),       
                            PUSH=(81:ID=8))                 
/*                                                         
//JNF2CNTL DD *                                             
  INREC IFTHEN=(WHEN=GROUP,KEYBEGIN=(1,4),                 
                            PUSH=(81:SEQ=3))               
/*                                                         

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
pawan.konduru
Beginner


Joined: 07 Oct 2014
Posts: 8
Topics: 4
Location: HYDERABAD

PostPosted: Wed Oct 09, 2019 7:46 am    Post subject: Reply with quote

Thanks a Bunch Kolusu,
Its working, and yes my both the input files are in sorted order
_________________
Pawan K
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group