Page 1 of 1

DFSORT: SORT and GROUP

PostPosted: Tue Jan 11, 2011 11:57 am
by New2MF
Hi,

Below is the sample input file -
Input File:

ACCOUNT AMONUT
111111 100.00
999999 200.00
888888 500.00
999999 50.00
111111 150.00
999999 600.00
888888 750.00
999999 999.00
111111 200.00
999999 250.00
888888 300.00

I want to create a file in which the records will be as follows -

Required Output:
ACCOUNT AMONUT
999999 999.00
999999 600.00
999999 250.00
999999 200.00
999999 50.00
888888 750.00
888888 500.00
888888 300.00
111111 200.00
111111 150.00
111111 100.00

The sorting needs to be done on the amount field but the grouping should be on the Account # field in such a way that the records corresponding to the account # having the highest amount should be listed in descending order in the output file. Then the records corresponding to the account of 2nd highest amount and so on.

I'm not good at DFSORT/SYNCSORT. And not sure if this kind or sorting+grouping would be possible. But thought of exploring the possibilities before having to write a program to create the required output file.[code][/code]

Re: DFSORT: SORT and GROUP

PostPosted: Tue Jan 11, 2011 3:28 pm
by NicC
sort on the account field descending and then the amount field descending.
  SORT FIELDS=(p1,p2,CH,D,p3,p4,CH,D)

where p1 and p2 are the start and end positions of Account and p3, p4 the start and end positions of Amount. Check with the manual (numerous links within the DFSORT section of the forum) for the correct data type - I have put CH because I cut and pasted but ZD may be more to the point.

Also, when posting sort questions you should specify in your post the following
LRECL, RECFM, start position of all relevant fields and end position of all relevant fields - remember to add 4 bytes to these positions if the file has variable length records. Also include sample input data including duplicates if such are allowed and sample output data and the rules for getting from input to output.

Re: DFSORT: SORT and GROUP

PostPosted: Tue Jan 11, 2011 11:59 pm
by Frank Yaeger
I have put CH because I cut and pasted but ZD may be more to the point.


Actually, UFF would probably be the correct format to use for the numbers.

New2MF,

If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from:

http://www.ibm.com/support/docview.wss? ... g3T7000080