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

Compare files with duplicates in one file.


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
gy3c

New User


Joined: 31 Aug 2022
Posts: 5
Location: India

PostPosted: Wed Aug 31, 2022 10:42 pm
Reply with quote

Hello All,

Could someone please help me with a logic for the below requirement. I have two input files

Input file 1:(no duplicates)

100 data1
101 data2
102 data3
103 data4


File 2:

100 1
100 2
100 3
100 4
101 1
101 2
102 1
102 2
103 1
103 2
103 3
104 4

Output file 1:

100 1 data1
100 2
100 3
100 4
101 1 data2
101 2
102 1 data3
102 2
103 1 data4
103 2
103 3
103 4

Can someone help me how to accomplish this using cobol or sort ?
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 1614

PostPosted: Wed Aug 31, 2022 10:53 pm
Reply with quote

This question is not related in any manner neither to “COBOL programming”, nor to any other programming language.

This requires only your ability to think logically, and to design algorithms for various tasks.

In your case: you only need to join records from both inputs when 3-bytes keys are equal in both of them, AND the sequence number from the second input equals to 1.
In all other cases you need to use only the record from input two.

P.S.
Usually, this is covered at the Lesson #1 of any programming classes…

P.P.S.
It would be nice if you learned how to use the Code button, when posting your questions.
Back to top
View user's profile Send private message
Joerg.Findeisen

Active Member


Joined: 15 Aug 2015
Posts: 905
Location: Bamberg, Germany

PostPosted: Wed Aug 31, 2022 11:00 pm
Reply with quote

It's 10 lines of SORT (or less) to achieve this. Also, z/OS mostly knows only Datasets.
Back to top
View user's profile Send private message
gy3c

New User


Joined: 31 Aug 2022
Posts: 5
Location: India

PostPosted: Thu Sep 01, 2022 7:29 am
Reply with quote

Thanks all for the response. The sequence number will not be always 1,2,3,4.It could be a random 3 digit code.sortee in ascending order.
I just posted an example..i will also try some coding today and let know for any doubts.
Back to top
View user's profile Send private message
Joerg.Findeisen

Active Member


Joined: 15 Aug 2015
Posts: 905
Location: Bamberg, Germany

PostPosted: Thu Sep 01, 2022 10:08 am
Reply with quote

The beginning of the sequence number doesn't matter. It will always be the first entry from F2 that gets the additional data added. Sample:
Code:
100 2 data1
100 3       
100 4       
100 9       
101 1 data2
101 2       
102 1 data3
102 2       
103 1 data4
103 2       
103 3       
Back to top
View user's profile Send private message
gy3c

New User


Joined: 31 Aug 2022
Posts: 5
Location: India

PostPosted: Thu Sep 01, 2022 11:41 am
Reply with quote

Yes,the beginning of sequence number doesn't matter.its always the first one. Because , the input file 2 will be anyways sorted
Back to top
View user's profile Send private message
gy3c

New User


Joined: 31 Aug 2022
Posts: 5
Location: India

PostPosted: Thu Sep 01, 2022 12:48 pm
Reply with quote

can someone please let me know if the below logic would work ? and if there is any other easier way of doing it ?


read file1
read file 2

perform until EOF-FILE 1 OR EOF -FILE 2

If file1-key = file2-key
if FLAG-NOT SET
move data to output file
set flag-set to true
end-if
move file 2 to output layout

read file 1
read file 2
end-if

if file 1 < file 2
Write Output file from file 2
read file 1
end if

if file 1 > FILE 2
Write Output file from file 2
READ FILE 2
END-IF

END-PERFORM
Back to top
View user's profile Send private message
Joerg.Findeisen

Active Member


Joined: 15 Aug 2015
Posts: 905
Location: Bamberg, Germany

PostPosted: Thu Sep 01, 2022 2:16 pm
Reply with quote

Sample, free of charge:

