|
View previous topic :: View next topic
|
| Author |
Message |
Chidane
New User
Joined: 25 Nov 2021 Posts: 32 Location: India
|
|
|
|
Hi Team,
I have a requirement as follows.
ID - PIC X(03)
NUM- PIC X(02)
For the same ID key (first 3 char), if there are duplicate entries, I wanted records if the NUM IS > 00. If there is no duplicate, then we need records with 00 num.
| Code: |
ABC10
ABC20
ABC00
DEF00
GHI30
GHI00 |
In this case, for ID - ABC, since there are duplicate entries, we need to write ABC10 and ABC20 discarding ABC00. Since DEF occurs only once, we need that record DEF00 even if NUM is 00. For GHI, we need only GHI30
Output
| Code: |
ABC10
ABC20
DEF00
GHI30
|
I have tried writing sort card as below but not gettign desired output. This will incorrectly remove the record with 00 entry too if it occured once.
| Code: |
SORT FIELDS=(1,5,CH,A)
OMIT COND=(5,2,ZD,EQ,0)
SUM FIELDS=NONE
|
Kindly help. |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2275 Location: USA
|
|
|
|
Please, explain: what is your goal of using
| Code: |
| OMIT COND=(5,2,ZD,EQ,0) |
|
|
| Back to top |
|
 |
Chidane
New User
Joined: 25 Nov 2021 Posts: 32 Location: India
|
|
|
|
Hi Sergeyken,
With the below mentioned code
OMIT COND=(5,2,ZD,EQ,0)
I thought to remvoe the Num value as 00 if duplicate entry of ID comes
But i tested and it didnt work the way I have coded. |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2275 Location: USA
|
|
|
|
How to deal with this?
| Code: |
ABC10
ABC20
ABC20
ABC20
ABC20
ABC20
ABC20
ABC20
ABC00 |
|
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2275 Location: USA
|
|
|
|
| Chidane wrote: |
Hi Sergeyken,
With the below mentioned code
OMIT COND=(5,2,ZD,EQ,0)
I thought to remvoe the Num value as 00 if duplicate entry of ID comes
But i tested and it didnt work the way I have coded. |
Absolutely wrong:
1) the field is out of real data,
2) OMIT/INCLUDE are executed before any other statement in SORT. Its position among other statements doesn't matter (but is often misleading) |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2275 Location: USA
|
|
|
|
| Code: |
//GROUP00 EXEC PGM=SYNCTOOL
//TOOLMSG DD SYSOUT=*
//SSMSG DD SYSOUT=*
//*
//TOOLIN DD *
SORT FROM(SORTIN) TO(SORTF1,COUNTF2) USING(SPLT)
SORT JKFROM TO(SORTOUT) USING(JOIN)
//*
//SORTIN DD *
ABC10
ABC20
ABC20
ABC20
ABC20
ABC20
ABC20
ABC00
DEF00
GHI30
GHI00
KLM00
KLM50
//*
//SORTF1@ DD SYSOUT=*
//SORTF1 DD SPACE=(TRK,(10,10),RLSE)
//*
//COUNTF2@ DD SYSOUT=*
//COUNTF2 DD SPACE=(TRK,(10,10),RLSE)
//*
//SORTOUT DD SYSOUT=*
//*
//SPLTCNTL DD *
* reformat test record to given requirements
SORT FIELDS=(1,5,CH,A)
OUTREC IFTHEN=(WHEN=GROUP,
KEYBEGIN=(1,3),
PUSH=(81:ID=3))
OUTFIL FNAMES=(SORTF1,SORTF1@)
OUTFIL FNAMES=(COUNTF2,COUNTF2@),
REMOVECC,NODETAIL,
SECTIONS=(81,3,
TRAILER3=(81,3,
X,COUNT=(EDIT=(TTT))))
//*
//JOINCNTL DD *
* join and select required records
JOINKEYS F1=SORTF1,
FIELDS=(81,3,A),SORTED
JOINKEYS F2=COUNTF2,
FIELDS=(1,3,A),SORTED
REFORMAT FIELDS=(F1:1,80, =(1,80)
F2:1,7) =(81,3,X,85,3)
INCLUDE COND=(4,2,ZD,NE,+0, NUM not zero?
OR,85,3,ZD,EQ,+1)
SORT FIELDS=(1,5,CH,A)
SUM FIELDS=NONE - to remove full duplicates
OUTFIL FNAMES=(SORTOUT),
BUILD=(1,80)
//* |
| Code: |
********************************* TOP OF DATA ****************************************
ABC00 001
ABC10 001
ABC20 001
ABC20 001
ABC20 001
ABC20 001
ABC20 001
ABC20 001
DEF00 002
GHI00 003
GHI30 003
KLM00 004
KLM50 004
******************************** BOTTOM OF DATA ************************************** |
| Code: |
********************************* TOP OF DATA **********
001 008
002 001
003 002
004 002
******************************** BOTTOM OF DATA ******** |
| Code: |
********************************* TOP OF DATA ************
ABC10
ABC20
DEF00
GHI30
KLM50
******************************** BOTTOM OF DATA ********** |
|
|
| Back to top |
|
 |
Chidane
New User
Joined: 25 Nov 2021 Posts: 32 Location: India
|
|
|
|
Thanks Sergeyken.
Sorry. My bad. I have tried as OMIT COND=(4,2,ZD,EQ,0)
Thanks for the code. I am trying to understand the script that you have mentioned. Whether this is the only way that can be achieved via SORT utility |
|
| Back to top |
|
 |
sergeyken
Senior Member

Joined: 29 Apr 2008 Posts: 2275 Location: USA
|
|
|
|
| Chidane wrote: |
Thanks Sergeyken.
Sorry. My bad. I have tried as OMIT COND=(4,2,ZD,EQ,0)
Thanks for the code. I am trying to understand the script that you have mentioned. Whether this is the only way that can be achieved via SORT utility |
Anyway, it is logically wrong. This OMIT would exclude ALL records with zeroes in that field - at the very beginning, before any other condition can be considered. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|