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: 

Best way to determine min and max date in a table

Former Member
0 Kudos

Hi gurus,

I have this table with 2 fields startdate and finishdate :

startdate                finishdate
01.01.2009               06.01.2009
02.02.2009               07.02.2009
03.03.2009               08.03.2009
04.04.2009               09.04.2009

I would like to determine :

the minimum date in field startdate

the maximum date in field finishdate.

What is the best way to do that ? Perhaps any functionmodule suggestions ?

Thanks in advance friends,

Abjuh.

Edited by: Abjuh Nahasapee on Sep 8, 2009 1:54 PM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Abjuh,

if you have internal table with two fields then

first thing sort your internal table with start date ascending

and then take that date into a variable

second thing sort your internal table with end date descending

and then take that date into another variable.

Regards,

Vijay

5 REPLIES 5

Former Member
0 Kudos

Hi,

If its a database table, use the aggregate functions,


select max( startdate ) into itab from DBtable.

If its a internal table use sort by descending.


sort itab by startdate descending.

The first record will have the max start date.

Similarly you can do the same for finishdate.

Regards,

Vikranth

Former Member
0 Kudos

while fetching it from the data base use aggregate functions.

SELECT MAX( date ) FROM mara INTO max_date

WHERE mtart = 'HALB'.

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

If you have data in internal table,

sort itab by startdate.

and then read the index 1 record for getting minimum date.

sort itab by finishdate descending.

and then read the index1 record for getting maximum date.

Former Member
0 Kudos

Hi Abjuh,

if you have internal table with two fields then

first thing sort your internal table with start date ascending

and then take that date into a variable

second thing sort your internal table with end date descending

and then take that date into another variable.

Regards,

Vijay

Former Member
0 Kudos

Wow, thx for the fast replies guys ...

These are all really good hints !

Awarded points !

it was concerning an internal table btw.

BR,

ABjuh