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

Please help - SORT with SUM fields and filter on same step


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

New User


Joined: 21 Apr 2010
Posts: 7
Location: USA

PostPosted: Thu Apr 09, 2020 11:01 am
Reply with quote

Hi, I have 2 questions on using DFSORT on a FB dataset with 2 fields - Branch nbr, dollar value (PD). I want to group the input records on Branch Nbr and sum on the dollar field. I want to write to output file ONLY if the sum on dollar field is not 0.00 and less than 100.00.

1. Is it possible to achieve this in ONE sort step?
2. How should packed decimal be coded in include condition in sort step?

I/P file looks like below
A001 -100.00
A001 100.00
A002 300.00
A002 -250.00
A003 -400.00
A003 600.00

O/P file I need should be:
A002 50.00

I can do this in 2 sort steps but I was trying to do this in one step if possible. This is my first post. Hopefully, I have provided enough information to look into this. Can you please help?
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1222
Location: Bamberg, Germany

PostPosted: Thu Apr 09, 2020 11:35 am
Reply with quote

What have you tried? Please use code tags to make it easier to understand.
Back to top
View user's profile Send private message
clearskynot

New User


Joined: 21 Apr 2010
Posts: 7
Location: USA

PostPosted: Thu Apr 09, 2020 11:54 am
Reply with quote

Joerg.Findeisen wrote:
What have you tried? Please use code tags to make it easier to understand.


Thanks for looking into it. I could not get it in one step.
Below is how i was able to get the desired output with 2 steps:

1. SORT FIELDS=(1,4,CH,A)
SUM FIELDS=(5,6,PD)

2. SORT FIELDS=COPY
INCLUDE COND=(5,6,PD,NE,0,AND,5,6,PD,LT,10000)
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


Joined: 15 Aug 2015
Posts: 1222
Location: Bamberg, Germany

PostPosted: Thu Apr 09, 2020 12:24 pm
Reply with quote

Use OUTFIL and put your INCLUDE in there. That should be it. You are close to your One Ring to rule them All solution.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2010
Location: USA

PostPosted: Thu Apr 09, 2020 6:12 pm
Reply with quote

The developers of all SORT products allowed to include their control statements in any order under //SYSIN DD.

This resulted in a huge mess in the beginners' mind, because they do not catch the order each statement is processed.

In practice, it make sense (much more sense than it appears from the first sight): to code statements in the same order they are handled by the SORT product. There is such diagram in existing manuals, but nobody pays any attention to it (if had RTFM at all).

The order of statements is as follows
Code:
 INCLUDE/OMIT COND=…
 INREC …
 SORT …
 SUM …
 …
 OUTREC …
 OUTFIL [INCLUDE/OMIT=…]
 OUTFIL [INCLUDE/OMIT=…]
 END

In case of JOIN operation
Code:
 JOINKEYS F1=…,[INCLUDE/OMIT=…]
 JOINKEYS F2=…,[INCLUDE/OMIT=…]
 JOIN UNPAIRED,...
 REFORMAT
 INCLUDE/OMIT COND=...
 SORT …
 SUM …
 …
 OUTREC …
 OUTFIL [INCLUDE/OMIT=…]
 OUTFIL [INCLUDE/OMIT=…]
 END
Back to top
View user's profile Send private message
clearskynot

New User


Joined: 21 Apr 2010
Posts: 7
Location: USA

PostPosted: Fri Apr 10, 2020 3:43 am
Reply with quote

Joerg.Findeisen wrote:
Use OUTFIL and put your INCLUDE in there. That should be it. You are close to your One Ring to rule them All solution.


That worked perfectly ! thank you !
Back to top
View user's profile Send private message
clearskynot

New User


Joined: 21 Apr 2010
Posts: 7
Location: USA

PostPosted: Fri Apr 10, 2020 3:43 am
Reply with quote

sergeyken wrote:
The developers of all SORT products allowed to include their control statements in any order under //SYSIN DD.

This resulted in a huge mess in the beginners' mind, because they do not catch the order each statement is processed.

In practice, it make sense (much more sense than it appears from the first sight): to code statements in the same order they are handled by the SORT product. There is such diagram in existing manuals, but nobody pays any attention to it (if had RTFM at all).

The order of statements is as follows
Code:
 INCLUDE/OMIT COND=…
 INREC …
 SORT …
 SUM …
 …
 OUTREC …
 OUTFIL [INCLUDE/OMIT=…]
 OUTFIL [INCLUDE/OMIT=…]
 END

In case of JOIN operation
Code:
 JOINKEYS F1=…,[INCLUDE/OMIT=…]
 JOINKEYS F2=…,[INCLUDE/OMIT=…]
 JOIN UNPAIRED,...
 REFORMAT
 INCLUDE/OMIT COND=...
 SORT …
 SUM …
 …
 OUTREC …
 OUTFIL [INCLUDE/OMIT=…]
 OUTFIL [INCLUDE/OMIT=…]
 END


Thank you for looking into this!
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 JCL sort card - get first day and las... JCL & VSAM 9
No new posts Return codes-Normal & Abnormal te... JCL & VSAM 7
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
No new posts how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
No new posts how to calculate SUM for VB file usin... JCL & VSAM 1
Search our Forums:

Back to Top