Posted: Tue Oct 11, 2005 2:33 am Post subject: Getting first occurence of the record using SYNCSORT.
Hi,
I need only records with "STD" or "REF" at position 6. This can be done by INCLUDE, but for "REF" records I need only the first occurence. Can this be done by SEQNUM ?? Can I reset the SEQNUM in SYNCSORT ??
Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
Posted: Tue Oct 11, 2005 3:15 am Post subject:
krkcs,
Quote:
Can I reset the SEQNUM in SYNCSORT ??
The answer is "Yes" & "No". Yes - If you have latest version of syncsort (v 1.1 or 1.2). No - if not.
Quote:
I need only records with "STD" or "REF" at position 6. This can be done by INCLUDE, but for "REF" records I need only the first occurence.
From your statement, I understand that you need all occurrences of STD but only one occurrence of REF. Correct me if I am wrong.
This being the case and if you are not concerned with the order of records in the output file then the following SORT should get you desired results.
I'm assuming that your SORTIN is of RECFM=FB & LRECL=80.
Code:
//R010 EXEC PGM=SORT
//SORTIN DD *
AABHYSTDPERE
BAMQHSTDPERE
BAMQHREFOPER
BAMQHREFUPER
BAMQHSTDPERE
BBCBKREFUPER
BBCBKREFUPEF
BBCBZREFFERE
BBCBZREFR342
/*
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
OPTION EQUALS
INCLUDE COND=(6,3,SS,EQ,C'STD,REF') * INCLUDE ONLY STD & REF *
INREC FIELDS=(1,80, * COPY INPUT DATA *
6,3,CHANGE=(1,C'REF',C'0'), * CHANGE REF TO '0' *
NOMATCH=(C'1')) * ALL OTHERS TO '1' *
SORT FIELDS=(81,1,ZD,A) * SORT ON CONSTANT @ 81 *
OUTREC FIELDS=(1,81,SEQNUM,8,ZD) * INCLUDE SEQNUM @ 82-89 *
OUTFIL INCLUDE=((6,3,CH,EQ,C'REF',AND,82,8,ZD,EQ,1),OR,
6,3,CH,EQ,C'STD')
/*
Description:
Code:
1. Include only records with STD & REF @ column 6 (INCLUDE COND)
2. Insert a constant character at Position 81 depending on the value in column 6-8.
a. For 'REF' insert '0' @ pos 81
b. For 'STD' insert '1'
3. Sort on this constant char so that REFs comes first followed by STDs.
4. Using OUTREC, include SEQNUM @ position 82-89. Now first record (which is a REF) will have seqnum 00000001.
5. Using OUTFIL INCLUDE, for REFs include only one record which has seqnum 1 and for STDs include everything.
Phantom,
Where are we resetting the SEQNUM here ?? I think we should reset the SEQNUM counter whenever it encounters the new data at pos-1, len-5. Huh..am I making some point _________________ -kr
Yes Phantom. The first five characters of my input file is the Key for which there should be only a single "REF". I have two "REF" in my output, this is because I need only first occurence of "REF" record, for each and every unique key.
I should have been more clear with my question... _________________ -kr
Phantom,
In this post, Kolusu has given solution using ICETOOL, will it be working for SYNCSORT too ?? Anyway I'm checking it...thanks for the info. Phantom ! _________________ -kr
Pass 1:
1. Include a 8 digit sequence number at pos 82-89.
2. Reset this seqnum to ZEROES for records which have REF @ pos 6.
Pass 2:
1. Sort on key + REF/STD + Seqnum
2. Eliminate duplicates. Now that seqnum is ZEROES for all REF records irrespective of key, duplicate are ignored (Note: Since Key is part of the SORT criteria, one REF per key is maintained).
3. None of the duplicate STDs are rejected since their SEQNUM are always different.
Does this solve your requirement ?
Also, With the new code, I got 3 REFs in the output.
Code:
********************************* TOP OF D
AABHYSTDPERE
BAMQHREFOPER
BAMQHSTDPERE
BAMQHSTDPERE
BBCBKREFUPER
BBCBZREFFERE
******************************** BOTTOM OF
Thanks,
Phantom
Last edited by Phantom on Tue Oct 11, 2005 4:59 am; edited 1 time in total
I need all the STD records for all the keys(key is 1 to 5 bytes) but REF records only the first occurence of the key.
Code:
AABHYSTDPERE - This should be written to output (since it's STD)
BAMQHSTDPERE - This should be written to output (since it's STD)
BAMQHREFOPER - Since this is the first occurence of BAMQH with REF, this should be written
BAMQHREFUPER - Omit
BAMQHSTDPERE - This should be written to output (since it's STD)
BBCBKREFUPER - Since this is the first occurence of BBCBK with REF, this should be written
BBCBKREFUPEF - Omit
BBCBZREFFERE - Since this is the first occurence of BBCBZ with REF, this should be written
BBCBZREFR342 - Omit
Hope I'm bit more clear now..!! _________________ -kr
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum