1

Valid JSON data types do not include dates. So why is SAP adding '-' ?

   data:
        lo_writer type ref to cl_sxml_string_writer,
        lo_xmldoc type ref to if_ixml_document,
        lv_xml type string,
        l_xstring type xstring,
        l_descr_ref type ref to cl_abap_typedescr.

   lo_writer = cl_sxml_string_writer=>create( type = if_sxml=>co_xt_json
                                             no_empty_elements  = '' ).

   call transformation id source JSON_ROOT_NODE = SY-DATUM
                         result xml lo_writer.

   l_xstring  = lo_writer->get_output( ).

   r_json = /AXO/MC_Tools=>xstring2string(  i_xstring     = l_xstring
                                           i_encoding    = 'UTF-8'   ).

Result "YYYY-MM-DD" instead of "YYYYMMDD"

Why ? How can I fix this ?

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
phil soady
  • 11,043
  • 5
  • 50
  • 95

1 Answers1

3

You are right that JSON does not define a data type. SAP chose to represent a date as a string, which is a perfectly valid choice and conforms at least partially to the ISO 8601 approach favored by other implementations. I do not believe there is anything to "fix" here other than perhaps the receiving application.

vwegert
  • 18,371
  • 3
  • 37
  • 55
  • Given that Javascript does and that many use 8601 then you could argue SAP has done it correctly. Unfornately I cant change the consumer expecting YYYYMMDD. https://www.w3.org/TR/NOTE-datetime – phil soady Jul 14 '17 at 14:09