Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert TIMESTAMPL (timestamp long) to TIMESTAMP ends with 60

Tags:

abap

I am having an OData Service returning some DateTime values. They are saved in a table in the back end as TIMESTAMPL (with some other data).

Now there is the value 20160630084459.5000. With MOVE-CORRESPONDING into the et_entityset, where it is a TIMESTAMP. Because of the rounding, it gets 20160630084460, Since a the seconds must be between 00 and 59, this is not a valid value to return.

My main problem is, that my table has extremely much entries, so I need a performant way to fix this error.

like image 909
inetphantom Avatar asked Oct 18 '22 06:10

inetphantom


1 Answers

First of all your TIMESTAMPL value is incorrect. The first eight positions do not conform to the YYYYMMDD pattern. So I assume it should be 20160630084459.5000 instead of 20163006084459.5000 (20160630 vs. 20163006).

Second of all here is a way to convert it to what you want.

REPORT zzy NO STANDARD PAGE HEADING.

FORM convert_timestamp.
  DATA(l_t1) = CONV timestampl('20160630084459.5000').
  DATA: l_t2 TYPE timestamp.
  l_t2 = l_t1.
  WRITE / : l_t1, l_t2.
  CONVERT TIME STAMP l_t1 TIME ZONE sy-zonlo INTO DATE DATA(l_date) TIME DATA(l_time).
  CONVERT DATE l_date TIME l_time INTO TIME STAMP l_t2 TIME ZONE sy-zonlo.
  WRITE / l_t2.
ENDFORM.

START-OF-SELECTION.
  PERFORM convert_timestamp.

Here is the output.

20.160.630.084.459,5000000
20.160.630.084.460
20.160.630.084.459

like image 175
Jagger Avatar answered Oct 21 '22 22:10

Jagger