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

To Discard record with 0 entry if Duplicate is there


IBM Mainframe Forums -> SYNCSORT
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Chidane

New User


Joined: 25 Nov 2021
Posts: 32
Location: India

PostPosted: Thu Dec 18, 2025 3:52 pm
Reply with quote

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
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2275
Location: USA

PostPosted: Thu Dec 18, 2025 6:19 pm
Reply with quote

Please, explain: what is your goal of using
Code:
OMIT COND=(5,2,ZD,EQ,0)
Back to top
View user's profile Send private message
Chidane

New User


Joined: 25 Nov 2021
Posts: 32
Location: India

PostPosted: Thu Dec 18, 2025 9:28 pm
Reply with quote

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
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2275
Location: USA

PostPosted: Thu Dec 18, 2025 11:20 pm
Reply with quote

How to deal with this?
Code:
ABC10
ABC20
ABC20
ABC20
ABC20
ABC20
ABC20
ABC20
ABC00
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2275
Location: USA

PostPosted: Thu Dec 18, 2025 11:24 pm
Reply with quote

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
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2275
Location: USA

PostPosted: Thu Dec 18, 2025 11:35 pm
Reply with quote

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
View user's profile Send private message
Chidane

New User


Joined: 25 Nov 2021
Posts: 32
Location: India

PostPosted: Fri Dec 19, 2025 11:08 am
Reply with quote

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
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2275
Location: USA

PostPosted: Fri Dec 19, 2025 6:29 pm
Reply with quote

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
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts To Populate Trailer cnt in the file w... SYNCSORT 1
No new posts Write record twice based on condition... SYNCSORT 7
No new posts Create a specific record/file based o... SYNCSORT 8
No new posts Sort to insert record in an empty file. DFSORT/ICETOOL 5
No new posts Create a FTP record with help of SYNC... SYNCSORT 3
Search our Forums:


Back to Top