Page 1 of 1

How to pick the last record if all the records are same

PostPosted: Tue Mar 29, 2016 10:58 pm
by pgkkreddy1
Hi All,
Good evening.
I have 3 records with same values in file and I want to pick last record in the file. Setting the sequence num is one way, is there any other way to do this. Please suggest

Records in file are like below
05 3333 1604 N
05 3333 1604 Y
05 3333 1604

I am sorting based on only first 3 fields .

Regards,
kk

Re: How to pick the last record if all the records are same

PostPosted: Wed Mar 30, 2016 11:33 am
by Aki88
Hello,

pgkkreddy1 wrote:I am sorting based on only first 3 fields .

Check the SUBSET operator of ICETOOL, it has various functions which can be used to achieve what you're looking for.
Since you're SORTing the data on first three bytes, hence the added SORT statement:

//TESTRUN  EXEC PGM=ICETOOL                          
//TOOLMSG  DD SYSOUT=*                                
//DFSMSG   DD SYSOUT=*                                
//IN       DD *                                      
05 3333 1604 N                                        
05 3333 1604 Y                                        
05 3333 1604                                          
/*                                                    
//OUT      DD SYSOUT=*                                
//TOOLIN   DD *                                      
 SUBSET FROM(IN) TO(OUT) KEEP OUTPUT LAST USING(CTL1)
/*                                                    
//CTL1CNTL DD *                                      
 SORT FIELDS=(1,3,CH,A)                              
/*                                                    

Output:


05 3333 1604
 


Hth.

Re: How to pick the last record if all the records are same

PostPosted: Wed Mar 30, 2016 11:55 am
by BillyBoyo
Your editor?

Why do you want to SORT three records with the same key? Do you want to keep them in the original input sequence, or whatever the output from SORT gives you?

SUBSET can be used for this, SELECT can be used for this (and can operate on keys), OUTFIL reporting features can be used for this (REMOVECC, NODETAIL, SECTIONS with TRAILER3).

However, why not your editor?

Explain more, please.

Re: How to pick the last record if all the records are same

PostPosted: Wed Mar 30, 2016 3:35 pm
by pgkkreddy1
Thanks very much for reply.
My requirement is to load the latest record. Based on those fields. i.e from input file last dup record. Input file I can't edit it is from some other source.

Actually I kept sequence for all the records
sort all three fields in ascending order and sequence number in descending order.
so last dup record comes to first. Then I used sort xsum and first record pick in the out file.

once again thank you

Regards,
kk

Re: How to pick the last record if all the records are same

PostPosted: Wed Mar 30, 2016 4:18 pm
by BillyBoyo
For three records, I suppose it doesn't matter much, but that's not an effective general way to do it.

XSUM means you are using SyncSORT, so topic moved to the correct part of the forum.

Re: How to pick the last record if all the records are same

PostPosted: Fri Apr 08, 2016 8:03 am
by c62ap90
I did not try it out but maybe...
//SYSIN DD *
SORT FIELDS=(1,3,CH,A)
DUPKEYS LASTDUP,NODUPS

Re: How to pick the last record if all the records are same

PostPosted: Fri Apr 08, 2016 12:01 pm
by BillyBoyo
Yeah, 'cept the data is already in sequence. Why SORT it again?