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: 

Reading highest value out of internal table

Former Member
0 Kudos

Hi all,

It feels like a bit of a newbie question, but does anyone know an appropriate way to read the highest value of a field in an internal table? For instance simular to ..select max.. for DB selections?

I can of course sort the table on that field and do a read table with index = 1, but that doesn't look very pretty. A function module which does the trick would be most appreciated.

Kind regards,

Martijn de Jong.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi M.,

1. There is no direct FM to do it.

2. We need to use our own logic.

3. One way is :

SORT ITAB by field1 DESCENDING.

READ ITAB INDEX 1.

regards,

amit m.

5 REPLIES 5

Former Member
0 Kudos

Hi M.,

1. There is no direct FM to do it.

2. We need to use our own logic.

3. One way is :

SORT ITAB by field1 DESCENDING.

READ ITAB INDEX 1.

regards,

amit m.

Former Member
0 Kudos

Hello,

There is no FM to do this operation and further SORT and read is always better in performance than FM which is going to use some memory and finally going to do the same.

former_member188685
Active Contributor
0 Kudos

Hi Jong,

<i>I can of course sort the table on that field and do a read table with index = 1, but that doesn't look very pretty.</i>

who said it doesn't look pretty.

that logic which you have is the way you should proceed.

There is no FM for this , try Putting the logic in side new FM and call it if you want.

Regards

vijay

Former Member
0 Kudos

Hi M. de Jong,

When you call a function module, the current contents are pushed into stack, the control moves to the function module, function is executed , the control returns back to main program and contents are poped out of the stack..

If u see, this requires more space and time complexity..

Although function modules are always gud n easy to use,

in this case, thats not the alternative..

So its always better off to do the work using sort descendng and READ.

Regards,

Tanveer.

Please mark helpful answers..

Former Member
0 Kudos

Okay,

I'm convinced. Performance of course should not suffer from my urge to deliver pretty code.....

All thnx for the fast input, i'll keep my "sort and read with index 1" sollution.

Kind regards,

Martijn de Jong.