Code:
//WHATEVER EXEC PGM=ICEMAN                                       
//F1       DD *                                                   
100 data1                                                         
101 data2                                                         
102 data3                                                         
103 data4                                                         
/*                                                               
//F2       DD *                                                   
100 2                                                             
100 3                                                             
100 6                                                             
100 9                                                             
101 5                                                             
101 6                                                             
102 8                                                             
102 9                                                             
103 1                                                             
103 2                                                             
103 6                                                             
104 8                                                             
/*                                                               
//SYSOUT   DD SYSOUT=*                                           
//SORTOUT  DD SYSOUT=*                                           
//SYSIN    DD *                                                   
  OPTION COPY                                                     
  JOINKEYS F1=F1,FIELDS=(1,3,A),SORTED                           
  JOINKEYS F2=F2,FIELDS=(1,3,A),SORTED                           
  REFORMAT FIELDS=(F2:1,5,F1:5,8)                                 
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,4,ZD,RESTART=(1,3)))
  OUTFIL FNAMES=(SORTOUT),                                       
    REMOVECC,                                                     
    IFTHEN=(WHEN=(81,4,ZD,EQ,+1),BUILD=(1,5,X,6,8)),             
    IFTHEN=(WHEN=NONE,BUILD=(1,5))                               
  END                                                             
/*
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 1614

PostPosted: Thu Sep 01, 2022 6:48 pm
Reply with quote

Again:

It would be nice if you learned how to use the Code button, when posting your questions.
Back to top
View user's profile Send private message
Lynne

New User


Joined: 15 Jan 2015
Posts: 72
Location: USA

PostPosted: Sat Sep 03, 2022 7:51 am
Reply with quote

Read up on the JOIN for Sort (ICEMAN or Syncsort)
and then go thru Joerg.Findeisen's excellent simple example.
Back to top
View user's profile Send private message
gy3c

New User


Joined: 31 Aug 2022
Posts: 5
Location: India

PostPosted: Sun Sep 04, 2022 2:36 pm
Reply with quote

Joerg.Findeisen wrote:
Sample, free of charge:

Code:
//WHATEVER EXEC PGM=ICEMAN                                       
//F1       DD *                                                   
100 data1                                                         
101 data2                                                         
102 data3                                                         
103 data4                                                         
/*                                                               
//F2       DD *                                                   
100 2                                                             
100 3                                                             
100 6                                                             
100 9                                                             
101 5                                                             
101 6                                                             
102 8                                                             
102 9                                                             
103 1                                                             
103 2                                                             
103 6                                                             
104 8                                                             
/*                                                               
//SYSOUT   DD SYSOUT=*                                           
//SORTOUT  DD SYSOUT=*                                           
//SYSIN    DD *                                                   
  OPTION COPY                                                     
  JOINKEYS F1=F1,FIELDS=(1,3,A),SORTED                           
  JOINKEYS F2=F2,FIELDS=(1,3,A),SORTED                           
  REFORMAT FIELDS=(F2:1,5,F1:5,8)                                 
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,4,ZD,RESTART=(1,3)))
  OUTFIL FNAMES=(SORTOUT),                                       
    REMOVECC,                                                     
    IFTHEN=(WHEN=(81,4,ZD,EQ,+1),BUILD=(1,5,X,6,8)),             
    IFTHEN=(WHEN=NONE,BUILD=(1,5))                               
  END                                                             
/*
Back to top
View user's profile Send private message
hyeamit

New User


Joined: 16 Apr 2009
Posts: 1
Location: Jaipur

PostPosted: Thu Sep 08, 2022 10:29 am
Reply with quote

Thank you. This is useful.
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 Selecting the max value from a file. DFSORT/ICETOOL 3
No new posts Change history of vsam file. JCL & VSAM 3
No new posts Merge files with a key and insert a b... DFSORT/ICETOOL 6
No new posts Split large FB file based on Key coun... DFSORT/ICETOOL 4
No new posts EMPTY file check scenario JCL & VSAM 6
Search our Forums:

Back to Top