|
View previous topic :: View next topic
|
| Author |
Message |
Karthigaiselvan
New User
Joined: 11 Dec 2006 Posts: 35 Location: India
|
|
|
|
Hi,
I want to create multiple header records with a count of detail records to group based on a key field.
For ex -
I have an input file of the following record lay out
| Code: |
ENO DNO
------ -----
0001 1000
0002 1000
0003 1000
0004 1001
0005 1001
0006 1002
|
Now i want to get the counts of all employees working for each department. i.e. my output file should look like
| Code: |
ENO DNO
------ -----
HEADER 1000 03
0001 1000
0002 1000
0003 1000
HEADER 1001 02
0004 1001
0005 1001
HEADER 1002 01
0006 1002
|
Any SORT tricks for this? |
|
| Back to top |
|
 |
CICS Guy
Senior Member

Joined: 18 Jul 2007 Posts: 2146 Location: At my coffee table
|
|
|
|
As has been shown in other posts, the headers need to be generated as trailers and then sorted to the front of each key group....
Take a look at Header with record statistics |
|
| Back to top |
|
 |
Frank Yaeger
DFSORT Developer

Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Karthi,
Here's a DFSORT/ICETOOL job that will do what you asked for:
| Code: |
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=... input file
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)
//CON DD DSN=*.T1,VOL=REF=*.T1,DISP=(OLD,PASS)
// DD DSN=*.IN,VOL=REF=*.IN,DISP=(OLD,PASS)
//OUT DD DSN=... output file
//TOOLIN DD *
COPY FROM(IN) USING(CTL1)
SORT FROM(CON) TO(OUT) USING(CTL2)
/*
//CTL1CNTL DD *
OUTFIL FNAMES=T1,REMOVECC,NODETAIL,
SECTIONS=(24,4,
TRAILER3=('HEADER',24:24,4,31:COUNT=(EDIT=(TT))))
/*
//CTL2CNTL DD *
OPTION EQUALS
SORT FIELDS=(24,4,CH,A)
/*
|
|
|
| Back to top |
|
 |
Karthigaiselvan
New User
Joined: 11 Dec 2006 Posts: 35 Location: India
|
|
|
|
Thanks Frank,
I am trying to understand the sort job you have given.
Can you please explain what the following will do?
| Code: |
SECTIONS=(24,4,
TRAILER3=('HEADER',24:24,4,31:COUNT=(EDIT=(TT))))
|
|
|
| Back to top |
|
 |
Frank Yaeger
DFSORT Developer

Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
SECTIONS=(24,4 - starts a new "section" whenever the value in 24-27 changes (e.g. when it changes from 1000 to 1001). Every record with the same value in 24-27 is part of the same section. So the three 1000 records are in the first section, the two 1001 records are in the second section and the 1002 record is in the third section.
TRAILER3 - adds a trailer record for each section.
'HEADER' - puts the constant 'HEADER' in output positions 1-6 of the trailer record for each section.
24:24,4 - puts input positions 24-27 in output positions 24-27 of the trailer record fo each section. For the first section, that's 1000, for the second section 1001 and for the third section 1002.
31:COUNT=(EDIT=(TT)) - puts the count of records in each section in output positions 31-32 of the trailer record for each section. For the first section, that's 03 (there are three 1000 records), for the second section 02 and for the third section 01.
If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from:
Use [URL] BBCode for External Links |
|
| Back to top |
|
 |
Karthigaiselvan
New User
Joined: 11 Dec 2006 Posts: 35 Location: India
|
|
|
|
Hi Frank,
Thank you verymuch for your help! |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|