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

How to match two files using SYNCSORT


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rajatbagga

Active User


Joined: 11 Mar 2007
Posts: 199
Location: india

PostPosted: Mon Dec 24, 2007 7:00 pm
Reply with quote

i have requrement in which i have to write a JOB for matching two files for example if i have two input files FILE A and FILE B as shown below and i have to create FILE C as shown below.

Input files FILE A and FILE B
FILE A
A45 345
A45 678
A78 346
A56 456
A56 789
A56 678
A92 900

FILE B
A45 RAHUL
A67 ANKUR
A78 ROY
A56 AMIT

Output file FILE C
FILE C
A45 RAHUL 345 678
A78 ROY 346
A56 AMIT 456 789 678
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Mon Dec 24, 2007 7:15 pm
Reply with quote

Rajat,
Found similar topic in the below link. Customize to your requirement -
www.ibmmainframes.com/viewtopic.php?t=24724&highlight=splice
Back to top
View user's profile Send private message
krisprems

Active Member


Joined: 27 Nov 2006
Posts: 649
Location: India

PostPosted: Mon Dec 24, 2007 8:13 pm
Reply with quote

Code:
//*************************
//STEP001  EXEC PGM=ICETOOL
//TOOLMSG  DD SYSOUT=*     
//DFSMSG   DD SYSOUT=*     
//IN1      DD *           
A45 345                   
A45 678                   
A78 346                   
A56 456                   
A56 789                   
A56 678                   
A92 900                   
/*                         
//IN2      DD *           
A45 RAHUL                 
A67 ANKUR                 
A78 ROY                   
A56 AMIT                   
/*                         
//TMP1     DD DSN=&&TEMP1,DISP=(MOD,PASS),SPACE=(TRK,(5,5)),UNIT=SYSDA
//BOTH     DD SYSOUT=*                                               
//F1ONLY   DD SYSOUT=*                                               
//F2ONLY   DD SYSOUT=*                                               
//TOOLIN   DD *                                                       
 COPY FROM(IN2)  TO(TMP1)                                             
 COPY FROM(IN1)  TO(TMP1) USING(NKK1)                                 
 SPLICE FROM(TMP1) TO(BOTH) ON(1,3,CH) WITH(11,3) WITH(15,3) -       
 WITH(20,3) WITHEACH                                                 
/*                                                                   
//NKK1CNTL DD   *                                                     
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,3))),   
        IFTHEN=(WHEN=(81,8,ZD,EQ,1),BUILD=(1,4,11:5,3)),             
        IFTHEN=(WHEN=(81,8,ZD,EQ,2),BUILD=(1,4,15:5,3)),             
        IFTHEN=(WHEN=(81,8,ZD,EQ,3),BUILD=(1,4,20:5,3)),             
        IFOUTLEN=80                                                   
/*                                                                   


BOTH contains
Code:
A45 RAHUL 345 678     
A56 AMIT  456 789  678
A78 ROY   346         

Note: in the o/p the first field would be in sorted order, let me know if it is a must to have it in original order as the i/p.
Back to top
View user's profile Send private message
krisprems

Active Member


Joined: 27 Nov 2006
Posts: 649
Location: India

PostPosted: Mon Dec 24, 2007 8:36 pm
Reply with quote

This is a 2 pass solution if both i/p files are of same attributes
Code:
//*******************************************************             
//STEP001  EXEC PGM=ICETOOL                                           
//TOOLMSG  DD SYSOUT=*                                               
//DFSMSG   DD SYSOUT=*                                               
//IN1      DD I/P FILE-1                                             
//         DD I/P FILE-2                                             
//TMP1     DD DSN=&&TEMP1,DISP=(MOD,PASS),SPACE=(TRK,(5,5)),UNIT=SYSDA
//BOTH     DD SYSOUT=*                                               
//TOOLIN   DD *                                                       
 SORT FROM(IN1)  TO(TMP1) USING(NKK1)                                 
 SPLICE FROM(TMP1) TO(BOTH) ON(1,3,CH) WITH(11,3) WITH(15,3) -       
 WITH(20,3) WITHEACH                                                 
/*                                                                   
//NKK1CNTL DD   *                                                     
  SORT FIELDS=(1,3,CH,A),EQUALS                                       
  OUTREC IFTHEN=(WHEN=INIT,                                           
        OVERLAY=(81:SEQNUM,8,ZD,START=0,RESTART=(1,3))),             
        IFTHEN=(WHEN=(81,8,ZD,EQ,1),BUILD=(1,4,11:5,3)),             
        IFTHEN=(WHEN=(81,8,ZD,EQ,2),BUILD=(1,4,15:5,3)),             
        IFTHEN=(WHEN=(81,8,ZD,EQ,3),BUILD=(1,4,20:5,3)),             
        IFOUTLEN=80                                                   
/*
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Mon Dec 24, 2007 9:44 pm
Reply with quote

Krisprems,

You don't need F1ONLY or F2ONLY in your first solution.

rajatbagga,

If you need the output sorted in the original input file B order as shown in your example, you can use a DFSORT/ICETOOL job like this. I assumed that your input files have RECFM=FB and LRECL=80, but the job can be changed appropriately for other attributes:

Code:

//S1    EXEC  PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG  DD SYSOUT=*
//CON DD *      INPUT FILE B
A45  RAHUL
A67  ANKUR
A78  ROY
A56  AMIT
/*
//    DD *      INPUT FILE A
A45   345
A45   678
A78   346
A56   456
A56   789
A56   678
A92   900
/*
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//T2 DD DSN=&&T2,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//OUT DD DSN=...  output file (FB/80)
//TOOLIN DD *
SORT FROM(CON) TO(T1) USING(CTL1)
SPLICE FROM(T1) TO(T2) ON(1,3,CH) -
  WITHEACH WITH(13,3) WITH(18,3) WITH(23,3)
SORT FROM(T2) TO(OUT) USING(CTL2)
/*
//CTL1CNTL DD *
  OPTION EQUALS
  INREC OVERLAY=(89:SEQNUM,8,ZD)
  SORT FIELDS=(1,3,CH,A)
  OUTREC IFTHEN=(WHEN=INIT,
      OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,3))),
    IFTHEN=(WHEN=(81,8,ZD,EQ,+2),BUILD=(1,3,13:7,3,81:81,16)),
    IFTHEN=(WHEN=(81,8,ZD,EQ,+3),BUILD=(1,3,18:7,3,81:81,16)),
    IFTHEN=(WHEN=(81,8,ZD,EQ,+4),BUILD=(1,3,23:7,3,81:81,16))
/*
//CTL2CNTL DD *
  SORT FIELDS=(89,8,ZD,A)
  OUTREC BUILD=(1,80)
/*
Back to top
View user's profile Send private message
krisprems

Active Member


Joined: 27 Nov 2006
Posts: 649
Location: India

PostPosted: Mon Dec 24, 2007 9:56 pm
Reply with quote

Quote:
Krisprems,

You don't need F1ONLY or F2ONLY in your first solution.
yes Frank, but i realised it after posting here icon_neutral.gif
Back to top
View user's profile Send private message
rajatbagga

Active User


Joined: 11 Mar 2007
Posts: 199
Location: india

PostPosted: Tue Dec 25, 2007 12:37 am
Reply with quote

Thank you very much Krisprems and Frank . Now please tell me how can i understand this code . I mean can you please provide me with some kind of document which i can read and understand the code you all have posted since i am new to these utilities.....
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Tue Dec 25, 2007 1:49 am
Reply with quote

If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from:

Use [URL] BBCode for External Links

For complete details of all DFSORT and ICETOOL functions and syntax, see "z/OS Application Programming Guide" which you can access from the same link above.
Back to top
View user's profile Send private message
rajatbagga

Active User


Joined: 11 Mar 2007
Posts: 199
Location: india

PostPosted: Tue Dec 25, 2007 3:07 am
Reply with quote

thank you very much i was reading the same document as spcified by you.....
Back to top
View user's profile Send private message
rajatbagga

Active User


Joined: 11 Mar 2007
Posts: 199
Location: india

PostPosted: Fri Dec 28, 2007 2:09 pm
Reply with quote

i have a change in my requrement if following are the two input files

FILE A
A45 RAHUL
A67 ANKUR
A78 ROY
A56 AMIT


FILE B
A45 345
A45 678
A78 346
A56 456
A56 789
A56 678
A92 900

then the output file should be:

FILE C
A45 RAHUL 345
A45 RAHUL 678
A67 ANKUR
A78 ROY 346
A56 AMIT 456
A56 AMIT 789
A56 AMIT 678

how to do that now?
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Dec 28, 2007 10:52 pm
Reply with quote

Here's a DFSORT/ICETOOL job for your new requirement.

Code:

//S1    EXEC  PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG  DD SYSOUT=*
//CON DD *      INPUT FILE A
A45  RAHUL
A67  ANKUR
A78  ROY
A56  AMIT
/*
//    DD *      INPUT FILE B
A45  345
A45  678
A78  346
A56  456
A56  789
A56  678
A92  900
/*
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//T2 DD DSN=&&T2,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//OUT DD SYSOUT=*
//TOOLIN DD *
SORT FROM(CON) TO(T1) USING(CTL1)
SPLICE FROM(T1) TO(T2) ON(1,3,CH) KEEPNODUPS -
  WITHALL WITH(13,3) USING(CTL2)
SORT FROM(T2) TO(OUT) USING(CTL3)
/*
//CTL1CNTL DD *
  OPTION EQUALS
  INREC OVERLAY=(89:SEQNUM,8,ZD)
  SORT FIELDS=(1,3,CH,A)
  OUTREC IFTHEN=(WHEN=INIT,
      OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,3))),
    IFTHEN=(WHEN=(81,8,ZD,GE,+2),BUILD=(1,3,13:6,3,81:81,16))
/*
//CTL2CNTL DD *
  OUTFIL FNAMES=T2,OMIT=(6,1,CH,GE,C'0')
/*
//CTL3CNTL DD *
  SORT FIELDS=(89,8,ZD,A)
  OUTREC BUILD=(1,80)
/*
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 -> JCL & VSAM

 


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