Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to match two files using SYNCSORT

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
View previous topic :: :: View next topic  
Author Message
rajatbagga

Active User


Joined: 11 Mar 2007
Posts: 193
Location: india

PostPosted: Mon Dec 24, 2007 7:00 pm    Post subject: How to match two files using SYNCSORT
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: 1439
Location: Bangalore,India

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

Rajat,
Found similar topic in the below link. Customize to your requirement -
http://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    Post subject:
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    Post subject:
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 Moderator


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

PostPosted: Mon Dec 24, 2007 9:44 pm    Post subject:
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    Post subject:
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: 193
Location: india

PostPosted: Tue Dec 25, 2007 12:37 am    Post subject:
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 Moderator


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

PostPosted: Tue Dec 25, 2007 1:49 am    Post subject:
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:

www.ibm.com/servers/storage/support/software/sort/mvs/srtmpub.html

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: 193
Location: india

PostPosted: Tue Dec 25, 2007 3:07 am    Post subject: Reply to: How to match two files and create a output file us
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: 193
Location: india

PostPosted: Fri Dec 28, 2007 2:09 pm    Post subject:
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 Moderator


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

PostPosted: Fri Dec 28, 2007 10:52 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Unable to create multiple files using... mbattu COBOL Programming 3 Fri May 05, 2017 5:35 pm
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
No new posts Dynamic split of files under groups sril.krishy DFSORT/ICETOOL 4 Mon Apr 17, 2017 1:09 pm
No new posts Compare two files and subtract values ameetmund DFSORT/ICETOOL 7 Fri Mar 31, 2017 3:35 pm
No new posts Append data from two files into a sin... Praveen04 DFSORT/ICETOOL 5 Thu Mar 16, 2017 7:29 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us