Application Development and Automation 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: 
Read only

Comparing dates in one internal table

Wil_Wilstroth
Active Participant
0 Likes
2,017

Hi guys,

I have an internal table with 3 fields. One of the fields is holding date.

I need to compare these dates in the internal table to find the latest.

Do you know any function module that can compare dates to find the latest in one internal table?

Thanks

William Wilstroth

William Wilstroth
5 REPLIES 5
Read only

Former Member
0 Likes
1,074

Why don't simply SORT the internal table by DATE DESCENDING and take the first row.

SORT ITAB BY DATE_COLUMN DESCENDING.

READ TABLE ITAB INDEX 1

Regards,

Ravi

Read only

Former Member
0 Likes
1,074

Sort the table using below command

sort i_table by date_field decending.

read i_table index 1.

Read only

Former Member
0 Likes
1,074

Hi William,

U can use this sample of code to get the latest among the three dates of an internal table.

DATA : BEGIN OF itab OCCURS 0,

date1 TYPE sy-datum,

date2 TYPE sy-datum,

date3 TYPE sy-datum,

END OF itab.

DATA : l_date TYPE sy-datum.

itab-date1 = '20061228'.

itab-date2 = '20061201'.

itab-date3 = '20061231'.

APPEND itab.

itab-date1 = '20060728'.

itab-date2 = '20060601'.

itab-date3 = '20060531'.

APPEND itab.

LOOP AT itab.

IF itab-date1 >= itab-date2.

IF itab-date1 >= itab-date3.

l_date = itab-date1.

ELSE.

l_date = itab-date3.

ENDIF.

ELSEIF itab-date2 >= itab-date3.

l_date = itab-date2.

ELSE.

l_date = itab-date3.

ENDIF.

WRITE : / l_date, sy-tabix.

ENDLOOP.

Hope it will help u in some way.

Read only

Former Member
0 Likes
1,074

HI

GOOD

I DONT THINK THERE IS ANY DATE FUNCTION MODULE WHO WILL COMPARE DATE IN A INTERNAL TABLE AND GIVE YOU THE RESULT.

TRY WITH

RH_GET_DATE_DAYNAME return the day based on the date provied

THANKS

MRUTYUN

Read only

Former Member
0 Likes
1,074

hi william,

u can use TIMESTAMP functionality for sort ur internal table , it sort bye date as well as timealso .

i hope it will help u.

with regard

chetan vishnoi