‎2006 Mar 31 11:12 AM
Hi all,
i have a Internal table with two fields and i need to findout maximum value of the field value.
how can i do tht
plese help me
thanks
sai
‎2006 Mar 31 11:14 AM
Hi,
Sort the table by ascending/descending order on the respective columns.. the first row in itab will give the least/largest value.
Also there is an Func. MAX. But it works on N, I, P types.
MAX(column1) gives maximum of column1
Regards,
Anjali
‎2006 Mar 31 11:14 AM
Hi,
Sort the table by ascending/descending order on the respective columns.. the first row in itab will give the least/largest value.
Also there is an Func. MAX. But it works on N, I, P types.
MAX(column1) gives maximum of column1
Regards,
Anjali
‎2006 Mar 31 3:05 PM
‎2006 Mar 31 11:15 AM
Sai,
SORT the table by the field in question and read the first row.
SORT table by Column1 descending.
read table into workarea index 1.
The value in the workarea will be the maximum one.
Regards,
Ravi
Note : Please mark the helpful answers
‎2006 Mar 31 11:15 AM
YOu wqant oto compare the two fields or you want the maximum value in all the records?
i think you want the second:
loop at itab.
if itab-field > l_max.
l_max = itab-field.
endif.
endloop.
at the end of the loop, you will have the max value in l_max.
‎2006 Mar 31 11:15 AM
1) sort itab by decending order.
2)read table itab into wa.
3)wa-field1.(max value)
‎2006 Mar 31 11:32 AM
Hi
As per your question you want to know the the field name which contain maximum value.
so you can TRY OUT THIS LIGIC
REPORT ztemp .
TYPES: BEGIN OF line,
brand(10) TYPE c,
rate(3) TYPE p DECIMALS 2,
gender(1) TYPE c,
sno TYPE i,
desc(30) TYPE c,
END OF line.
DATA: it_lines_1 TYPE TABLE OF line
WITH KEY brand
rate
gender,
wa_lines_1 LIKE LINE OF it_lines_1.
DATA: it_lines_2 TYPE TABLE OF line
WITH KEY brand
rate
gender,
wa_lines_2 LIKE LINE OF it_lines_2.
DATA: gi_counter TYPE i.
START-OF-SELECTION.
PERFORM fill_it_line_1. " not included; tested with your 4 records
SORT it_lines_1.
CLEAR gi_counter.
LOOP AT it_lines_1 INTO wa_lines_1.
wa_lines_2 = wa_lines_1.
ADD 1 TO gi_counter.
AT END OF gender.
IF gi_counter > 1.
APPEND wa_lines_2 TO it_lines_2.
ENDIF.
CLEAR gi_counter.
ENDAT.
ENDLOOP.
i HOPE THIS WILL HELP YOU TO SOLVE YOR PROBLEM
THANKS
MRUTYUNJAYA TRIPATHY
‎2006 Mar 31 3:23 PM
Hi Sai,
I think you can use MAX keyword as an addition in your SELECT statement.
For eg:
DATA: CARRID TYPE SFLIGHT-CARRID,
MINIMUM TYPE P DECIMALS 2,
MAXIMUM TYPE P DECIMALS 2.
SELECT CARRID MIN( PRICE ) MAX( PRICE )
INTO (CARRID, MINIMUM, MAXIMUM)
FROM SFLIGHT
GROUP BY CARRID.
WRITE: / CARRID, MINIMUM, MAXIMUM.
ENDSELECT.
the output of this code I got is
DL 100.00 100,000.00
LH 14.00 234,560.00
RAJ 0.00 849.00
so it will select each value of 'DL', 'LH' and raj and compare the various values of each and maximum will be displayed.
I suppose your query is solved.
If so , please close the thread by awarding points to helpful answers.
Regards,
Sylendra.
‎2006 Mar 31 3:42 PM
Sorting is a bad idea. Sorting needs O(log(n)n) to O(nn) cycles to get the tabl sorted. Just went thru it and compare the actiual value with the first one The first one is accessible thur read index 1.
This is only O(n) and the fastest way.