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: 

Finding greatest value of date in a table

Former Member
0 Kudos

Hi experts,

I have many dates in an internal table.How to find min and max dates of these.

Is there any FM or i have to write logic.

Please help.

Krishan

1 ACCEPTED SOLUTION

vinod_vemuru2
Active Contributor
0 Kudos

Hi Krishan,

Adding to pavan ans....

SORT itab BY date.

DESCRIBE TABLE itab LINES l_lines. "Get total number of lines in itab.

READ TABLE itab INTO wa INDEX 1 TRANSPORTING date. "Read first entry

Here wa-date have Min date value.

READ TABLE itab INTO wa INDEX l_lines TRANSPORTING date. "Read last entry

Here wa-date Have Max date value.

Thanks,

Vinod.

5 REPLIES 5

bpawanchand
Active Contributor
0 Kudos

HI

I don't know about the FM but the logic is very simple all you have to do is sort the internal table in Ascending order by DATE the first index, I mean the first entry in the table will be the min and the last entry in the internal table will be the Maximum.

Regards

Pavan

0 Kudos

Hi Pawan,

Thanks a lot for ur immediate response. Problem Solved.

vinod_vemuru2
Active Contributor
0 Kudos

Hi Krishan,

Adding to pavan ans....

SORT itab BY date.

DESCRIBE TABLE itab LINES l_lines. "Get total number of lines in itab.

READ TABLE itab INTO wa INDEX 1 TRANSPORTING date. "Read first entry

Here wa-date have Min date value.

READ TABLE itab INTO wa INDEX l_lines TRANSPORTING date. "Read last entry

Here wa-date Have Max date value.

Thanks,

Vinod.

0 Kudos

Hi Vinod,

Thanks a lot. Problem Solved.

Former Member
0 Kudos

Hi,

You can do as below :



"Get the max date
sort itab by date descending.

Read table itab index 1.

write : /itab-date.  "MAx date.

sort itab by date ascending.

Read table itab index 1.

write : /itab-date.  "Min date.

Thanks,

Sriram Ponna.