|
View previous topic :: View next topic
|
| Author |
Message |
suganthyprabha
New User
Joined: 28 Jul 2005 Posts: 58
|
|
|
|
Hi Friends,
I am getting incorrect Output While summing the fields. Can u please correct me what mistake I have made.
I want the Output as :
411
Following is the code i am using.
//JOB1 JOB (U,1019),'AAA',CLASS=0,MSGCLASS=X,MSGLEVEL=(1,1),
// NOTIFY=&SYSUID
//S1 EXEC PGM=ICEMAN
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=A.B.PS1,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,3,CH,A)
SUM FIELDS=(5,3,ZD)
/*
INPUT FILE:
==========
ZZZ 111
BBB 100
CCC 200
OUTPUT:
========
********************************
BBB 100
CCC 200
ZZZ 111
******************************** |
|
| Back to top |
|
 |
raajan_p
New User
Joined: 19 Sep 2005 Posts: 17
|
|
|
|
Hi,
the output is correct.
it will be displayed as
BBB 100
CCC 200
ZZZ 111
according to your input and SYSIN statement. If you want the output to be 411 then your input should have been
BBB 100
BBB 200
BBB 111
if the input file is like
ZZZ 111
CCC 200
CCC 100
Then your output would be
CCC 300
ZZZ 111.
Hope you get wat i am trying to say. Please correct me if i am wrong. |
|
| Back to top |
|
 |
suganthyprabha
New User
Joined: 28 Jul 2005 Posts: 58
|
|
|
|
Hi rajan,
Thanks for ur Reply. I got that.
I am having one more doubt.
Suppose my input file is as foll.
110
100
050
300
I want to sort and Sum this fields.
So i have tried like
//SYSIN DD *
SORT FIELDS=(1,3,CH,A)
SUM FIELDS=(1,3,ZD)
S000 U0016 stating that
ILLEGAL OVERLAPPING OF SUM FIELDS .
So can u please let me know regarding this.
Thanks and Regards,
Suganthy. |
|
| Back to top |
|
 |
Frank Yaeger
DFSORT Developer

Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
SUM works with equal SORT keys. If you don't have equal SORT keys, the fields aren't summed. If you do have equal SORT keys, then you get a sum for each sort key.
In your first post, you did not have any equal SORT keys, so none of the records were summed. If you want a total of the field for all of the records, you can use these DFSORT statements:
| Code: |
OPTION COPY
OUTFIL REMOVECC,NODETAIL,
OUTREC=(TOT=(1,3,ZD,TO=ZD,LENGTH=3))
|
In your second post, you used the same field for SORT and SUM - that's not allowed, and if it were, nothing would be summed because none of the keys (the sum fields) would be equal. If you used:
| Code: |
SORT FIELDS=(4,1,CH,A)
OPTION ZDPRINT
SUM FIELDS=(1,3,ZD)
|
that would give you a total. The sort key (1 blank) would be equal for every record, so the field would be summed. Note that I added ZDPRINT to ensure that the records are readable (F sign). |
|
| Back to top |
|
 |
suganthyprabha
New User
Joined: 28 Jul 2005 Posts: 58
|
|
|
|
Hi Frank,
Thank u so much. Now only i have the clear idea about the SUM.
Thanks and Regards,
Suganthyprabha. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|