How to create an KSQL Timestamp in ABAP ?
ISO Extended is not enough.
"timestamp":"2022-02-07T08:35:02,4595190",
I need this ..
"timestamp": "2021-03-23T14:00:04.893888792Z",
Who has an idea ?
CodePudding user response:
Use TIMESTAMPL data type. "2021-03-23T14:00:04.893888792Z" is just external presentation. It's 20210323140004.893888792 inside
CodePudding user response:
"timestamp":"2022-02-07T08:35:02,4595190"
I assume that is a typo. Looks like json output and The SAP Standard JSON conversion of TZNTSTMPL uses decimal point.
You may also have fun dealing with time fields and initial dates. I had to write converters to handle the output.
If you are using the identity transformation approach, something like this,
" get a JSON writer
lo_writer = cl_sxml_string_writer=>create(
type = if_sxml=>co_xt_json
no_empty_elements = i_suppress_initial ).
CALL TRANSFORMATION id SOURCE json_root_node = myAbapStru
RESULT XML lo_writer
l_xstring = lo_writer->get_output( ).
lo_converter = cl_abap_conv_in_ce=>create(
input = l_xstring
encoding = 'UTF-8' ).
lo_converter->read( EXPORTING n = lv_length
IMPORTING data = r_string ).
Then you get the output in SAPs interpretation of JSON Standard. Which is unfortunately valid in ISO8601. Since ALL timestamps in sap are in UTC the Z can be dropped :(
You may need to parse/fix the resulting JSON string before sending it. I ended up fixing the result at the other end. In c# using NetwonSoft Datatype converters
