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 

Sorting Detail records
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Nov 09, 2004 11:55 am    Post subject: Reply with quote

nguyenh,

Let me put your requirement in simple terms.

Code:

col 1- 38       col 39-44       col 77 - 78
****************header rec1*****************
detail rec 3     key400            cc
detail rec 2     key100            aa
....
****************header rec2*****************
detail rec 1     key300            cc
detail rec 5     key200            aa
....



Now

1. you just want 1 header record
2. sort all the detail records on col 39 -44 and col 77- 78
3. you want to append the columns 39 thru at the end of each record

sample output

Code:

****************one header*****************
detail rec 2     key100            aa           key100
detail rec 5     key200            aa           key200
detail rec 1     key300            cc           key300
detail rec 3     key400            cc           key400


Is this what you wanted ?

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


Joined: 09 Mar 2004
Posts: 52
Topics: 6

PostPosted: Tue Nov 09, 2004 2:05 pm    Post subject: Reply with quote

Kolusu,
Here is exactly what it should be:

Code:

col 1- 38                          39-44       77 - 78
****************header key001********
detail rec 3                                        cc
detail rec 2                                        aa
....
****************header key002********
detail rec 1                                        cc
detail rec 5                                        aa
....



Quote:

1. you just want 1 header record (Yes! the first one only)
2. sort all the detail records on col 39 -44 and col 77- 78 (Yes!)
3. you want to append the columns 39 thru 44 at the end of each record (Yes!)



Here is sample output:

Code:

col 1- 38                          39-44     77-78  81-82
****************header key001*****************
detail rec 2                                        aa  key001
detail rec 3                                        cc   key001
....
detail rec 5                                        aa  key002
detail rec 1                                        cc   key002
...


Thank you very much for your helps!
nguyenhh
Back to top
View user's profile Send private message
nguyenh
Beginner


Joined: 09 Mar 2004
Posts: 52
Topics: 6

PostPosted: Tue Nov 09, 2004 2:10 pm    Post subject: Reply with quote

Oop! I messed them up.

Code:

col 1- 38       39-44       77-78
****************key001*************
detail rec 3                   cc
detail rec 2                   aa
....
****************key002*************
detail rec 1                   cc
detail rec 5                   aa
...


Code:

col 1- 38        39-44     77-78 81-82
****************key001*****************
detail rec 2               aa    key001
detail rec 3               cc    key001
....
detail rec 5               aa    key002
detail rec 1               cc    key002
Back to top
View user's profile Send private message
nguyenh
Beginner


Joined: 09 Mar 2004
Posts: 52
Topics: 6

PostPosted: Tue Nov 09, 2004 2:12 pm    Post subject: Reply with quote

Sorry,
it's 81- 86 , not 81-82
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Nov 09, 2004 3:29 pm    Post subject: Reply with quote

nguyenh,

The following DFSORT/ICETOOL JCL will give you the desired results. If you have syncsort at your shop then change the pgm name to synctool. However you need the latest version of syncsort to run this jcl which supports the splice parameter.

A brief explanation of the job. I assumed that your header record is identified by * in the 1st byte. I also assumed that your detail record is key the first 12 bytes.

The first copy operator splits the file into 2 files, namely HDR and detail. we first a seqnum of 8 bytes of ZD format to records using INREC fields.

Using OUTFIL we split the records into 2 HDR and DET files. On the header record we zero out the seqnum and start new seqnum of 8 bytes of ZD format from 89th byte. We also add an indicator 'H' and copy the contents from 39 thru 44.

All the detail records are copied into DET file. we add an indicator of "z" to all the detail records.

The next SORT operator concatenates the above created HDR & DET files and using INREC we perform the tagging the record no: to all the detail records.

We now sort on the tagno and the indicator and the detail records key( 1 thru 12)

By doing so the detail records are sorted within each header.

We take the output from the sort step and use splice operator to splice the header name at the end of every detail record.

Code:

