Skip to Content
author's profile photo Former Member
Former Member

Best way to determine min and max date in a table

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 08, 2009 at 12:07 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 08, 2009 at 12:01 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 08, 2009 at 12:02 PM

    while fetching it from the data base use aggregate functions.

    SELECT MAX( date ) FROM mara INTO max_date

    WHERE mtart = 'HALB'.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 08, 2009 at 12:03 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 08, 2009 at 12:12 PM

    Wow, thx for the fast replies guys ...

    These are all really good hints !

    Awarded points !

    it was concerning an internal table btw.

    BR,

    ABjuh

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.