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: 

Minimum value

former_member423024
Participant
0 Kudos
917

Hi Gurus,

I have 2 small requirements for my object.

1)I have to select the Minimum value of field AUFNR from table AUFK. Is there any command for that instead of using a select query.

2)Also i have to extract the common values from 2 internal tables and then I have to select the minimum value.

Could anyone let me know about the solution for the above 2 issues.

Thanks

Natasha SS.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
643

Hi,

1) As far as I know, you can do it using two ways.

Write a select query using aggregate function MIN and select the data.

Alternatively, you can select all the data from the table into an internal table and sort it ascending based on the required field and get the value from the first record.

2) For your second query, try something like this. Its just a skeleton.


sort itab1 by field1 field2.
sort itab2 by field1 field2.
loop at itab1 into wtab1.
at new wtab1-field1. "This will happen only for every new value of field1. 
  read table itab2 into wtab2 with key = wtab1-field1.
  lv_tabix = sy-tabix.
  loop at itab2 into wtab2 from lv_tabix. 
   append wtab2 to it_temp. "Or append the required fields
  endloop.
endat.
append wtab1 to it_temp.
endloop.

3 REPLIES 3

Former Member
0 Kudos
643

HI Natasha,

Press F1 on these : SELECT , MIN , INNER JOIN.

Select with min , will help you to get minimum value from the database table.

And if you will make a combination of Inner join also , you can get value from two tables.

Edited by: Harsh Bhalla on Nov 17, 2009 5:10 PM

Former Member
0 Kudos
644

Hi,

1) As far as I know, you can do it using two ways.

Write a select query using aggregate function MIN and select the data.

Alternatively, you can select all the data from the table into an internal table and sort it ascending based on the required field and get the value from the first record.

2) For your second query, try something like this. Its just a skeleton.


sort itab1 by field1 field2.
sort itab2 by field1 field2.
loop at itab1 into wtab1.
at new wtab1-field1. "This will happen only for every new value of field1. 
  read table itab2 into wtab2 with key = wtab1-field1.
  lv_tabix = sy-tabix.
  loop at itab2 into wtab2 from lv_tabix. 
   append wtab2 to it_temp. "Or append the required fields
  endloop.
endat.
append wtab1 to it_temp.
endloop.

Former Member
0 Kudos
643

Hi,

Using select query we can get the minimum value as ahown.

data: l_aufnr(12) type c.

select min( AUFNR ) into l_aufnr from aufk.

write: l_aufnr.

Is there any specific reason of not using select query ?

Orelse you can use sort keyword to sort the records according to ascending or decending by which you can get

the minimum value. Use the below link for more info

http://help.sap.com/saphelp_nw70/helpdata/EN/66/bc7ad243c211d182b30000e829fbfe/content.htm

Regards

VEnk@

Edited by: Venkat Reddy on Nov 17, 2009 5:33 PM