|
View previous topic :: View next topic
|
| Author |
Message |
RGiri
New User
Joined: 09 Nov 2009 Posts: 3 Location: Chennai, India
|
|
|
|
Hi,
I am trying to find the average of the quantity field from the input records. The SORT CARD that I coded is not displaying the decimal values correctly.
Below are the input records.
STR01-STK01-QTY01-TERR01
STR01-STK01-QTY02-TERR01
STR03-STK01-QTY03-TERR01
STR01-STK02-QTY01-TERR02
STR01-STK02-QTY02-TERR02
STR01-STK02-QTY03-TERR02
Below is the SORT CARD.
SORT FIELDS=(07,05,CH,A,19,06,CH,A)
OUTFIL FNAMES=SORTOUT,NODETAIL,
SECTIONS=(01,05,
TRAILER3=(01,25,C' TOT:',TOT=(16,02,ZD,EDIT=(TTT)),
C' CNT:',COUNT=(M11,LENGTH=02),
C' AVG:',AVG=(16,02,ZD,EDIT=(TT.TT))))
The output of the above SORT card is:
STR01-STK01-QTY02-TERR01 TOT:003 CNT:02 AVG:00.01
STR03-STK01-QTY03-TERR01 TOT:003 CNT:01 AVG:00.03
STR01-STK02-QTY03-TERR02 TOT:006 CNT:03 AVG:00.02
Expected output is:
STR01-STK01-QTY02-TERR01 TOT:003 CNT:02 AVG:01.50
STR03-STK01-QTY03-TERR01 TOT:003 CNT:01 AVG:03.00
STR01-STK02-QTY03-TERR02 TOT:006 CNT:03 AVG:02.00 |
|
| Back to top |
|
 |
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2482 Location: @my desk
|
|
|
|
Giri,
You may try the below card.
| Code: |
//SYSIN DD *
INREC OVERLAY=(81:16,2,ZD,MUL,+100,M11,LENGTH=8)
SORT FIELDS=(07,05,CH,A,19,06,CH,A)
OUTFIL FNAMES=SORTOUT,NODETAIL,
SECTIONS=(01,05,
TRAILER3=(01,25,C' TOT:',TOT=(16,02,ZD,EDIT=(TTT)),
C' CNT:',COUNT=(M11,LENGTH=02),
C' AVG:',AVG=(81,08,ZD,EDIT=(TT.TT))))
//* |
|
|
| Back to top |
|
 |
RGiri
New User
Joined: 09 Nov 2009 Posts: 3 Location: Chennai, India
|
|
|
|
Arun Raj,
Thank you. The SORT card that you gave is working and it is giving me the expected result.
But I am not sure why we are mutiplying the input data by 100 before averaging. Am I missing something about the AVG function? |
|
| Back to top |
|
 |
Frank Yaeger
DFSORT Developer

Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
AVG only displays an integer value, not a decimal value.
So if you have 21/8, it will be displayed as 2, not as 2.625. If you want to display the decimal part, you have to multiply by the appropriate value (e.g. +100 for two decimal places or +1000 for three decimal places). |
|
| Back to top |
|
 |
RGiri
New User
Joined: 09 Nov 2009 Posts: 3 Location: Chennai, India
|
|
|
|
Frank Yaeger,
Thanks a lot for the clarification. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|