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

Cross join of 2 files


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Aneesh

New User


Joined: 30 Sep 2006
Posts: 60

PostPosted: Thu Jul 02, 2009 3:35 am
Reply with quote

Hi,

I have 2 files FB of length 5 bytes each. I want to create an output file that has the cross join of all records from the first file to the second.

Input file 1
11111
22222
33333

Input file 2
AAAAA
BBBBB

Output file
11111AAAAA
11111BBBBB
22222AAAAA
22222BBBBB
33333AAAAA
33333BBBBB

Can this be done using sort?

Thanks in advance,
Aneesh.
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: Thu Jul 02, 2009 4:51 am
Reply with quote

Hello,

No.

What you want to do is a cartesian join.

The last several times this was asked (searching this dfsort part of the forum will find these topics), the answer from IBM was that
Quote:
DFSORT does not have a built-in function to do a cartesian join.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Jul 02, 2009 5:27 am
Reply with quote

Aneesh,

The following JCL will give you the desired results. I assumed that your input 2 has just 2 records and you are interested in only the first 5 bytes. If you have more records in your file2 , the output will be huge.

Code:

//STEP0100 EXEC PGM=SORT                                   
//SYSOUT   DD SYSOUT=*                                     
//SORTIN   DD *                                           
AAAAA                                                     
BBBBB                                                     
//SORTOUT  DD DSN=&&S1,DISP=(,PASS),SPACE=(TRK,(1,1),RLSE)
//SYSIN    DD *                                           
  OPTION COPY,STOPAFT=2                                   
  OUTREC BUILD=(C'SYM',SEQNUM,1,ZD,C',C''',1,5,C'''',80:X)
/*                                                         
//STEP0200 EXEC PGM=SORT             
//SYSOUT   DD SYSOUT=*               
//SYMNAMES DD DSN=&&S1,DISP=SHR     
//SORTIN   DD *                     
11111                               
22222                               
33333                               
//SORTOUT  DD SYSOUT=*               
//SYSIN    DD *                     
  OPTION COPY                       
  OUTFIL BUILD=(1,5,SYM1,/,1,5,SYM2)
/*
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Jul 02, 2009 5:38 am
Reply with quote

SAS PROC SQL without a WHERE clause will do a Cartesian join (every record in file 1 will be matched to every record in file 2, yielding output of the number of records in file 1 times the number of records in file 2).

Googling SAS Cartesian join will get over 14,000 hits including some good explanations of the process.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Tue Nov 17, 2009 5:03 am
Reply with quote

Aneesh,

With z/OS DFSORT V1R5 PTF UK51706 or z/OS DFSORT V1R10 PTF UK51707, you can use the Joinkeys function like shown below to get the desired results. Since both files don't have a common key we add an extra byte at pos 6 using INREC for each file via JNF1CNTL and JNF2CNTL and use that as a key for matching

Code:


//STEP0100 EXEC PGM=SORT                           
//SYSOUT   DD SYSOUT=*                             
//SORTJNF1 DD DSN=Your input 5 byte file1,DISP=SHR
//SORTJNF2 DD DSN=Your input 5 byte file2,DISP=SHR
//SORTOUT  DD SYSOUT=*                             
//SYSIN    DD *                                   
  SORT FIELDS=COPY                                 
  JOINKEYS FILE=F1,FIELDS=(6,1,A),SORTED,NOSEQCK   
  JOINKEYS FILE=F2,FIELDS=(6,1,A),SORTED,NOSEQCK   
  REFORMAT FIELDS=(F1:1,5,F2:1,5)                 
//JNF1CNTL DD *                                   
  INREC BUILD=(1,5,X)                             
//JNF2CNTL DD *                                   
  INREC BUILD=(1,5,X)                             
//*


For complete details on Joinkey functions and the other new functions available with the Nov, 2009 DFSORT PTF, see:

www.ibm.com/support/docview.wss?rs=114&uid=isg3T7000174
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Merge two VSAM KSDS files into third ... JCL & VSAM 6
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
No new posts How to append a PS file into multiple... JCL & VSAM 3
Search our Forums:

Back to Top