IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Help on AVG function in SORT


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
RGiri

New User


Joined: 09 Nov 2009
Posts: 3
Location: Chennai, India

PostPosted: Tue Nov 10, 2009 10:51 am
Reply with quote

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
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Tue Nov 10, 2009 12:48 pm
Reply with quote

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
View user's profile Send private message
RGiri

New User


Joined: 09 Nov 2009
Posts: 3
Location: Chennai, India

PostPosted: Tue Nov 10, 2009 3:42 pm
Reply with quote

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
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Wed Nov 11, 2009 12:11 am
Reply with quote

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
View user's profile Send private message
RGiri

New User


Joined: 09 Nov 2009
Posts: 3
Location: Chennai, India

PostPosted: Wed Nov 11, 2009 9:31 am
Reply with quote

Frank Yaeger,

Thanks a lot for the clarification.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts Calling an Open C library function in... CICS 1
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
No new posts how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
Search our Forums:

Back to Top