04-21-2008 9:41 PM
How to find the third largest value in internal table.
please give me logic without using sort statement?
and how to find the 3rd largest value with using sort on internal table.
please give the both logic separately?
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Apr 21, 2008 5:28 PM
04-21-2008 9:45 PM
>SORT TABLE DESCENDING BY Value.
>DELETE ADJACENT DUPLICATES COMPARING value.
>READ table INDEX 3 INTO wa.*
Other way would be to loop over table after sort.
loop at table into wa.
at new value.
add 1 to counter.
if counter = 3.
here is 3rd largets value.
endif.
endat.
endloop.
04-21-2008 9:55 PM
First sort the internal table. and read the 3 record by index.
if duplicate exists use delete adjacent duplicates and read the 3 record.
second method.
loop at itab into wa_itab.
if sy-tabix = 1.
lv_high = wa_itab-value.
else.
if lv_high > wa_itab-value.
else.
lv_high = wa_itab-value.
endif.
endif.
endloop.
loop at itab into wa_itab < lv_high.
if sy-tabix = 1.
lv_sechigh = wa_itab-vlaue.
else.
if lv_shigh > wa_itab-value.
else.
lv_sechigh = wa_itab-value.
endif.
endif.
endloop.
loop at itab into wa_itab < lv_sechigh.
if sy-tabix = 1.
lv_thirdhigh = wa_itab-vlaue.
else.
if lv_thirdhigh > wa_itab-value.
else.
lv_thirdhigh = wa_itab-value.
endif.
endif.
endloop.
04-22-2008 7:15 AM
Hello Sanjeev-
For retrieving 3rd largest value.
1st you need to sort the itab.
2nd read with index 3.
sort itab.
read table itab into workarea index 3.
Cheers,
~Srini....