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 

Combine Different Records with Sort

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


Joined: 17 Aug 2004
Posts: 25
Topics: 14

PostPosted: Wed May 04, 2005 2:45 am    Post subject: Combine Different Records with Sort Reply with quote

Hi,
I have an input file, which will have different types of records. Each record type is identified from 1st Digit of the record. Record types can be 'A','F','E' and 'B'. First A - Type record will come, followed by F & E and ends with B type. There is no specific sequence followed by F & E type records. But, A bunch of records start with record type A and end with Record type B .

I want to combine some fields in Record Type A and Record Type B. Is it possible through Sort(even by E35 Exit).
Here is the sample Input file and expected out put.
INPUT FILE
Code:

AXY1
F123
F123
E123
F123
BPQ1
AXY2
BPQ2
AXY3
F123
BPQ3

Expected OUTPUT FILE
Code:

XY1PQ1
XY2PQ2
XY3PQ3


Thanks
Siva
Back to top
View user's profile Send private message AIM Address  
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Wed May 04, 2005 5:06 am    Post subject: Reply with quote

Siva Kumar Sunku,


Please post the LRECL, RECFM and positions of the fields to be combined

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website  
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


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

PostPosted: Wed May 04, 2005 10:09 am    Post subject: Reply with quote

Siva,

Are you pairing up the A and B records based on a common key in the records (e.g. position 4 in your example above), or based on their location in the file (e.g. first A record and first B record, second A record and second B record, etc)?
_________________
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  
Siva Kumar Sunku
Beginner


Joined: 17 Aug 2004
Posts: 25
Topics: 14

PostPosted: Wed May 04, 2005 7:48 pm    Post subject: Reply with quote

Hi Kolusu/Frank,

LRECL = 80
RECFM = FB

There is no common key between the type of records. What I know is I will get 'A' type record first and 'B' type record last. Intermediate record types I need to ignore.

Thanks
Siva.
Back to top
View user's profile Send private message AIM Address  
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


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

PostPosted: Thu May 05, 2005 4:31 am    Post subject: Reply with quote

Siva,

The following job will solve your requirement.

Code:

//R010     EXEC  PGM=SYNCTOOL                 
//TOOLMSG  DD  SYSOUT=*                       
//DFSMSG   DD  SYSOUT=*                       
//INPUT    DD  *                               
AXY1                                           
F123                                           
F123                                           
E123                                           
F123                                           
BPQ1                                           
AXY2                                           
BPQ2                                           
AXY3                                           
F123                                           
BPQ3                                           
/*                                             
//TEMPFILE DD  DSN=&&TEMP1,DISP=(,PASS)       
//OUTPUT   DD  SYSOUT=*                       
//SYSOUT   DD  SYSOUT=*                       
//TOOLIN   DD  *                                             
  COPY FROM(INPUT) TO(TEMPFILE) USING(CTL1)                   
  SORT FROM(TEMPFILE) TO(OUTPUT) USING(CTL2)                 
/*                                                           
//CTL1CNTL DD  *                                             
  INCLUDE COND=(1,1,SS,EQ,C'A,B')                             
  INREC FIELDS=(1,4,10:X,SEQNUM,4,ZD,START=0)                 
  OUTREC FIELDS=(1,1,                                         
                 1,1,CHANGE=(3,C'B',X'000000'),NOMATCH=(2,3),
                 1Z,                                         
                 1,1,CHANGE=(3,C'A',X'000000'),NOMATCH=(2,3),
                 1Z,                                         
                 40:X,11,4,ZD,DIV,+2,EDIT=(TTTT))             
/*                                                           
//CTL2CNTL DD  *                                             
  SORT FIELDS=(41,4,ZD,A)                                     
  SUM FIELDS=(6,4,BI)                                         
  OUTREC FIELDS=(2,3,6,3,40:X)                               
/*                                                           


Change the PGM name to ICETOOL if you have DFSORT in your shop.

Brief Desc:
1. The first COPY operator creates a temporary file like this,
Code:

AXY1                                    0000   
B    PQ1                                0000   
AXY2                                    0001   
B    PQ2                                0001   
AXY3                                    0002   
B    PQ3                                0002   


2. The second SORT operator sorts the records on the sequence number, thus grouping each A-B pair and then performs a BINARY summation on the field in B-RECORD which merges the two records together.

Let me know if you need more information on the logic.

Thanks,
Phantom
Back to top
View user's profile Send private message  
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Thu May 05, 2005 5:51 am    Post subject: Reply with quote

Siva,

Check this link which discusses similar requirement

http://mvsforums.com/helpboards/viewtopic.php?t=10&highlight=lateral

Phantom,

Wouldn't it be easier to split the file into 2 temp files instead of going for the complicated logic of division?

Code:

//T1       DD DSN=&T1,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//T2       DD DSN=&T2,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)
//CON      DD DSN=&T1,DISP=OLD,VOL=REF=*.T1             
//         DD DSN=&T2,DISP=OLD,VOL=REF=*.T2             
//OUT      DD SYSOUT=*                                   
//TOOLIN   DD *                                         
  COPY FROM(IN)  USING(CTL1)                             
  SORT FROM(CON) USING(CTL2)                             
//CTL1CNTL DD *                                         
  INCLUDE COND=(1,1,SS,EQ,C'AB')                         
  OUTFIL FNAMES=T1,INCLUDE=(1,1,CH,EQ,C'A'),             
  OUTREC=(2,3,4Z,SEQNUM,8,ZD)                           
  OUTFIL FNAMES=T2,INCLUDE=(1,1,CH,EQ,C'B'),             
  OUTREC=(3Z,2,3,Z,SEQNUM,8,ZD)                         
//CTL2CNTL DD *                                         
  SORT FIELDS=(8,8,CH,A)                                 
  SUM FIELDS=(3,4,BI)                                   
  OUTFIL FNAMES=OUT,                                     
  OUTREC=(1,6)                                           
/*                                                       


Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website  
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


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

PostPosted: Thu May 05, 2005 6:00 am    Post subject: Reply with quote

Yes Kolusu you are correct.

It would be much simpler if the data is divided across two datasets. Frankly speaking, I didn't think of that option at all.

Just an after-effect of the series of "Sort Challenges" (to accomplish the result using min. number of steps / datasets) that we were having some time back !!! Wink

Cheers,
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: Thu May 05, 2005 11:49 am    Post subject: Reply with quote

Or you could use DFSORT's new IFTHEN parameter with a similar technique to do it in one pass as follows:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
AXY1
F123
F123
E123
F123
BPQ1
AXY2
BPQ2
AXY3
F123
BPQ3
//SORTOUT  DD SYSOUT=*
//SYSIN    DD    *
 INCLUDE COND=(1,1,SS,EQ,C'A,B')
 INREC IFTHEN=(WHEN=(1,1,CH,EQ,C'A'),BUILD=(2,3,4:4Z,8:SEQNUM,8,ZD)),
   IFTHEN=(WHEN=(1,1,CH,EQ,C'B'),BUILD=(3Z,4:2,3,7:Z,8:SEQNUM,8,ZD))
 OPTION EQUALS
 SORT FIELDS=(8,8,BI,A)
 SUM FIELDS=(3,4,BI)
 OUTREC FIELDS=(1,6)
/*


_________________
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  
Siva Kumar Sunku
Beginner


Joined: 17 Aug 2004
Posts: 25
Topics: 14

PostPosted: Thu May 05, 2005 8:53 pm    Post subject: Reply with quote

Hi Kolusu/Phantom/Frank,

Thanks for the support.

Thanks
Siva
Back to top
View user's profile Send private message AIM Address  
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