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: 

to find the latest date and latest time

Former Member
0 Kudos

hi all

I have a ZTABLE which contains fields as NAME, DATE ,TIME and STATUS. Entries are

Eg: ztest 01.01.2005 12:05:10 1

ztest 12.01.2005 15:05:10 1

ztest1 23.01.2005 12:05:10 1

ztest1 05.04.2005 05:05:10 1

ztest1 15.10.2005 05:05:10 1

ztest1 15.10.2005 15:05:10 1

Now I need to fetch the latest data and latest time. So I need ztest1 15.10.2005 15:05:10 1.

How can we retrieve it. Even If i use SORT ZTABLE BY DATE TIME DESCENDING I am not getting the lastest date and latest time

Kinldy help

Points will be rewarded

Thanksin advance

7 REPLIES 7

Former Member
0 Kudos

You need to define the table fields for date with types D (LIKE SY-DATUM) and for those with time LIKE SY-UZEIT. Then only sorting will be meaningful. Also ensure that the fields are formatted in DDMMYYYY for date and HHMMSS for time, these are the interal representations for date and time and sorting will then respect them

SORT ZTABLE BY DATE DESCENDING TIME DESCENDING

If ZTABLE is a database table, first fetch the records to a internal table using

SELECT * FROM ZTABLE INTO ITAB WHERE ...

then SORT ITAB BY DATE DESCENDING TIME DESCENDING

former_member533584
Contributor
0 Kudos

hai,

try this once.

SORT ZTABLE BY DATE DESCENDING TIME DESCENDING

Former Member
0 Kudos

hi,

You need to define the table fields for date with types D (LIKE SY-DATUM) and for those with time LIKE SY-UZEIT

and use SORT ZTABLE DESCENDING BY DATE TIME

Former Member
0 Kudos

you cannot sort a ZTABLe

try this..

select max( date ) into v_date from ztable.

select max( time ) into v_time from ztable.

Former Member
0 Kudos

Hi Jayasree,

You should use SORT ZTABLE BY DATE DESCENDING TIME DESCENDING. Because for field DATE if the order is not specified, it will be sorted in ASCENDING order which is default sorting order.

Regards,

Vishnu Priya

Former Member
0 Kudos

Hi Jayasree,

Please refer the link,

Regards,

Hema.

    • Reward points if it is useful.

Former Member
0 Kudos

SELECT -


FROM ZTABLE INTO ITAB WHERE condition ...

then

SORT ITAB BY <b>DATE DESCENDING TIME DESCENDING</b>

Read itab index 1.

" for the latest hit .

so this will fetch the latest entry on date and time .

You need to do the operation on internal table .

regards,

vijay