View previous topic :: View next topic
Author
Message
Jithucse New User Joined: 18 Apr 2008Posts: 11 Location: Coimbatore
Hi,
I've have a requirement like this...My input file contains records as shown below..
ABD10Y
ABD20Y
DEF10N
DEF30N
DEF30N
GEH40Y
And my output records are...
ABD30
DEF0
GEH40
That is if the sixth byte is 'Y', then i will be adding the amount fields(4,5) of that key.
Can anyone suggest any method in sort?
Regards,
Jithucse
Back to top
Escapa Senior Member Joined: 16 Feb 2007Posts: 1399 Location: IL, USA
Hi Jithucse,
Do you want sum to be left alligned?
Back to top
Jithucse New User Joined: 18 Apr 2008Posts: 11 Location: Coimbatore
Not required..I'm fine with
ABD30
DEF 0
FEH40
Back to top
Escapa Senior Member Joined: 16 Feb 2007Posts: 1399 Location: IL, USA
Hi below sortstep will give you desired result
Code:
//S1 EXEC PGM=SORT
//SORTIN DD *
ABD10Y
ABD20Y
DEF10N
DEF30N
DEF30N
GEH40Y
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,3,CH,A)
SUM FIELDS=(4,2,ZD)
INREC IFTHEN=(WHEN=(6,1,CH,EQ,C'N'),OVERLAY=(4:C'00'))
OUTFIL BUILD=(1,3,4,2,ZD,EDIT=(IT))
/*
Back to top
Escapa Senior Member Joined: 16 Feb 2007Posts: 1399 Location: IL, USA
But I suggest you to use this so that sum fields will not overflow...
Code:
//S1 EXEC PGM=SORT
//SORTIN DD *
ABD10Y
ABD20Y
DEF10N
DEF30N
DEF30N
GEH99Y
GEH99Y
GEH99Y
GEH99Y
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,3,CH,A)
SUM FIELDS=(4,8,ZD)
INREC IFTHEN=(WHEN=(6,1,CH,EQ,C'N'),BUILD=(1,3,8C'0')),
IFTHEN=(WHEN=NONE,BUILD=(1,3,6C'0',4,2))
OUTFIL BUILD=(1,3,4,8,ZD,EDIT=(IIIIIIIT))
/*
Output will be
Code:
ABD 30
DEF 0
GEH 396
Back to top
Jithucse New User Joined: 18 Apr 2008Posts: 11 Location: Coimbatore
Thanks Sambhaji,
It worked...Thanks a lot...
Regards,
Jithucse
Back to top
Skolusu Senior Member Joined: 07 Dec 2007Posts: 2205 Location: San Jose
Jithucse,
Since your input is already sorted on the key, you can use COPY instead of sort and here is another way to get the desired results without worrying about the overflow and padding the records before summing
Code:
//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=(6,1,CH,EQ,C'N'),OVERLAY=(4:C'00'))
OUTFIL REMOVECC,NODETAIL,
SECTIONS=(1,3,TRAILER3=(1,3,TOT=(4,2,ZD,M10,LENGTH=8)))
//*
Back to top
Frank Yaeger DFSORT Developer Joined: 15 Feb 2005Posts: 7129 Location: San Jose, CA
Sambhaji,
I'm curious. Why do you have
//SYSPRINT DD SYSOUT=*
in your DFSORT jobs? DFSORT does NOT use this ddname.
Back to top
Escapa Senior Member Joined: 16 Feb 2007Posts: 1399 Location: IL, USA
Yeah... You are right Frank.
I copied STEP from existing JCL(calling some other program) and changed it for this example.
Missed to delete SYSPRINT
Back to top
Please enable JavaScript!