//STEP0100 EXEC PGM=ICETOOL                                 
//DFSMSG   DD SYSOUT=*                                       
//TOOLMSG  DD SYSOUT=*                                       
//IN       DD DSN=YOUR INPUT FILE,
//            DISP=SHR                                       
//HDR      DD DSN=&HDR,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)   
//DET      DD DSN=&DET,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)   
//CON      DD DSN=*.HDR,VOL=REF=*.HDR,DISP=OLD               
//         DD DSN=*.DET,VOL=REF=*.DET,DISP=OLD               
//T3       DD DSN=&T3,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)   
//OUT      DD SYSOUT=*                                       
//TOOLIN   DD *                                               
   COPY FROM(IN)  USING(CTL1)                                 
   SORT FROM(CON) USING(CTL2)                                 
   SPLICE FROM(T3) TO(OUT) -                                 
           ON(87,8,CH) -                                     
           WITH(1,80) -                                       
           WITHALL  USING(CTL3)                               
//CTL1CNTL DD *                                               
   INREC  FIELDS=(1,80,SEQNUM,8,ZD)                           
   OUTFIL FNAMES=HDR,INCLUDE=(1,1,CH,EQ,C'*'),               
   OUTREC=(1,80,8C'0',SEQNUM,8,ZD,C'H',39,6)                 
   OUTFIL FNAMES=DET,SAVE,                                   
   OUTREC=(1,88,SEQNUM,8,ZD,C'Z',6X)                         
//CTL2CNTL DD *                                               
  OPTION EQUALS                                               
  INREC  FIELDS=(1,96,(81,8,ZD,SUB,89,8,ZD),M11,LENGTH=8,97,7)
  SORT   FIELDS=(97,8,ZD,A,105,1,CH,A,1,12,CH,A)             
  OUTFIL FNAMES=T3,OUTREC=(1,80,106,6,97,8)                   
//CTL3CNTL DD *                                               
  OUTFIL FNAMES=OUT,OUTREC=(1,86)                 
