Page 1 of 1

sorting a file - sum fields and removing duplicates

PostPosted: Tue Dec 18, 2012 2:45 am
by test
Hi

I'm very new to this and would love to hear if this is possible to achive and how to solve it.

My file is:
userid    acct.    note    cost-cmp3
333-444   222333   TEXT2   -10
333-444   222222   TEXT1   -20
111-222   111111   TEXT1   -10
111-222   111111   TEXT1   +10
111-222   111111   TEXT2   -20
555-666   111111   TEXT1   -10


Now, is it possible in my JCL to add a sort that sorts and reduce my file?

The output should be something like this:
userid    acct.    note    cost-cmp3
111-222   111111   TEXT1   +00
111-222   111111   TEXT2   -20
333-444   222222   TEXT1   -10
333-444   222333   TEXT2   -20
555-666   111111   TEXT1   -10


The file is sorted by userid, acct and note.
And duplicates (where userid, acct, and notes are same) we remove the the line and sumerize all costs together (see -10 and +10 we get 0).

Is this possible?

How do I solve this? Do you have any good sort manual?

Please advice

Thank you.

Re: sorting a file - sum fields and removing duplicates

PostPosted: Tue Dec 18, 2012 3:34 am
by Akatsukami
As you have posted in the DFSORT forum, I shall presume until it is shown otherwise that you indeed have DFSORT, and not Syncsort, CA-SORT, Sort of a Different Colo(u)r, or some other product.

The DFSORT programming manual is here. Read it. This is an extremely elementary task, even by the standards of software engineers; if you cannot figure it out on your own, your prospects for a career in the IT industry are dim indeed.

Re: sorting a file - sum fields and removing duplicates

PostPosted: Tue Dec 18, 2012 3:52 am
by BillyBoyo
The DFSORT Getting Started is here. You will find examples. You need SORT and SUM.

The manuals in the links are also available as PDFs.

Re: sorting a file - sum fields and removing duplicates

PostPosted: Tue Dec 18, 2012 4:14 am
by skolusu
use the following DFSORT JCL which will give you the desired results

//STEP0100 EXEC PGM=SORT                       
//SYSOUT   DD SYSOUT=*                         
//SORTIN   DD DSN=Your Input FB file,DISP=SHR               
//SORTOUT  DD SYSOUT=*                         
//SYSIN    DD *                               
  SORT FIELDS=(01,10,CH,A,           $ USER-ID
               11,06,CH,A,           $ ACCT   
               20,04,CH,A)           $ NOTE   
                                               
  SUM FIELDS=(25,6,PD)               $ SUM COST
//*

Re: sorting a file - sum fields and removing duplicates

PostPosted: Wed Jan 30, 2013 6:14 pm
by test
Thank you all for the urls !
and for the solution skolusu!