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

Compare two files and replace file2 values with file1 values


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   This topic is locked: you cannot edit posts or make replies.
View previous topic :: View next topic  
Author Message
vinuk2009

New User


Joined: 30 Apr 2009
Posts: 19
Location: chennai

PostPosted: Tue Sep 04, 2012 10:35 pm
Reply with quote

Hi,

I have two fixed length files. file1 has record length 80 and file2 has record length 600. I need to compare these two files and replace file2 values file1 values if the key in file1 match with key in file2. key in file1 starts from 10 and ends at 18. key in file2 starts from 6 and ends at 14. I need to replace file2 values start from 20 to 28 with file1 values start from 1 to 9 if the file1 key matches with file2 key otherwise we need not to replace. Also I need to keep header and trailer of file2 as it is. header record is first record on the file and trailer record is last record in the file. Could some one please help me in achieving this result.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Sep 04, 2012 10:41 pm
Reply with quote

Quote:
Could some one please help me in achieving this result.


Can you this and post the sysout so we can see what level of sort you have at your site, please?

Code:
//S1 EXEC PGM=ICEMAN
//SYSOUT   DD SYSOUT=*
//SORTIN DD *
RECORD
/*
//SORTOUT DD DUMMY
//SYSIN   DD   *
  OPTION COPY
/*


JOINKEYS would be the favourite if you have it, but we need to know the results of the above to see if you do and what else you may have.
Back to top
View user's profile Send private message
vinuk2009

New User


Joined: 30 Apr 2009
Posts: 19
Location: chennai

PostPosted: Tue Sep 04, 2012 10:48 pm
Reply with quote

Hi Bill,

Thank you for looking into this post. Our site will support DFSORT as well as join keys. So please give me solution by using any of the above.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Sep 04, 2012 10:49 pm
Reply with quote

other than position in the file,
is there a way to interrogate and recognize the head and trailer records?

The sysout was requested,
because JOINKEYS is available with G.

hopefully none of the H functions are necessary if you only have G.

re: ibmmainframes.com/viewtopic.php?t=33389
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Tue Sep 04, 2012 10:55 pm
Reply with quote

vinuk2009 wrote:
Hi Bill,

Thank you for looking into this post. Our site will support DFSORT as well as join keys. So please give me solution by using any of the above.


Post the SYSOUT from the sample job that BILL gave you to run.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Sep 04, 2012 10:58 pm
Reply with quote

How did we slip from giving you help to giving you a solution?

With respect, I'd like to see the requested output before investing time into giving you some pointers.
Back to top
View user's profile Send private message
vinuk2009

New User


Joined: 30 Apr 2009
Posts: 19
Location: chennai

PostPosted: Wed Sep 05, 2012 9:54 pm
Reply with quote

Hi Bill,

Sorry for late response. I have executed your sort job and the information of DFSORT from the sysout is as follows. I believe you are looking for this information.

ICE250I 0 VISIT www.ibm.com/storage/dfsort FOR DFSORT PAPERS, EXAMPLES AND,MORE
ICE000I 1 - CONTROL STATEMENTS FOR 5694-A01, Z/OS DFSORT V1R12 - 01:52 ON WED SEP 05, 2012 -
0 OPTION COPY 00001601
ICE201I H RECORD TYPE IS F - DATA STARTS IN POSITION 1
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Sep 06, 2012 5:12 am
Reply with quote

Thank you vinuk2009.

It is a fairly simple JOINKEYS.

Specify the key for each file on the JOINKEYS statement. If the files are already sorted, specify SORTED,NOSEQ on the JOINKEYS statement. If not sorted, they will be sorted by default.

JOIN UNPAIRED,F2

Assuming that F2 is your main file.

REFORMAT FIELDS=(F2:1,600,F1:1,9,?)

INREC IFOUTLEN=600,
IFTHEN=(WHEN=(610,1,CH,EQ,C'B),
OVERLAY=(20:602,9)


And that'd be about it.

I'm assuming that the file 1 can never match a header/trailer record; that you want all unmatch file 2 records on your output file; that you are unconcerned about unmatched file 1 records; you are not really "comparing" the recors, but joining/matching on the key fields.

The header/trailer point that you brought up is a red-herring, unless there is more you are not telling.

Edit: Corrected 601 to 602, per Kolusu :-)
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Fri Sep 07, 2012 12:35 am
Reply with quote

vinuk2009,

use the following DFSORT JCL which will give you the desired results
Code:

//STEP0100 EXEC PGM=SORT                               
//SYSOUT   DD SYSOUT=*                                 
//INA      DD DISP=SHR,DSN=Your Input FB 600 Byte file
//INB      DD DISP=SHR,DSN=Your Input FB 80 Byte file
//SORTOUT  DD SYSOUT=*                                 
//SYSIN    DD *                                         
  OPTION COPY                                           
  JOINKEYS F1=INA,FIELDS=(06,9,A)                       
  JOINKEYS F2=INB,FIELDS=(10,9,A)                       
  JOIN UNPAIRED,F1                                     
  REFORMAT FIELDS=(F1:1,600,?,F2:1,9)                   
  INREC IFOUTLEN=600,                                   
  IFTHEN=(WHEN=(601,1,CH,EQ,C'B'),OVERLAY=(20:602,9))   
//*
Back to top
View user's profile Send private message
vinkum

New User


Joined: 20 Sep 2019
Posts: 2
Location: INDIA

PostPosted: Fri Sep 20, 2019 3:43 pm
Reply with quote

Hi,

Can anyone help me out, File 1 data is not getting overlayed with file2 data
i could see in spool number of matched records and mismatched records but for matched records data in FILE1 is not getting replaced by file2

Can someone please correct me or suggest

//**REQUIREMENT: FOR ALL MATCHING RECORDS OF FILE2,UPDATE FILE 1 DATA AT POSITION 24:8 BY PICKING VALUES FROM FILE2 FROM POSITION 16:8

//SETP001 EXEC PGM=SORT,REGION=0K
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTJNF1 DD DSN=FILE1,DISP=SHR FB LRECL=49 KEY 9,15
//SORTJNF2 DD DSN=FILE2,DISP=SHR FB LRECL=250 KEY 1,15
//SORTOUT DD DSN=FILE.ALL,DISP=SHR
// DISP=(,CATLG,DELETE),
// UNIT=SYSDA,SPACE=(CYL,(50,500),RLSE)
//SORTWK01 DD UNIT=SYSDA,SPACE=(CYL,(50,500),RLSE)
//SORTWK02 DD UNIT=SYSDA,SPACE=(CYL,(50,500),RLSE)
//SYSIN DD *
JOINKEYS FILES=F1,FIELDS=(9,015,A)
JOINKEYS FILES=F2,FIELDS=(1,015,A)
JOIN UNPAIRED,F1
REFORMAT FIELDS=(F1:1,49,?,F2:16,08)
OPTION COPY
INREC IFOUTLEN=49,
IFTHEN=(WHEN=(50,1,CH,EQ,C'B'),OVERLAY=(24:51,8))
/*

SPOOL:
WER484I SORTJNF1 : RCD IN= 72597,OMITTED= 0,PAIRED= 37573,UNPAIRED= 35024

WER484I SORTJNF2 : RCD IN= 40257,OMITTED= 0,PAIRED= 37573,UNPAIRED= 2684
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2022
Location: USA

PostPosted: Fri Sep 20, 2019 5:21 pm
Reply with quote

vinuk2009 wrote:
Hi,

I have two fixed length files. file1 has record length 80 and file2 has record length 600. I need to compare these two files and replace file2 values file1 values if the key in file1 match with key in file2. key in file1 starts from 10 and ends at 18. key in file2 starts from 6 and ends at 14. I need to replace file2 values start from 20 to 28 with file1 values start from 1 to 9 if the file1 key matches with file2 key otherwise we need not to replace. Also I need to keep header and trailer of file2 as it is. header record is first record on the file and trailer record is last record in the file. Could some one please help me in achieving this result.


Dear Moderators,

I believe the questions of this type: "How can I start doing my own job?" - must be prohibited at the Expert Forum.

The only questions allowed are:
- I tried to do <this>, and <this>
- I use this tool to achieve my goal
- I expected results like <this>, and <this>
- I've got the result like <this>, and/or messages/errors like <this>
- Please clarify for me the reason of bad results

Instead, again and again there are messages in the style
- Please, perform my job duties for me! I have no idea where to start from...

Those trying to ask these questions must be banned, I think.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3051
Location: NYC,USA

PostPosted: Sat Sep 21, 2019 1:01 am
Reply with quote

sergeyken, This is 7 years old post. What you raised is totally a different topic which has been discussed in past several times... So far it difficult to control such posts appearing it here than Beginners Forum.

vinkum, Please don't tailgate any post , specially too old ones. Start a new one with your requirements and make a use of Code tags.

Please lock this Thread.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Sat Sep 21, 2019 2:32 am
Reply with quote

Vinkum - apart from tailgating someone else's topic, posting to an old topic and not using the code tags you have posted in the DFSort part of the formum when you are using Syncsort.

Topic locked.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies. View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
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 INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
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
Search our Forums:

Back to Top