Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Aggregate functions usage

Former Member
0 Kudos

Hi ! In my ALV report, added a custom net rate column. Now, I want to find out the minimum, maximum and average values from that custom nat rate colum. How that can be acheived.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Goen ,

Say suppose your IT_FINAL is the final Internal Table.

if your Final table getting data from Single table , you can use Aggregate function directly. Please refer the below link for the same.

[http://www.thespot4sap.com/articles/SAPABAPPerformanceTuning_AggregateFunctions.asp]

if not from single table. Go by the below method.

You can use SORT statement for finding the Minimum and Maximum Net rate.


SORT IT_FINAL BY NET_RATE.

READ TABLE IT_FINAL INDEX 1.
if sy-subrc is initial.
"IT_FINAL-NET_RATE will be the Minimum one
Endif.

SORT IT_FINAL BY NET_RATE DESCENDING.

READ TABLE IT_FINAL INDEX 1.
if sy-subrc is initial.
"IT_FINAL-NET_RATE will be the Maximum one
Endif.

for getting average value , You need to sum all the entries NET RATE and then Divide by Number of entries of table.

3 REPLIES 3

Former Member
0 Kudos

Hi Goen ,

Say suppose your IT_FINAL is the final Internal Table.

if your Final table getting data from Single table , you can use Aggregate function directly. Please refer the below link for the same.

[http://www.thespot4sap.com/articles/SAPABAPPerformanceTuning_AggregateFunctions.asp]

if not from single table. Go by the below method.

You can use SORT statement for finding the Minimum and Maximum Net rate.


SORT IT_FINAL BY NET_RATE.

READ TABLE IT_FINAL INDEX 1.
if sy-subrc is initial.
"IT_FINAL-NET_RATE will be the Minimum one
Endif.

SORT IT_FINAL BY NET_RATE DESCENDING.

READ TABLE IT_FINAL INDEX 1.
if sy-subrc is initial.
"IT_FINAL-NET_RATE will be the Maximum one
Endif.

for getting average value , You need to sum all the entries NET RATE and then Divide by Number of entries of table.

0 Kudos

Thanks a lot. The MAX rate is coming perfectly fine. But, the MIN rate is giving problem, because several lines of the NET RATE are 0. Please help.

0 Kudos

HI Goen ,


"Declare one more ITAB IT_FINAL_TMP with same structure of IT_FINAL.

"Copy the data to new ITAB for data manipulations
IT_FINAL_TMP[] = IT_FINAL[].

" Delete the entries which  are having net rate as Zero
delete ITAB IT_FINAL_TMP where NET_RATE is initial. " Write appropriate Where condition

"Use IT_FINAL_TMP for finding the MIN Value

SORT IT_FINAL_TMP BY NET_RATE.
 
READ TABLE IT_FINAL_TMP INDEX 1.
if sy-subrc is initial.
"IT_FINAL_TMP-NET_RATE will be the Minimum one
Endif.

Edited by: Prasath Arivazhagan on May 27, 2010 8:48 AM