View previous topic :: View next topic
Author
Message
vissubhai New User Joined: 07 Nov 2007Posts: 12 Location: Hyderabad
Hi All,
Hope everyone is doing great. This time I am stuck with an interesting requirement.
I have a file with different record types such as header, merchant header, merchant records, detail records, merchant trailer and the file trailer.
First byte = 1 (File Header)
First byte = 2 (Merchant Header)
First byte = 3 (Detail Record)
First byte = 4 (Merchant Trailer)
First byte = 9 (File trailer)
My requirement is to sort only the detail records and keep all the other records in place.
Sorting of detail records is on the key starting from 2nd position to 4 bytes.
Sampe Input file:
1HEADER1
2MERCHANT HEADER1
3REC5
3REC1
3REC4
3REC3
3REC2
4MERCHANT TRAILER1
9FILE TRAILER1
1HEADER2
2MERCHANT HEADER2
3REC3
3REC5
3REC4
3REC1
3REC2
4MERCHANG TRAILER2
9FILE TRAILER2
1HEADER3
2MERCHANT HEADER3
3REC3
3REC5
3REC4
3REC1
3REC2
4MERCHANG TRAILER3
9FILE TRAILER3
Desired Output file:
1HEADER1
2MERCHANT HEADER1
3REC1
3REC2
3REC3
3REC4
3REC5
4MERCHANT TRAILER1
9FILE TRAILER1
1HEADER2
2MERCHANT HEADER2
3REC1
3REC2
3REC3
3REC4
3REC5
4MERCHANG TRAILER2
9FILE TRAILER2
1HEADER3
2MERCHANT HEADER3
3REC1
3REC2
3REC3
3REC4
3REC5
4MERCHANG TRAILER3
9FILE TRAILER3
Hope I am clear with my requirement and thanks a lot in advance.
Regards,
Viswanath.
Back to top
vasanthz Global Moderator Joined: 28 Aug 2007Posts: 1742 Location: Tirupur, India
Hello,
You could try the below job for the requirement,
Code:
//JS020 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//SORTIN DD DISP=SHR,DSN=WELLS.SORTIN
//SORTOUT DD DSN=WELLS.SORTOUT,DISP=OLD
//SYSOUT DD SYSOUT=*
//TOOLIN DD *
SORT FROM(SORTIN) TO(SORTOUT) USING(CTL1)
/*
//CTL1CNTL DD *
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'1'),
PUSH=(81:ID=8))
SORT FIELDS=(81,8,ZD,A,1,1,ZD,A,2,4,CH,A)
OUTREC BUILD=(1,80)
/*
//SYSUDUMP DD SYSOUT=*
/*
Hope it helps.
Back to top
nigelosberry New User Joined: 06 Jan 2009Posts: 88 Location: Ggn, IN
At some point in career, a sort user faces this requirement in same form or with a slight change.
The icetool way of doing it looks cool. But this can as well be done in DFSORT(with a little bit of clever logic). I did that back in 2007.
Let me know if you are interested in the other way of doing it.
Back to top
vasanthz Global Moderator Joined: 28 Aug 2007Posts: 1742 Location: Tirupur, India
mmm.. To do it with DFSORT
Use the same statements above in SYSIN of DFSORT,
Code:
//PS020 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SORTIN DD DSN=WELLS.SORTIN,DISP=SHR
//SORTOUT DD DSN=WELLS.SORTOUT,DISP=OLD
//SYSIN DD *
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,1,CH,EQ,C'1'),
PUSH=(81:ID=8))
SORT FIELDS=(81,8,ZD,A,1,1,ZD,A,2,4,CH,A)
OUTREC BUILD=(1,80)
/*
CNTL DD's in ICETOOL are like SYSIN for DFSORT.
Quote:
But this can as well be done in DFSORT(with a little bit of clever logic).I did that back in 2007.
Please share your technique as well, as it might help in learning.
Back to top
nigelosberry New User Joined: 06 Jan 2009Posts: 88 Location: Ggn, IN
Nothing new. This is precisely the technique I was talking about(sort sequence characters in the unused columns of record). This is taken care by:
BEGIN=(1,1,CH,EQ,C'1'),
PUSH=(81:ID=8))
This is a nice and neat way of grouping same batch of records together.
Though, I did a bit differently coz I did not know about begin and push (in dfsort). I did the sequencing of records in seperate step using Selcopy. Have these commands recently been added to DFSORT?
Back to top
Escapa Senior Member Joined: 16 Feb 2007Posts: 1399 Location: IL, USA
Quote:
Have these commands recently been added to DFSORT?
In this fast it world.. I wont call July, 2008 as recently... ..
Back to top
Frank Yaeger DFSORT Developer Joined: 15 Feb 2005Posts: 7129 Location: San Jose, CA
Back to top
vissubhai New User Joined: 07 Nov 2007Posts: 12 Location: Hyderabad
Thanks vasanthz & nihalansari. The solution worked like charm
Back to top
Please enable JavaScript!