‎2007 Jan 16 4:46 PM
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
‎2007 Jan 16 4:53 PM
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
‎2007 Jan 16 4:55 PM
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
‎2007 Jan 16 4:54 PM
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
‎2007 Jan 16 4:55 PM
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
‎2007 Jan 16 5:00 PM
‎2007 Jan 16 5:03 PM
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.
‎2007 Jan 16 5:05 PM
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