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: 

How to select maximum date out of the entries I got for the given input.

Former Member
0 Kudos
6,251

Hi ,

Can any one please help how to select maximum or latest entry of the date out of the 6 or 7 entries i got for the given input as say for instance sy-datum(14-07-2008).

Thanks in advance

1 ACCEPTED SOLUTION

Former Member
0 Kudos
744

If it is in internal table. Sort the internal table by descending and pick the first record.

Sort itab by datum descending.

Read table itab into ws_itab index 1.

If you need to read from database tgable, use the statement MAX( ERDAT ) in your select statement.

Regards,

Subramanian

6 REPLIES 6

Former Member
0 Kudos
745

If it is in internal table. Sort the internal table by descending and pick the first record.

Sort itab by datum descending.

Read table itab into ws_itab index 1.

If you need to read from database tgable, use the statement MAX( ERDAT ) in your select statement.

Regards,

Subramanian

Former Member
0 Kudos
744

Hi johny ,

As you said you are taking input values from user thrugh the selection screen,what you can do is save each input in an internal table and then sort the internal tabledescending by date. This gives you the latest entry.

Best of luck,

Bhumika

Former Member
0 Kudos
744

Hi Johny,

Try this code :

SELECT-OPTIONS:
  s_date FOR sy-datum.


SORT s_date BY low DESCENDING.

LOOP AT s_date.

  READ TABLE s_date INDEX 1.

  WRITE 😕 s_date-low.

ENDLOOP.

For the select-options s_date give some values and check. It will fetch you the latest date among the entries you gave as input.

Regards,

Swapna.

Former Member
0 Kudos
744

Hi,

You can also ORDER BY Statement in your Select Query to get the the data into Internal table in Date Descending-

Like-

Select * from Ztable into table itab ORDER BY Date DESCENDING.

In This case you will get First the Record with Latest Date.

Hope it will help you.

Regards,

Sujit

Former Member
0 Kudos
744

hi,

If you have used your date field as a Select-options then

you can access maximum date using this satatement.

write <fieldname>-high.

Former Member
0 Kudos
744

Answered