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

Adding negatives and positives separately in DFSORT


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

Active User


Joined: 14 Dec 2008
Posts: 107
Location: India

PostPosted: Sat Nov 07, 2015 2:58 am
Reply with quote

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

Global Moderator


Joined: 21 Sep 2010
Posts: 2727
Location: NYC,USA

PostPosted: Sat Nov 07, 2015 3:09 am
Reply with quote

Please check your offsets.
Back to top
View user's profile Send private message
RahulG31

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Sat Nov 07, 2015 3:35 am
Reply with quote

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
View user's profile Send private message
hiravibk
Warnings : 1

Active User


Joined: 14 Dec 2008
Posts: 107
Location: India

PostPosted: Sat Nov 07, 2015 4:32 am
Reply with quote

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

Active User


Joined: 20 Dec 2014
Posts: 446
Location: USA

PostPosted: Sat Nov 07, 2015 8:05 pm
Reply with quote

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7310
Location: Inside the Matrix

PostPosted: Mon Nov 09, 2015 8:02 pm
Reply with quote

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

Global Moderator


Joined: 21 Sep 2010
Posts: 2727
Location: NYC,USA

PostPosted: Tue Nov 10, 2015 12:08 am
Reply with quote

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
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 REXX - Adding variables CLIST & REXX 8
No new posts DFSORT to add 6 hours to time(tdate-t... DFSORT/ICETOOL 16
No new posts SOC7 error with DFSORT DFSORT/ICETOOL 9
No new posts Join lines with dfsort DFSORT/ICETOOL 5
No new posts Covert k to 1000 / m to 1000000 using... DFSORT/ICETOOL 5
Search our Forums:

Back to Top