|
View previous topic :: View next topic
|
| Author |
Message |
abhi.5873
New User
Joined: 28 Jan 2013 Posts: 8 Location: India
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
SYNCTOOL SELECT with LAST.
EDIT:
Also, please note that SyncSort questions go in the JCL part of the forum. |
|
| Back to top |
|
 |
abhi.5873
New User
Joined: 28 Jan 2013 Posts: 8 Location: India
|
|
|
|
| Is there any way with Sort Program to do this? |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| Are you saying you are not allowed to use SYNCTOOL (often "aliased" to ICETOOL), which is part of SyncSort? |
|
| Back to top |
|
 |
abhi.5873
New User
Joined: 28 Jan 2013 Posts: 8 Location: India
|
|
|
|
| Yes.... |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
bodatrinadh
Active User

Joined: 05 Jan 2007 Posts: 101 Location: chennai (India)
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
-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 |
|
 |
bodatrinadh
Active User

Joined: 05 Jan 2007 Posts: 101 Location: chennai (India)
|
|
|
|
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 |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|