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

Syncsort to copy the last occurance of a duplicate


IBM Mainframe Forums -> SYNCSORT
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Mon Mar 25, 2013 12:51 pm
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
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

Moderator Emeritus


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

PostPosted: Mon Mar 25, 2013 3:50 pm
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
Reply with quote

Yes....
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: Mon Mar 25, 2013 4:05 pm
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
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

Moderator Emeritus


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

PostPosted: Wed Apr 03, 2013 3:57 am
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts Duplicate transid's declared using CEDA CICS 3
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts VB to VB copy - Full length reached SYNCSORT 8
No new posts Need COBOL COPY Help in MVS Environment COBOL Programming 4
No new posts Duplicate several members of/in one l... JCL & VSAM 7
Search our Forums:

Back to Top