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

How to insert header recs for a group of some detail recs?


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

New User


Joined: 11 Dec 2006
Posts: 35
Location: India

PostPosted: Thu Sep 13, 2007 11:02 pm
Reply with quote

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
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Thu Sep 13, 2007 11:44 pm
Reply with quote

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
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Sep 14, 2007 12:03 am
Reply with quote

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
View user's profile Send private message
Karthigaiselvan

New User


Joined: 11 Dec 2006
Posts: 35
Location: India

PostPosted: Fri Sep 14, 2007 10:29 pm
Reply with quote

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
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Sep 14, 2007 11:30 pm
Reply with quote

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
View user's profile Send private message
Karthigaiselvan

New User


Joined: 11 Dec 2006
Posts: 35
Location: India

PostPosted: Mon Sep 17, 2007 10:10 am
Reply with quote

Hi Frank,

Thank you verymuch for your help!
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 Insert header record with record coun... DFSORT/ICETOOL 14
No new posts Insert system time/date (timestamp) u... DFSORT/ICETOOL 5
No new posts Identify Program Insert DB2 7
No new posts Insert trailer for non empty file only DFSORT/ICETOOL 6
No new posts Compare latest 2 rows of a table usin... DB2 1
Search our Forums:

Back to Top