Application Development and Automation 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: 
Read only

Internal table

Former Member
0 Likes
795

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
Read only

Former Member
0 Likes
779

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
Read only

Former Member
0 Likes
780

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

Read only

0 Likes
779

MAX() on internal tables? Howto?

Read only

Former Member
0 Likes
779

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

Read only

Former Member
0 Likes
779

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.

Read only

Former Member
0 Likes
779

1) sort itab by decending order.

2)read table itab into wa.

3)wa-field1.(max value)

Read only

Former Member
0 Likes
779

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

Read only

Former Member
0 Likes
779

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.

Read only

rainer_hbenthal
Active Contributor
0 Likes
779

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.