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
 

 

Syncsort to copy the last occurance of a duplicate

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> SYNCSORT
View previous topic :: :: View next topic  
Author Message
abhi.5873

New User


Joined: 28 Jan 2013
Posts: 8
Location: India

PostPosted: Mon Mar 25, 2013 11:06 am    Post subject: Syncsort to copy the last occurance of a duplicate
Reply with quote

Hi
I have requirement like
File contains
abc 002
bcd 001
cde 004
abc 003
xyz 008

output
abc 003
bcd 001
cde 004
xyz 008

My intenion is to copy all the records in the file and for the duplicates i want the last record of the duplicate occurance record. here the key is first three letters.
I want this by using syncsort commands is it possible?
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Mon Mar 25, 2013 12:51 pm    Post subject: Reply to: Syncsort to copy the last occurance of a duplicate
Reply with quote

SYNCTOOL SELECT with LAST.

EDIT:

Also, please note that SyncSort questions go in the JCL part of the forum.
Back to top
View user's profile Send private message
abhi.5873

New User


Joined: 28 Jan 2013
Posts: 8
Location: India

PostPosted: Mon Mar 25, 2013 2:10 pm    Post subject:
Reply with quote

Is there any way with Sort Program to do this?
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Mon Mar 25, 2013 3:50 pm    Post subject: Reply to: Syncsort to copy the last occurance of a duplicate
Reply with quote

Are you saying you are not allowed to use SYNCTOOL (often "aliased" to ICETOOL), which is part of SyncSort?
Back to top
View user's profile Send private message
abhi.5873

New User


Joined: 28 Jan 2013
Posts: 8
Location: India

PostPosted: Mon Mar 25, 2013 3:52 pm    Post subject:
Reply with quote

Yes....
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Mon Mar 25, 2013 4:05 pm    Post subject: Reply to: Syncsort to copy the last occurance of a duplicate
Reply with quote

You could add a sequence number to each record, then SORT on your key, followed by the sequence-number, descending, do the SUM, and remove the sequence number in OUTREC.

If you don't want to SORT (maybe the file is "big") then either of the two techniques here can be applied to what you want.
Back to top
View user's profile Send private message
bodatrinadh

Active User


Joined: 05 Jan 2007
Posts: 101
Location: chennai (India)

PostPosted: Mon Mar 25, 2013 10:45 pm    Post subject: Reply to: Syncsort to copy the last occurance of a duplicate
Reply with quote

Hi Abhi,

If you have Syncsort 1.4.0R version at your site, you can try this code...
Code:

//STEP01 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT   DD SYSOUT=*
//SORTOUT  DD SYSOUT=*
//SORTIN   DD *
ABC 002
BCD 001
CDE 004
ABC 003
XYZ 008
//SYSIN   DD *
  OPTION EQUALS
  SORT FIELDS=(1,3,CH,A)
  DUPKEYS LASTDUP,NODUPS



Output :-

Code:

ABC 003
BCD 001
CDE 004
XYZ 008


Thanks
-3nadh
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Wed Apr 03, 2013 3:57 am    Post subject: Reply to: Syncsort to copy the last occurance of a duplicate
Reply with quote

-3nadh,

Presumably, as has already been mentioned recently, you have "EQUALS" as your installation option.

However, for solutions which require EQUALS, it would be good to use it explicitly, as not all sites have that as their default (I have added it to your code).

For SyncSort prior to 1.4, you could try this to get the last record of equal keys:

Code:
//STEP0100 EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SYMNAMES DD *
INPUT-RECORD,1,80,CH
INPUT-KEY,=,03,CH
INPUT-REST,*,77,CH
//SYMNOUT DD SYSOUT=*
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *
                                             
  OPTION EQUALS
                                             
                                             
  SORT FIELDS=(INPUT-KEY,A)
                                             
                                             
  OUTFIL  REMOVECC,
          NODETAIL,
          SECTIONS=(INPUT-KEY,
                     TRAILER3=(INPUT-RECORD))
                                             
//SORTIN   DD *
ABC 002
BCD 001
CDE 004
ABC 003
XYZ 008


This one gets the first record of equal keys:
Code:

//STEP0200 EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SYMNAMES DD *
INPUT-RECORD,1,80,CH
INPUT-KEY,=,03,CH
INPUT-REST,*,77,CH
//SYMNOUT DD SYSOUT=*
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *
                                           
  OPTION EQUALS
                                           
                                           
  SORT FIELDS=(INPUT-KEY,A)
                                           
                                           
  OUTFIL  REMOVECC,
          NODETAIL,
          SECTIONS=(INPUT-KEY,
                     HEADER3=(INPUT-RECORD))
                                           
//SORTIN   DD *
ABC 002
BCD 001
CDE 004
ABC 003
XYZ 008



I have left the symbols/SYMNAMES in to leave the code as "generic". For different fixed-length records, simply adjust the length of the record, and the start position (if necessary), and length of the key.

Without the symbols, the code looks like this (for the first):

Code:
 OPTION EQUALS                                         
SORT FIELDS=(1,3,CH,A)                                 
OUTFIL REMOVECC,NODETAIL,SECTIONS=(1,3,TRAILER3=(1,80))
Back to top
View user's profile Send private message
bodatrinadh

Active User


Joined: 05 Jan 2007
Posts: 101
Location: chennai (India)

PostPosted: Wed Apr 03, 2013 4:21 pm    Post subject: Reply to: Syncsort to copy the last occurance of a duplicate
Reply with quote

Thanks Bill for making my code look meaningful.

Also thank you for sharing the code that works on prior version.


Thanks
-3nadh
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 -> SYNCSORT All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts syncsort: copy lines after the keyword shreya19 SYNCSORT 7 Fri Dec 02, 2016 9:47 am
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm
No new posts Syncsort - Hard coded Value in output PORYES SYNCSORT 1 Thu Nov 03, 2016 9:23 am
No new posts Single COPY CICS TS datasets and when... Kyle Carroll CICS 2 Tue Oct 11, 2016 9:47 pm
No new posts Syncsort - NULL in Integer field chec... nartcr SYNCSORT 4 Thu Oct 06, 2016 6:47 am


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