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

How to remove duplicates on some conditions


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ram prasad

New User


Joined: 28 May 2007
Posts: 17
Location: india

PostPosted: Wed Jan 27, 2010 10:28 pm
Reply with quote

I have a requirement to remove duplicates from the input file.

The input file has 2 variables, Account and Action.
The sample input is as follows:

Acct1 Action1
Acct1 spaces
Acct1 Action1
Acct2 spaces -- For account 2
Acct2 spaces -- 2 records with no action
Acct3 Action3a -- For account 3
Acct3 Action3b -- 2 records with different actions
Acct4 Action4
Acct5 spaces

Conditions are:

1)If there is a duplicate account in the file (one with Action info and another without Action info), the record with Action info is extracted. (Acct1 in the above example)

2)If there is a duplicate account, and both record do not have Action info, then only one record is extracted.(Acct 2 in the above example)

3) If there are duplicate records on account key and they have diffrerent actions, then both the records should be extracted. (Acct 3 in the above example)


The expected output is:
Acct1 Action1
Acct2 spaces
Acct3 Action3a
Acct3 Action3b
Acct4 Action4
Acct5 spaces

There is a possibility of more records for each account with same or different Action.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Jan 27, 2010 11:27 pm
Reply with quote

Hi Ram Prasad,
if sequence of actions within account is not a matter then below solution will work for you.
Code:

//STEP0010 EXEC PGM=SORT                                           
//SYSOUT   DD SYSOUT=*                                             
//SORTIN   DD *                                                     
ACCT1 ACTION1                                                       
ACCT1                                                               
ACCT1 ACTION1                                                       
ACCT2                                                               
ACCT2                                                               
ACCT3 ACTION3A                                                     
ACCT3 ACTION3B                                                     
ACCT4 ACTION4                                                       
ACCT5                                                               
//SORTOUT  DD SYSOUT=*                                             
//SYSIN    DD *                                                     
  SORT FIELDS=(1,5,CH,A,7,8,CH,D)                                   
  SUM FIELDS=NONE                                                   
  OUTREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,5))) 
  OUTFIL OMIT=(81,8,ZD,GT,1,AND,7,8,CH,EQ,C' ')             
/*                                                         


Output will be
Code:

ACCT1 ACTION1
ACCT2         
ACCT3 ACTION3B
ACCT3 ACTION3A
ACCT4 ACTION4
ACCT5         
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Jan 27, 2010 11:43 pm
Reply with quote

Sorry no need of ifthen actually
Code:

//SYSIN    DD *                                       
  SORT FIELDS=(1,5,CH,A,7,8,CH,D)                     
  SUM FIELDS=NONE                                     
  OUTREC OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,5))       
  OUTFIL OMIT=(81,8,ZD,GT,1,AND,7,8,CH,EQ,C' ')       
/*                                                     
Back to top
View user's profile Send private message
ram prasad

New User


Joined: 28 May 2007
Posts: 17
Location: india

PostPosted: Thu Jan 28, 2010 12:26 am
Reply with quote

Thank you so much Sambhaji..
Its working perfectly..
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts How to load to DB2 with column level ... DB2 6
No new posts Remove leading zeroes SYNCSORT 4
No new posts Db2 SQL - how to switch among differe... DB2 18
No new posts To search DB2 table based on Conditio... DB2 1
Search our Forums:

Back to Top