MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Merging records in one record

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
coolguy
Beginner


Joined: 01 Dec 2004
Posts: 82
Topics: 28

PostPosted: Tue Jun 21, 2005 3:21 am    Post subject: Merging records in one record Reply with quote

Hi

I have a I/Pfile
1234 NNY
1234 NYN
1234 YNN
1235 NNY
1235 YNN
I want the out put file

O/P File
1234 YYY
1235 YNY

Can we do it in Sort pls help me?

Thanks
CooL
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Tue Jun 21, 2005 4:39 am    Post subject: Reply with quote

coolguy,

I think similar questions are already posted in this forum. Anyway, here is my solution.

Code:

//R010   EXEC  PGM=SORT                           
//SORTIN   DD  *                                 
1234 NNY                                         
1234 NYN                                         
1234 YNN                                         
1235 NNY                                         
1235 YNN                                         
1236 NYY                                         
1236 YNN                                         
1236 YYN                                         
1236 YNN                                         
/*                                               
//SORTOUT  DD  SYSOUT=*                           
//SYSOUT   DD  SYSOUT=*                           
//SYSIN    DD  *                                 
  INREC FIELDS=(1,5,6,1,CHANGE=(1,C'N',C'0'),     
                       NOMATCH=(C'1'),           
                    7,1,CHANGE=(1,C'N',C'0'),     
                       NOMATCH=(C'1'),           
                    8,1,CHANGE=(1,C'N',C'0'),     
                       NOMATCH=(C'1'))           
  SORT FIELDS=(1,4,CH,A)                         
  SUM FIELDS=(6,3,ZD)                           
  OUTREC FIELDS=(1,5,6,1,CHANGE=(1,C'0',C'N'),   
                        NOMATCH=(C'Y'),         
                     7,1,CHANGE=(1,C'0',C'N'),   
                        NOMATCH=(C'Y'),         
                     8,1,CHANGE=(1,C'0',C'N'),   
                        NOMATCH=(C'Y'))         
/*                                               


The code is simple.

1. In the input record, I changed all 'N's to '0's and all 'Y's to '1's using INREC.
2. Sort the record on the key field 1st four characters so that the records get grouped on the key field.
3. Sum on the numbers - Col 6 thru 8.
If there are multiple occurences of Y in any column for a given key, they would add up and result in a value of more than 1.
4. In outrec, I change all zeroes back to 'N' and any value other than zero to 'Y'.

Note:
This solution will not work if the number of 'Y's in a column for a given key exceeds 9 occurences.

Hope this helps,

Thanks,
Phantom
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Tue Jun 21, 2005 10:06 am    Post subject: Reply with quote

Here's a DFSORT solution that will work regardless of the number of Y's in a column:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
1234 NNY
1234 NYN
1234 YNN
1235 NNY
1235 YNN
1236 NYY
1236 YNN
1236 YYN
1236 YNN
1237 NNN
1237 NNN
1238 NNN
1238 YNN
1239 NYN
1239 YNN
/*
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:15C'0')),
     IFTHEN=(WHEN=(6,1,CH,EQ,C'Y'),OVERLAY=(81:C'00001'),HIT=NEXT),
     IFTHEN=(WHEN=(7,1,CH,EQ,C'Y'),OVERLAY=(86:C'00001'),HIT=NEXT),
     IFTHEN=(WHEN=(8,1,CH,EQ,C'Y'),OVERLAY=(91:C'00001'))
  SORT FIELDS=(1,4,CH,A)
  SUM FORMAT=ZD,FIELDS=(81,5,86,5,91,5)
  OUTREC IFOUTLEN=80,
     IFTHEN=(WHEN=INIT,OVERLAY=(6:C'NNN')),
     IFTHEN=(WHEN=(81,5,ZD,GT,+0),OVERLAY=(6:C'Y'),HIT=NEXT),
     IFTHEN=(WHEN=(86,5,ZD,GT,+0),OVERLAY=(7:C'Y'),HIT=NEXT),
     IFTHEN=(WHEN=(91,5,ZD,GT,+0),OVERLAY=(8:C'Y'))
/*

_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
coolguy
Beginner


Joined: 01 Dec 2004
Posts: 82
Topics: 28

PostPosted: Wed Jun 22, 2005 5:47 am    Post subject: Reply with quote

Thanks a lot

Cool
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group