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

Max Values From internal table

Former Member
0 Likes
6,611

Hi,

I have following data into internal tab as

item1 item2 item3 value

A a a1 10

A a a1 20

A a a1 30

B b b1 50

B b b1 60

B b b1 50.

C c c1 6.

C c c1 7.

Now i want output as max values only.

item1 item2 item2 value

A a a1 30

B b b1 60

C c c1 7.

i can do it during select query and then save into internal table.but requirement is after pulling data into internal tab,then trying to find max value.

Thanks..

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,043

Hi,

try this.

declare an another internal table itab1.

SORT itab by item1 value descending.

loop at itab.

read table itab1 with key item1 = itab-item1 item2 = itab-item2 item3 = itab-item3.

if sy-subrc eq 4.

move records to itab1.

endif.

Edited by: Sathish Reddy on Jan 22, 2009 10:53 AM

7 REPLIES 7
Read only

Former Member
0 Likes
2,043

Hi,

First sort internal table in desending order and take first reord of the each block record Use controlling commads.

Regards

Md.MahaboobKhan

Read only

Former Member
0 Likes
2,043

This is just a suggetsion. i have not tried my code yet. Have two internal tables. In one, copy all the values.The second internal table needs to have an additional field to calculate the sum. In the second, loop through the first internal table and keep adding when the item ID is same into the additional field.

Hope this helps.

Thanks,

Saipriya

Read only

peter_ruiz2
Active Contributor
0 Likes
2,043

Hi anwar,

1. Sort your table like this


SORT TABLE itab BY item1 item2 item3 value

2. Loop at your table to retrieve the highest value like this


DATA: end3 TYPE c.

LOOP AT itab INTO wa.
AT END OF item3.
  MOVE 'X' TO end3.
ENDAT.

IF item3 EQ 'X'.
  WRITE: item1, item2, item3, value.

  CLEAR item3.
ENDIF.
ENDLOOP.

regards,

Peter

Read only

Former Member
0 Likes
2,043

Hi,

Sort the internal table in desending order and Check first record from each block of recordsUse At commad in taht if condition.

Regards

Md.MahaboobKhan

Read only

Former Member
0 Likes
2,044

Hi,

try this.

declare an another internal table itab1.

SORT itab by item1 value descending.

loop at itab.

read table itab1 with key item1 = itab-item1 item2 = itab-item2 item3 = itab-item3.

if sy-subrc eq 4.

move records to itab1.

endif.

Edited by: Sathish Reddy on Jan 22, 2009 10:53 AM

Read only

Former Member
0 Likes
2,043

Hi

Sort the ITAB by item1 item2 item3 ascending value descending

then use delete adjacent duplicates from ITAB comparing item1 item2 item3 value.

This will have only max value record based on value.

Regards

Shiva

Read only

Former Member
0 Likes
2,043

Thanks ALL.its done