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

finding lowest dates

Former Member
0 Likes
887

Dear experts,

I have an internal table with the date field . I need to delete all the dates except the least date in the Internal table list.

Can anyone send the code for this.

thanks in advance

karthik

7 REPLIES 7
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
826

You can try something like this.



report zrich_0001.

types: begin of t_datum,
       datum type sy-datum,
       end of t_datum.
data: i_datum type table of t_datum.
data: x_datum like line of i_datum.

x_datum-datum = '20060112'.  append x_datum to i_datum.
x_datum-datum = '20060112'.  append x_datum to i_datum.
x_datum-datum = '20060102'.  append x_datum to i_datum.
x_datum-datum = '20060102'.  append x_datum to i_datum.
x_datum-datum = '20060103'.  append x_datum to i_datum.
x_datum-datum = '20060103'.  append x_datum to i_datum.
x_datum-datum = '20060104'.  append x_datum to i_datum.
x_datum-datum = '20060104'.  append x_datum to i_datum.
x_datum-datum = '20060104'.  append x_datum to i_datum.

sort i_datum ascending by datum.

read table i_datum into x_datum index 1.
delete i_datum where datum <> x_datum-datum.

check sy-subrc  = 0.

Regards,

Rich Heilman

Read only

0 Likes
826

Hi

Sort the table in ascending order.

then delete all the contents of the table and make one condition that sy-index <> 1.

This is work

Read only

Former Member
0 Likes
826

Hi,

sort the internal table and delete the other records..

Example

-


SORT ITAB BY DATE.

DESCRIBE TABLE ITAB.

DELETE ITAB FROM 2 TO SY-TFILL.

Thanks,

Naren

Read only

Former Member
0 Likes
826

Hi,

A complete example

DATA: BEGIN OF ITAB OCCURS 0,

DATE TYPE SYDATUM,

END OF ITAB.

ITAB-DATE = SY-DATUM + 1.

APPEND ITAB.

ITAB-DATE = SY-DATUM.

APPEND ITAB.

ITAB-DATE = SY-DATUM - 1.

APPEND ITAB.

SORT ITAB BY DATE.

DESCRIBE TABLE ITAB.

DELETE ITAB FROM 2 TO SY-TFILL.

DESCRIBE TABLE ITAB.

WRITE: / SY-TFILL.

Thanks,

Naren

Read only

0 Likes
826

Naren, but what if there are multiple occurances of the lowest date and he wants to keep all of the records for that lowest date?

Regards,

RIch Heilman

Read only

0 Likes
826

Hi Rich,

We can go for sorting of the table in ascending order now date of index 1 should be stored in some var and while deleting the table content we should make sure that the date should not be equal.

if equal then leave the record in the table.

I guess this is the solution . but if you have any then please tell us.

Read only

Former Member
0 Likes
826

Hi Rich,

You are correct..:-)).If there are mulitple records with the same least date..Then my code will delete all the other records other than the first record..

My code will work if the least date record is having only one record..

Thanks,

Naren