Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Adding negatives and positives separately in DFSORT

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
hiravibk
Warnings : 1

Active User


Joined: 14 Dec 2008
Posts: 103
Location: India

PostPosted: Sat Nov 07, 2015 2:58 am    Post subject: Adding negatives and positives separately in DFSORT
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

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Sat Nov 07, 2015 3:09 am    Post subject:
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: 331
Location: USA

PostPosted: Sat Nov 07, 2015 3:35 am    Post subject: Reply to: Adding negatives and positives separately in DFSORT
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: 103
Location: India

PostPosted: Sat Nov 07, 2015 4:32 am    Post subject: Re: Reply to: Adding negatives and positives separately in DFSORT
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: 331
Location: USA

PostPosted: Sat Nov 07, 2015 8:05 pm    Post subject: Reply to: Adding negatives and positives separately in DFSORT
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7236

PostPosted: Mon Nov 09, 2015 8:02 pm    Post subject: Reply to: Adding negatives and positives separately in DFSORT
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

Senior Member


Joined: 21 Sep 2010
Posts: 1610
Location: NY,USA

PostPosted: Tue Nov 10, 2015 12:08 am    Post subject:
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.
http://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    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to get the remainder and quotient... vnktrrd DFSORT/ICETOOL 2 Mon Oct 31, 2016 10:59 am
No new posts Adding records from two files into on... shiitiizz SYNCSORT 4 Mon Sep 19, 2016 8:41 pm
No new posts Change date (DD/MM/YY) in 2nd record ... uday kiran DFSORT/ICETOOL 12 Wed Sep 07, 2016 10:57 pm
No new posts DFSORT sorting only specific records akodakka DFSORT/ICETOOL 4 Thu Aug 04, 2016 11:24 am
No new posts Adding a descending character to a file Steve Ironmonger DFSORT/ICETOOL 3 Fri Jul 15, 2016 4:57 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us