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: 

Internal table

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

8 REPLIES 8

Former Member
0 Kudos

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

0 Kudos

MAX() on internal tables? Howto?

Former Member
0 Kudos

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

former_member181962
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

1) sort itab by decending order.

2)read table itab into wa.

3)wa-field1.(max value)

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

rainer_hbenthal
Active Contributor
0 Kudos

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.