View previous topic :: View next topic
|
Author |
Message |
clearskynot
New User
Joined: 21 Apr 2010 Posts: 7 Location: USA
|
|
|
|
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 |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1222 Location: Bamberg, Germany
|
|
|
|
What have you tried? Please use code tags to make it easier to understand. |
|
Back to top |
|
|
clearskynot
New User
Joined: 21 Apr 2010 Posts: 7 Location: USA
|
|
|
|
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 |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1222 Location: Bamberg, Germany
|
|
|
|
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 |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2010 Location: USA
|
|
|
|
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 |
|
|
clearskynot
New User
Joined: 21 Apr 2010 Posts: 7 Location: USA
|
|
|
|
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 |
|
|
clearskynot
New User
Joined: 21 Apr 2010 Posts: 7 Location: USA
|
|
|
|
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 |
|
|
|