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: 

Deleting records from internal table using formatted timestamp

0 Kudos
TYPES: BEGIN OF ty_tbl,

        v1 TYPE string,

       END OF ty_sum.



DATA: lt_tbl TYPE STANDARD TABLE OF ty_sum,

      ls_tbl TYPE ty_sum.


ls_sum-v1 = '09/10/2018 23.22.10.120'.

APPEND ls_sum to lt_sum.

ls_sum-v1 = '08/12/2015 03.22.10.120'.

APPEND ls_sum to lt_sum.


ls_sum-v1 = '09/10/2016 23.22.10.120'.

APPEND ls_sum to lt_sum.

ls_sum-v1 = '07/10/2017 23.22.10.120'.

APPEND ls_sum to lt_sum.



DELETE lt_sum WHERE v1 NOT BETWEEN '09/01/2018' AND '09/30/2018'.

Here, I want that internal table should have data that are specified in the date range and return just the counts.

But delete statement returns 2 records instead of 1, as it compares '09' and rest of the string is ignored.

Note: I have tried with both formatted date and timestamp. These timestamps are directly extracted and populated in the internal table in actual in STRING format.

5 REPLIES 5

DoanManhQuynh
Active Contributor

you comparing string so that is what you get, if you want to compare as a date or timestamp, your field v1 should have date or timestamp type. i dont know how did you populate data but i dont think timestamp will converted into string.

0 Kudos

Agree. I am comparing the string basically not the timestamp, but is there an alternate way to this?

0 Kudos

vireshdshah : if your source data have string type with it own format, you have to split the string to create date, and time (with type DATS and TIMS) then you convert to timestamp (type: TIMESTAMP) with statement CONVERT TIME STAMP. you may add extra timestamp field in your table to do it or you can loop through the table, assign to help variable and compare.

maheshpalavalli
Active Contributor
0 Kudos

I think it would be best to pass the timestamp to a timestamp type field and do the delete operation.

internal table data is having both the date and time, so you have to use the below statement to get timestamp for date and time.

https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abapconvert_date_time-stamp.htm

dont forget to pass the same timestamp conversion date to the where condition in delete operation

BR,

Mahesh

0 Kudos

Thank you all closing