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

maximum value

Former Member
0 Likes
2,336

hii,

how to find the maximum value from the internal table field for each personel number?

for ex.

field

1

2

3

i want 3 as output.

thanks

18 REPLIES 18
Read only

Former Member
0 Likes
2,068

Try sorting(desc)your internal table and pick the first record..

hope it helps.

Read only

Former Member
0 Likes
2,068

data: begin of it occurs 3,

val type i,

end of it.

it-val = 100.

append it sorted by val.

it-val = 400.

append it sorted by val.

it-val = 200.

append it sorted by val.

read table it index 1.

write: / it-val.

Regards

Jayapriya

Read only

Former Member
0 Likes
2,068

hi,

do you want to identify which cloumn has maximum value

Edited by: guest on Jan 28, 2009 9:33 AM

Read only

Former Member
0 Likes
2,068

HI,

SORT ITAB BY <FIELD> DESCENDING.
READ ITAB INDEX 1.

Read only

Former Member
0 Likes
2,068

Hi,

Try using

select MAX(field) from table.

Hope this helps.

Regards,

Deepthi.

Read only

Former Member
0 Likes
2,068

Hi,

U can use SORT statement to achieve this.

SORT <internaltable> BY fieldname DESCENDING .

Then take the first value of this internaltable.

This will be the max value.

Hope this helps u,.

Thanks.

Read only

Former Member
0 Likes
2,068

Hi

data: itab type table of ystudent with header line.

select * from ystudent into table itab.

sort itab descending by id descending.

read table itab index 1.

write itab-id.

Hope this helps

Regards,

Jayanthi.K

Read only

Former Member
0 Likes
2,068

SORT TABLE ITAB BY PERNR DESCENDING.

READ TABLE ITAB INTO WA INDEX 1.

WA-PERNR is the max number

Read only

Former Member
0 Likes
2,068

my code:

read table itab into wa with key pernr = was-pernr.

now where to write index 1.

thanks.

Read only

0 Likes
2,068

Hi

Please be clear in asking questions

Read only

0 Likes
2,068

ok i got it how to use index 1.

thanks

but output showing all 3 values in field , i want only one dats max

Read only

0 Likes
2,068

Hi,

Sort the table by pernr and the field.

sort itab descending by pernr field1.

read table itab into wa with key pernr = was-pernr.

Now after this read statement, you can read the maximum value record.

Read only

0 Likes
2,068

Hi,

After reading ur internal table using index.

u can move the value to another internal table know.

For ex:


SORT it_sum BY amount1 DESCENDING.

READ TABLE it_sum INTO wa_sum INDEX 1.
if sy-subrc eq 0.
  move: wa_sum-date to wa_res-date,
        wa_sum-amount1 to wa_res-amount1,
        wa_sum-amount2 to wa_res-amount2.
  append wa_res to it_res.
 endif.

Here the it_res table has the maximum value only.

Hope this helps u.

Thanks.

Read only

Former Member
0 Likes
2,068

Hello

try this

Select Max from Per into Lt_pers

After that you have only the biggest values

regards

Chris

Read only

0 Likes
2,068

but we can use (select max) with standard tables n not with internal table.

Read only

Former Member
0 Likes
2,068

thanks all of u.

Read only

0 Likes
2,068

Hi Aks,

If your field for which you want to get the maximun value is a integer field than just sort the internal table descending and read the first record as also told by others, like:

Sort itab by char descending.

Read table itab into wa index 1.

but is its not a integer field say its a character field with lenght more than 1, than its always better to change it to a interger field than get the maximun value otherwise it can give a incorrect value to you, as for character fields it will compare with the first character, like if the field value are '12' and '5', it will take '5' as greater as the first character in the second case is 5 and its greater than the first character of the first case which is 1.

With luck,

Pritam.

Read only

Former Member
0 Likes
2,068

Hi,

Just sort your internal table in descending order and read the first row.

SORT ITAB BY PERNR DESCENDING.

READ TABLE ITAB INDEX 1.

ITAB-PERNR will be the biggest in the internal table ITAB.

Mubeen

Edited by: Mubeen Ahmed on Jan 29, 2009 4:52 PM