View previous topic :: View next topic
|
Author |
Message |
Narismha
New User
Joined: 22 Nov 2006 Posts: 23 Location: Mumbai
|
|
|
|
Hi,
I have file with headers and details records. I want to sort only detail record without disturbing header records( File has page break logic).
INPUT file:
Page1
Header1
Emp sal dep serv
------ ----- ----- ------
0001 2222 093 20
0003 1111 042 25
0004 3333 023 15
Page2
Header1
Emp sal dep serv
------ ----- ----- ------
0005 5555 023 30
0006 4444 022 20
REquired output:
Page1
Header1
Emp sal dep serv
------ ----- ----- ------
0003 1111 042 25
0001 2222 093 20
0004 3333 023 15
Page2
Header1
Emp sal dep serv
------ ----- ----- ------
0006 4444 022 20
0005 5555 023 30
I want a sort by Sal in the detail record.
Please let me know your suggestion.
Thanks
-Narisimha |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Trying to sort the details records within this kind of report does not make sense. I'd suggest getting just the detail records from the report, sorting them, and then redoing the report with the header records. Or better yet, go back to the original program that created the report and have it sort the detail records by salary. |
|
Back to top |
|
|
shreevamsi
Active User
Joined: 23 Feb 2006 Posts: 305 Location: Hyderabad,India
|
|
|
|
Hi Narismha,
This can be done using ICETOOL. Look at the following code:
//SORTIN EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=XXXX.XXXX.XXXX,DISP=SHR
//*** MUST USE DISP=MOD FOR OUTPUT - MAKE SURE
//*** THE OUTPUT DATA SET IS EMPTY INITIALLY
//OUT DD DISP=MOD,DSN=YYYY.YYYY.YYYY(0),
// DCB=(LRECL=080,RECFM=FB),
// SPACE=(TRK,(10,10),RLSE),
// UNIT=DISK
//TOOLIN DD *
* COPY HEADER RECORD
COPY FROM(IN) TO(OUT) USING(HHHH)
* SORT DETAIL RECORDS
SORT FROM(IN) TO(OUT) USING(DDDD)
* COPY TRAILER RECORD
COPY FROM(IN) TO(OUT) USING(TTTT)
/*
//HHHHCNTL DD *
* GET HEADER RECORD (FIRST)
OPTION STOPAFT=1
/*
//DDDDCNTL DD *
* SKIP HEADER RECORD
OPTION SKIPREC=1
* SKIP TRAILER RECORD
** USE AN OMIT CONDITION THAT DISTINGUISHES
** IDENTIFY THE TRAILER RECORD FROM THE DETAIL RECORDS WITH A **KEY FIELD
OMIT COND=(1,4,CH,EQ,C'VAMS')
* SORT ALL BUT THE HEADER AND TRAILER RECORDS
SORT FIELDS=(1,6,CH,A)
/*
//TTTTCNTL DD *
* SKIP HEADER RECORD
OPTION SKIPREC=1
* GET TRAILER RECORD
** USE AN INCLUDE CONDITION THAT DISTINGUISHES
** THE TRAILER RECORD FROM THE DETAIL RECORDS
** (SAME AS ABOVE)
INCLUDE COND=(1,4,CH,EQ,C'VAMS')
/*
The above code sorts detail records leaving both Header and Footer. I have give elobrate comments to each parameters. Look at them and tune this code according for your requirement. Let me know if you face any difficulty.
~Vamsi |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Vamsi,
I don't think you actually understand the complexity of the requirement.
I believe your job would only work for one page of the report (if that) and is less efficient for doing that then the "Sort records between a header and trailer" Smart DFSORT Trick which does that in one pass.
Go back and look at Narisimha's original post again and you'll see that the report has multiple pages and each page has a header that has to be kept for that page, and detail records which have to be sorted by salary. And the detail records may not even end up on their original pages. For example, a salary from page 3 could be the lowest salary and end up on page 1.
Do you really think the job you show handles all that? |
|
Back to top |
|
|
shreevamsi
Active User
Joined: 23 Feb 2006 Posts: 305 Location: Hyderabad,India
|
|
|
|
Yes Frank,
You are right. I will agree with you. My code won't work for reports.
~Vamsi |
|
Back to top |
|
|
skkp2006
New User
Joined: 14 Jul 2006 Posts: 93 Location: Chennai,India
|
|
|
|
Can we think of splitting the file/report by pages and joining it back after sorting by salary ??? |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
How exactly would you do that?
You'd still have to move each sorted-by-salary detail record to the correct page. You can't just extract a page, sort the detail records on that page and put it back. You have to sort all of the detail records on every page and put them back on the correct pages. For example, the current last record on the last page may be the first record when sorted by salary and thus would have to be moved to the first page. It really makes more sense to extract the data records, sort them and then recreate the report with the headers. |
|
Back to top |
|
|
skkp2006
New User
Joined: 14 Jul 2006 Posts: 93 Location: Chennai,India
|
|
|
|
You are correct Frank.I think the only way out is to extract the detail records get them sorted and re create the report or else sort the input file by salary and feed to the program which creates the report(if salary is not calculated in the report program)
Thanks...
Syam |
|
Back to top |
|
|
|