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

REPLACE records in file1 based on comparison with file2


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

New User


Joined: 15 Jul 2009
Posts: 4
Location: US

PostPosted: Wed Jul 15, 2009 3:42 am
Reply with quote

Hi,

I want to compare 2 files , file1 and file2 based on key and output the matching record key with file1 data in the output file


File1 (first 2 bytes- key)
****
AS ASIA
AZ ARIZONA
NY NEWYORK

File2
*****
AS AMERICAN SAMOA
AZ ARIZONA
NY NEWYORK

outputfile
********
AS ASIA


Thanks
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Wed Jul 15, 2009 9:24 am
Reply with quote

Hi Vinodh,

These are some of the topics already discussed in the forum before.
Please refer and let us know if you have still were not able to do it...

Topic1
Topic2
Topic3
Topic4
Topic5
Back to top
View user's profile Send private message
buzzvinodh_chandra

New User


Joined: 15 Jul 2009
Posts: 4
Location: US

PostPosted: Wed Jul 15, 2009 11:28 pm
Reply with quote

Hi Binop,

The related posts you gave does not help me.

Can anyone please helpme in getting the required results???

Thanks
Back to top
View user's profile Send private message
buzzvinodh_chandra

New User


Joined: 15 Jul 2009
Posts: 4
Location: US

PostPosted: Wed Jul 15, 2009 11:37 pm
Reply with quote

I actually modified my requirement slightly..

Compare the keys..if keys are matching then compare the next field...if that is not matching, then replace the record in file1 with file2 record

File1 (first 2 bytes- key)
****
AS ASIA
AZ ARIZONA
NY NEWYORK
CA CALIFORNIA

File2
*****
AS AMERICAN SAMOA
AZ ARIZONA
NY NEWYORK
NV NEVADA

outputfile ( ALL THE RECORDS IN FILE1 NEEDS TO BE OUTPUTED WITH MODIFICATIONS)
********
AS ASIA ---- ONLY THE POSITIONS 4 TO 15 NEEDS TO BE MODIFIED WITH FILE2 VALUES AS THE KEY (1-2) ARE MATCHING WITH FILE1
AZ ARIZONA
NY NEWYORK
CA CALIFORNIA
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: Thu Jul 16, 2009 1:24 am
Reply with quote

Your explanations are quite confusing. You say ALL THE RECORDS IN FILE1 NEEDS TO BE OUTPUTED WITH MODIFICATIONS, but the outputfile you show in your latest post is the same as the original file1 (no modifications). Then you say ONLY THE POSITIONS 4 TO 15 NEEDS TO BE MODIFIED WITH FILE2 VALUES AS THE KEY (1-2) ARE MATCHING WITH FILE1, but the value you show is positions 4-15 is from file1 (ASIA), not from file2 (AMERICAN SAMOA).

I don't know how you expect anyone to help you when you can't explain clearly what you want to do or show an input and output example that makes sense.
Back to top
View user's profile Send private message
buzzvinodh_chandra

New User


Joined: 15 Jul 2009
Posts: 4
Location: US

PostPosted: Thu Jul 16, 2009 3:25 am
Reply with quote

Hi ,

Sorry for the confusion in my previous note..below is the actual need.

File1 (first 2 bytes- key)
****
AS AMERICAN SAMOA
AZ ARIZONA
NY NEWYORK
CA CALIFORNIA

File2
*****
AS ASIA
AZ ARIZONA
NY NEWYORK
NV NEVADA

outputfile ( ALL THE RECORDS IN FILE1 NEEDS TO BE OUTPUTED WITH MODIFICATIONS)
********
AS ASIA ---- ONLY THE POSITIONS 4 TO 15 NEEDS TO BE MODIFIED WITH FILE2 VALUES AS THE KEY (1-2) ARE MATCHING WITH FILE1
AZ ARIZONA
NY NEWYORK
CA CALIFORNIA
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: Thu Jul 16, 2009 4:15 am
Reply with quote

Here's a DFSORT/ICETOOL job that will do what I think you asked for. I assumed that your input file has RECFM=FB and LRECL=80, but the job can be changed appropriately for other attributes. I also assumed that you want the output in the original order of the file1 input records as shown in your example (NY before CA).

Code:

//S1    EXEC  PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG  DD SYSOUT=*
//IN1 DD DSN=...  input file1 (FB/80)
//IN2 DD DSN=...  input file2 (FB/80)
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(MOD,PASS)
//T2 DD DSN=&&T2,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//OUT DD DSN=...  output file (FB/80)
//TOOLIN   DD    *
COPY FROM(IN1) TO(T1) USING(CTL1)
COPY FROM(IN2) TO(T1) USING(CTL2)
SPLICE FROM(T1) TO(T2) ON(1,2,CH) KEEPNODUPS WITH(4,15)
SORT FROM(T2) TO(OUT) USING(CTL3)
/*
//CTL1CNTL DD *
  INREC OVERLAY=(81:C'1',82:SEQNUM,8,ZD)
/*
//CTL2CNTL DD *
  INREC OVERLAY=(81:C'2',82:8X)
/*
//CTL3CNTL DD *
  INCLUDE COND=(81,1,CH,EQ,C'1')
  SORT FIELDS=(82,8,ZD,A)
/*
Back to top
View user's profile Send private message
Ketan Varhade

Active User


Joined: 29 Jun 2009
Posts: 197
Location: Mumbai

PostPosted: Thu Jul 16, 2009 1:43 pm
Reply with quote

If you want to use Syncsort then use Joinkey to get the desired results.
Back to top
View user's profile Send private message
Alissa Margulies

SYNCSORT Support


Joined: 25 Jul 2007
Posts: 496
Location: USA

PostPosted: Sat Jul 18, 2009 2:10 am
Reply with quote

Here is a SyncSort for z/OS job that will modify the records:
Code:
//SORT1  EXEC PGM=SORT                                 
//SORTJNF1 DD *                                       
AS AMERICAN SAMOA                                     
AZ ARIZONA                                             
NY NEWYORK                                             
CA CALIFORNIA                                         
//SORTJNF2 DD *                                       
AS ASIA                                               
AZ ARIZONA                                             
NY NEWYORK                                             
NV NEVADA                                             
//SORTOUT  DD SYSOUT=*                                 
//SYSOUT   DD SYSOUT=*                                   
//SYSIN    DD *                                           
   JOINKEYS FILES=F1,FIELDS=(1,2,A)                   
   JOINKEYS FILES=F2,FIELDS=(1,2,A)                   
   JOIN UNPAIRED,F1                                   
   REFORMAT FIELDS=(F1:1,80,F2:1,80),FILL=(X'FF')     
   INREC IFTHEN=(WHEN=(81,1,BI,EQ,X'FF'),BUILD=(1,80)),
         IFTHEN=(WHEN=NONE,BUILD=(1,3,84,15,19,62))   
   SORT FIELDS=COPY     
/*                               

Here is the output produced from the above job:
Code:
AS ASIA       
AZ ARIZONA   
CA CALIFORNIA
NY NEWYORK   

If you need the records in the same order as the original input File 1, let me know.
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
Search our Forums:

Back to Top