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

date

Former Member
0 Likes
1,134

hi experts,

i got the dates in the internal table, how can i caluculate first oldest date and second oldest date.

Thanks and regards,

praveen

1 ACCEPTED SOLUTION
Read only

FredericGirod
Active Contributor
0 Likes
1,102

sort ...

just because SAP store the date with year first, month second ... you can sort the date to have the first and the second ..

Fred

12 REPLIES 12
Read only

Former Member
0 Likes
1,102

SORT table DESCENDING by date.

Read only

FredericGirod
Active Contributor
0 Likes
1,103

sort ...

just because SAP store the date with year first, month second ... you can sort the date to have the first and the second ..

Fred

Read only

Former Member
0 Likes
1,102

sort itab by date descending.

read table itab index 1.

itab-date is the oldest.

read table itab index 2.

itab-date is the 2nd oldest.

Read only

Former Member
0 Likes
1,102

Hi praveen,

sort the internal table by the date up or down.

than you can loop and gets the result.

Regards, Dieter

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,102

Hi, first sort your internal table by the date in descending order.

sort itab by datum descending.

Then simply read the first two lines to get the dates.

read table itab index 1.
if sy-subrc  = 0.
Write:/ 'This is the first oldest date', itab-datum'.
endif.

read table itab index 2.
if sy-subrc  = 0.
Write:/ 'This is the second oldest date', itab-datum'.
endif.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,102

Hi,

Sort the table in descending order .

Cheers

Read only

Former Member
0 Likes
1,102

Hi,

You can use

SORT ITAB BY DATE DESCENDING.

READ TABLE ITAB INDEX 1. "To get the first oldest date.

READ TABLE ITAB INDEX 2. "To get the second oldest date.

Thanks,

Naren

Read only

Former Member
0 Likes
1,102

Am I missing something? Shouldn't it be <b>ascending</b>?

Rob

Read only

0 Likes
1,102

Hi Praveen

Rob is right..

It should be Asscending

since descending will give latest dates and not the oldest dates

Just take care while coding...

Read only

0 Likes
1,102

Right, its all in how you view the question, does oldest mean farthest away from current, or the most current.

Regards,

Rich Heilman

Read only

0 Likes
1,102

So if management asked you to archive the oldest documents you would ask if they meant "farthest away from current, or the most current"?

Rob

Read only

0 Likes
1,102

In that case, I would say farthest. Your point is very clear, Rob.

Regards,

Rich Heilman