View previous topic :: View next topic
Author
Message
hiravibk Warnings : 1 Active User Joined: 14 Dec 2008Posts: 107 Location: India
Hi,
I am trying to add negative numbers and positive numbers separately in DFSORT. I am not getting the desired output. Please help. Thanks in advance.
Input:
Code:
ALICE +00005
ALICE -00020
ALICE -00010
ALICE +00005
BOB -00020
BOB +00002
My Code:
Code:
//STEP25 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN =INPUT,DISP=SHR
//RPT1 DD SYSOUT=*
//SYSIN DD *
INREC OVERLAY=(07:07,6,SFF,TO=ZD,LENGTH=6)
SORT FIELDS=(01,5,CH,A,07,1,CH,A)
SUM FIELDS=(08,5,ZD)
OUTFIL FNAMES=RPT1,
HEADER1=(1:'NAME ',C',',07:'SPENDING'),
OUTREC=(1:1,5,C',',07:07,6,2X)
OUTREC OVERLAY=(07:07,6,ZD,EDIT=(STTTTT),SIGNS=(,-))
END
/*
Output Required:
Code:
NAME ,SPENDING
ALICE,+00010
ALICE,-00030
BOB ,-00020
BOB ,+00002
Output I am getting from the code:
Code:
NAME ,SPENDING
ALICE,-00020
BOB ,-00018
Back to top
Rohit Umarjikar Global Moderator Joined: 21 Sep 2010Posts: 3051 Location: NYC,USA
Please check your offsets.
Back to top
RahulG31 Active User Joined: 20 Dec 2014Posts: 446 Location: USA
I think this could be much simpler. Why Overlay?
Instead of Sort fields=(1,5) , you can use Sort fields=(1,7) that includes the sign and then make use of Sum fields=(8,5)
Here is a quick modification:
Code:
SORT FIELDS=(1,7,CH,A)
SUM FIELDS=(8,5,ZD)
OUTREC BUILD=(1:1,7,C',',9:8,5)
OUTFIL HEADER1=(1:'NAME',C',',06:'SPENDING')
Back to top
hiravibk Warnings : 1 Active User Joined: 14 Dec 2008Posts: 107 Location: India
RahulG31 wrote:
I think this could be much simpler. Why Overlay?
Instead of Sort fields=(1,5) , you can use Sort fields=(1,7) that includes the sign and then make use of Sum fields=(8,5)
Here is a quick modification:
Code:
SORT FIELDS=(1,7,CH,A)
SUM FIELDS=(8,5,ZD)
OUTREC BUILD=(1:1,7,C',',9:8,5)
OUTFIL HEADER1=(1:'NAME',C',',06:'SPENDING')
Thanks, i just tried and it does work. But it does not give which values are negative and which are positive. Is there any other way?
Back to top
RahulG31 Active User Joined: 20 Dec 2014Posts: 446 Location: USA
Quote:
But it does not give which values are negative and which are positive.
What do you mean?
It 'does' give you the sign field. You may need to rearrange it after ','.
Code:
OUTREC BUILD=(1,5,C',',7,1,9:8,5)
It should give you the expected result unless your expectations are different than what you had mentioned earlier.
.
Back to top
Bill Woodger Moderator Emeritus Joined: 09 Mar 2011Posts: 7309 Location: Inside the Matrix
Missed this.
If you are SORTing your data just to be able to use SUM, that is not a good use of resources. The sample you show is in sequence.
You also wouldn't get any output if there are no items for either positive or negeative for a particular key. Is that important to you?
Extend the data with two fields. For +, put the value in one field, and zero in the other. For -, put zero in one field, the value in the other.
Use OUTFIL reporting features with NODETAIL and REMOVECC. SECTIONS and TRAILER3. Use the slash operator (/) to output two lines for the TRAILER3, and use TOT/TOTAL for the two separate values.
Back to top
Rohit Umarjikar Global Moderator Joined: 21 Sep 2010Posts: 3051 Location: NYC,USA
Try this with what you said in you origianl post.
Code:
SORT FIELDS=(01,5,CH,A,07,1,CH,A)
SUM FIELDS=(08,5,ZD)
OUTFIL FNAMES=RPT1,
HEADER1=(1:'NAME ',C',',07:'SPENDING'),
OUTREC=(1:1,5,C',',7:7,1,08:08,5,3X)
OUTREC OVERLAY=(08:08,5,ZD,EDIT=(TTTTT))
END
This is similar post to what Bill is saying if you are wonder.
www.ibmmainframes.com/about41815.html
Back to top
Please enable JavaScript!