/*


Hope this helps...

Cheers

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


Joined: 09 Mar 2004
Posts: 52
Topics: 6

PostPosted: Wed Nov 10, 2004 11:42 am    Post subject: Reply with quote

Kolusu,
Thank you so much for your helps. The code works perfect for current requirements, however there are more functionalities that I want it to do. but
at the moment I am still trying to understand what the code is doing.
I will come back with more questions. I hope you dont mind. I really appreciate for your helps!

Big Thanks!
nguyenh
Back to top
View user's profile Send private message
nguyenh
Beginner


Joined: 09 Mar 2004
Posts: 52
Topics: 6

PostPosted: Thu Nov 11, 2004 1:51 pm    Post subject: help me understand this code Reply with quote

Kolusu,
Could you please help me understand what each of these parameters in this code does, and what the output records will look like after execute it ?

Code:
             
   OUTREC=(1,80,8C'0',SEQNUM,8,ZD,C'H',39,6)                 
   OUTFIL FNAMES=DET,SAVE,                                   
   OUTREC=(1,88,SEQNUM,8,ZD,C'Z',6X)                         


Thank you!
nguyenh
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Nov 11, 2004 2:12 pm    Post subject: Reply with quote

nguyenh,


Code:

OUTREC=(1,80,          $ Copy 80 bytes from pos1 of input
        8C'0',         $ pad 8 zeroes 
        SEQNUM,8,ZD,   $ seqnum( record #)
        C'H',          $ char of 'h'
        39,6)          $ Copy 6 bytes from pos 39 of input       

   OUTFIL FNAMES=DET,SAVE,                                     
   OUTREC=(1,88,          $ Copy 88 bytes from pos 1 of inrec
           SEQNUM,8,ZD,   $ seqnum( record #)
           C'Z',          $ char of 'z'
           6X)            $ pad 6 spaces.


option SAVE operates in a global fashion over all of the other OUTFIL statements for which SAVE is not specified, enabling you to keep any OUTFIL input records that would not be kept otherwise. SAVE will include the same records for each group for which it is specified.

In simple terms it is acts like the ELSE part of IF condition.

Code:

 IF COND = 'A' OR 'B' OR 'C'
    PUT OUTPUT1
 ELSE
   PUT OUTPUT2
 END-IF


Hope this helps...

Cheers

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


Joined: 09 Mar 2004
Posts: 52
Topics: 6

PostPosted: Wed Nov 17, 2004 5:20 pm    Post subject: Reply with quote

Thanks Kolusu,
Here is my next question, by looking at the code below:
is it possible to do something like this, if so could you please show me how.

Code:

//CTL2CNTL DD *
  OPTION EQUALS
  INREC  FIELDS=(1,96,(81,8,ZD,SUB,89,8,ZD),M11,LENGTH=8,97,7)
  SORT   FIELDS=(97,8,ZD,A,1,9,CH,A,105,1,CH,A,1,12,CH,A)
  OUTFIL FNAMES=T3,OUTREC=(1,80,106,6,97,8)
//CTL3CNTL DD *
  OUTFIL FNAMES=OPFILE,OUTREC=(1,86)
/*

If INREC FIELDS 1-1 is not blank and/or ....
   SORT   FIELDS=(97,8,ZD,A,1,9,CH,A,105,1,CH,A,1,12,CH,A)
ElseIf INREC FIELDS 1-1 is blank  and/or INREC FIELDS 77-78 is "CA"  and/or .....
   SORT   FIELDS=(97,8,ZD,A,105,1,CH,A,1,12,CH,A)
Else  SORT  FIELDS=(97,8,ZD,A,105,1,CH,A,1,12,CH,A............)


If this is not the way we do thing, then or is there another way?

Thank you very much for your helps!
nguyenh
Back to top
View user's profile Send private message
nguyenh
Beginner


Joined: 09 Mar 2004
Posts: 52
Topics: 6

PostPosted: Tue Dec 07, 2004 3:57 pm    Post subject: Reply with quote

Code:

//CTL2CNTL DD *                                               
  OPTION EQUALS                                               
  INREC  FIELDS=(1,96,(81,8,ZD,SUB,89,8,ZD),M11,LENGTH=8,97,7)
  SORT   FIELDS=(97,8,ZD,A,105,1,CH,A,1,12,CH,A)             
  OUTFIL FNAMES=T3,OUTREC=(1,80,106,6,97,8)                   
//CTL3CNTL DD *                                               
  OUTFIL FNAMES=OUT,OUTREC=(1,86)                 
/*

Sorry it's me again. Could someone please help me understand the above lines:
or please show me a link to the document that helps me understand this.

Thank you!
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Dec 07, 2004 4:21 pm    Post subject: Reply with quote

nguyenh,

OPTION EQUALS| NOEQUALS : Determines whether or not the sort will preserve the order of records with identical sort fields. NOEQUALS is the default, and causes equal-keyed records to be written in a random order,not in the order they were encountered.

Code:

  INREC  FIELDS=(1,96,(81,8,ZD,SUB,89,8,ZD),M11,LENGTH=8,97,7)


1,96 means copy the contents from byte 1 for a length of 96

(81,8,ZD,SUB,89,8,ZD),M11,LENGTH=8 means subtract the contents at 81 for 8 bytes from contents at 89 for 8 bytes and write out the result in the format TTTTTTTT ( no zero suppression as 9(08 ) in cobol)

97,7 means means copy the contents from byte 97 for a length of 7

Code:

Sort fields=(97,8,ZD,A,   $ sort on 8 bytes starting at 97
            105,1,CH,A,   $ sort on 1 byte starting at 105
            1,12,CH,A)    $ sort on 12 bytes starting at 1



Code:

  OUTFIL FNAMES=T3,      $ output file DD name
  OUTREC=(1,80,          $ copy 80 bytes from pos 1
          106,6,         $ copy 6 bytes from pos 106
          97,8)          $ copy 8 bytes from pos 97                   


Code:

//CTL3CNTL DD *                                               
  OUTFIL FNAMES=OUT,     $ output file DD name
  OUTREC=(1,86)          $ copy 86 bytes from pos 1                 


If your shop has DFSORT then you can access the DFSORT manual from here.

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/ICE1CA00/CONTENTS?SHELF=&DT=20031124143823#CONTENTS


Hope this helps...

cheers

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: Tue Dec 07, 2004 4:29 pm    Post subject: Reply with quote

This a portion of a DFSORT/ICETOOL job Kolusu showed earlier. The CTL2CNTL DD supplies DFSORT statements for the SORT operator with USING(CTL2) and the CTL3CNTL DD supplies DFSORT statements for the SPLICE operator with USING(CTL3).

If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "DFSORT: Getting Started". It's an excellent tutorial that will teach you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online at:

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/ICE1CG00/CCONTENTS

For complete information on DFSORT's ICETOOL, see:

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/ICE1CA00/6.0?DT=20031124143823

For complete information on the SPLICE operator of DFSORT's ICETOOL, see:

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/ICE1CA00/6.13?SHELF=&DT=20031124143823&CASE=

Here's a brief explanation of the DFSORT control statements in CTL2CNTL and CTL3CNTL.

CTL2CNTL statements:

EQUALS tells DFSORT to keep the original order of duplicate records.

INREC reformats the records before they are sorted using the following fields: 1-96; the ZD value in positions 81-88 minus the ZD value in positions 89-96, and 97-103. M11,LENGTH=8 edits the result of the subtraction.

SORT sorts the records ascending on the following fields in the reformatted INREC record: the ZD field in positions 97-104, the CH field in position 105 and the CH field in positions 1-12.

OUTFIL writes records to the T3 DD data set after they are sorted. OUTREC reformats the records for output using the following fields: positions 1-80, positions 106-111 and positions 97-104.

CTL3CNTL statements:

OUTFIL writes records to the OUT DD data set after they are spliced. OUTREC reformats the records using positions 1-86.
_________________
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
nguyenh
Beginner


Joined: 09 Mar 2004
Posts: 52
Topics: 6

PostPosted: Tue Dec 07, 2004 5:05 pm    Post subject: Reply with quote

Frank Yaeger,
Thank you very much. I actually read your mini ICETOOLS Userguide D/N: Fc27-1997-00 that is very impressive work of you, I even have a copy of it on my desk. But since I am a mainframe and DFSORT beginner so I need something more for dummy Smile. I will read DFSORT links that you suggested.

Kolusu,
Thank you for your helps. Now I understand that part,

This is the part that I am still confused on, I tried to catalog all the temporary datasets, so that I can see the actual data being put in them, but couldn't get it to work (I am very bad in mainframe), so I have to ask you this one more time:

Based on your explaination of the following code:

Code:

OUTREC=(1,80,          $ Copy 80 bytes from pos1 of input
        8C'0',         $ pad 8 zeroes 
        SEQNUM,8,ZD,   $ seqnum( record #)
        C'H',          $ char of 'h'
        39,6)          $ Copy 6 bytes from pos 39 of input 
       


so after the above lines has been executed: am I correct that the output records will have the following format?

Code:

[80 bytes from byte 1][8 zeros][8 bytes sequence number][H][6 bytes from byte 39]


so total record length = 80+8+8+1+6 = 103 ????


Thank you all again!
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Dec 07, 2004 5:25 pm    Post subject: Reply with quote

Quote:

so total record length = 80+8+8+1+6 = 103 ????


nguyenh,

You understanding of the control cards is correct !!

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: Tue Dec 07, 2004 11:20 pm    Post subject: Reply with quote

nguyenh,

Code:

I tried to catalog all the temporary datasets, so that I can see the actual data being put in them, but couldn't get it to work (I am very bad in mainframe), so I have to ask you this one more time:


You can do that easily. All you need to do is to create & catalog the datasets before the sort step. use IEFBR14 to create an empty file (& catalog it). Then use the datasets in the SYNCTOOL/ICETOOL with DISP as SHR.

Hope this helps,

Thanks,
Phantom
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
Goto page Previous  1, 2, 3, 4  Next
Page 2 of 4

 
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