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

Process only last key record in a file containing dup Keys


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Naveen.katkuri24

New User


Joined: 26 Sep 2013
Posts: 3
Location: India

PostPosted: Tue Oct 09, 2018 9:39 am
Reply with quote

Hi All,

I have been a silent follower of this forum and I have used lot of tips and resolutions posted by seniors on the different topics.

I just came across one scenario. I tried to search the forum for the same, but could not find( May be I have not used the exact word to search the forums). So posting it here.


I have an input file with below fields. When the file has duplicate keys, then It should process only the last key record in the output as shown below.


Code:
Key           Ref No     Last Changed Date
AAAA                7     2017-08-14
AAAA                7     9999-12-31
AAAA                8     9999-12-31     --> output
BBBB       2147483647     9999-12-31     --> output
CCCC                3     2012-06-19
CCCC                2     2012-06-16     --> output
DDDD                4     2017-06-10
DDDD                2     2016-09-17
DDDD                3     2018-10-09     --> output
EEEE                7     1998-01-20     
EEEE                6     2000-02-28     --> output



Can any one please let me know if we can achieve this using SORT ?

Thanks in Advance.

Regards,
Naveen
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1099
Location: Dublin, Ireland

PostPosted: Tue Oct 09, 2018 1:40 pm
Reply with quote

Hi,

I'd suggest looking at ICETOOLs' SELECT LAST or SELECT LASTDUP.

Garry.
Back to top
View user's profile Send private message
sergeyken

Active Member


Joined: 29 Apr 2008
Posts: 924
Location: Maryland

PostPosted: Tue Oct 09, 2018 6:06 pm
Reply with quote

Code:
 OUTFIL NODETAIL,REMOVECC,
        SECTIONS=(1,5,
                  TRAILER3=(full record positions))
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Tue Oct 09, 2018 7:22 pm
Reply with quote

Quote:
I just came across one scenario. I tried to search the forum for the same, but could not find( May be I have not used the exact word to search the forums). So posting it here.
Sure you missed the Google look up. icon_smile.gif
ibmmainframes.com/about40127.html
ibmmainframes.com/about57520.html
ibmmainframes.com/about49085.html
ibmmainframes.com/about60697.html
Back to top
View user's profile Send private message
Naveen.katkuri24

New User


Joined: 26 Sep 2013
Posts: 3
Location: India

PostPosted: Wed Oct 10, 2018 10:05 am
Reply with quote

I have used the below code.

Code:
//IN      DD *
 AAAA                7     2017-08-14
 AAAA                7     9999-12-31
 AAAA                8     9999-12-31     
 BBBB       2147483647     9999-12-31
 CCCC                3     2012-06-19
 CCCC                2     2012-06-16     
 DDDD                4     2017-06-10
 DDDD                2     2016-09-17
 DDDD                3     2018-10-09     
 EEEE                7     1998-01-20     
 EEEE                6     2000-02-28   
 FFFF                 4    2010--08-31 
 GGGG               2     2012-03-13   
//TOOLIN   DD  *                             
  SELECT FROM(IN) TO(OUT) ON(2,6,PD) LASTDUP
/*

OUTPUT:

 AAAA                8     9999-12-31     
 CCCC                2     2012-06-16     
 DDDD                3     2018-10-09     
 EEEE                6     2000-02-28 




The above code is ignoring unique key records and processing only dup keys.

But my input file may contain unique and non-unique keys in the input file.
If there are non-unique records, then it should process last dup key along with unique key in the output. So could you please let me know if there is any other way to achieve this.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8794
Location: Welsh Wales

PostPosted: Wed Oct 10, 2018 11:38 am
Reply with quote

Click HERE see if the manuals that you could have read help you.

I found what you want in less than a minute icon_eek.gif
Back to top
View user's profile Send private message
Naveen.katkuri24

New User


Joined: 26 Sep 2013
Posts: 3
Location: India

PostPosted: Wed Oct 10, 2018 12:17 pm
Reply with quote

At last achieved my desired result with the below code.

OPTION EQUALS
SORT FIELDS=COPY
OUTFIL NODETAIL,REMOVECC,
SECTIONS(1,5,TRAILER3=(1,30))


Thanks a lot for your valuable inputs. especially @expat.
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1099
Location: Dublin, Ireland

PostPosted: Wed Oct 10, 2018 1:50 pm
Reply with quote

You didn't try:

Code:
  SELECT FROM(IN) TO(OUT) ON(2,6,PD) LAST


which I think is more readable than the solution you have.

Garry
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


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

PostPosted: Wed Oct 10, 2018 7:02 pm
Reply with quote

Expat, Good one icon_smile.gif

Naveen, You got to open up those links I shared instead to overlook them and get to learn learn by yourself how it works.
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 -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Converting a file from PD to display ... SYNCSORT 4
No new posts Record count of RECFM=U tape file DFSORT/ICETOOL 17
This topic is locked: you cannot edit posts or make replies. Write Character to Hexadecimal file w... COBOL Programming 8
No new posts Checking the total counts inside a re... JCL & VSAM 5
No new posts File-aid batch how to repeat a line... Compuware & Other Tools 2
Search our Forums:

Back to Top