Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Data Interfaces and Communication Interfaces →  ABAP and XML →  Transformations for XML →  ST - Simple Transformations →  ST - Serialization and Deserialization →  ST - Transformation of ABAP Values →  ST - tt:value, Elementary Data Objects →  ST - option, Mapping Rules →  ST - option, Mapping Rules for Elementary Types 

Simple Transformation, Option for Decimal Places

This example demonstrates the display of numeric ABAP types and the time stamp type utclong with specifications for decimal places.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    utclong = utclong_current( ).
    timestmpl = cl_abap_tstmp=>utclong2tstmp( utclong ).
    datetimel = timestmpl.

    DATA(out) = cl_demo_output=>new( )->next_section( 'XML' ).
    DATA(writer) = cl_sxml_string_writer=>create(
            type = if_sxml=>co_xt_xml10 ).
    call_transformation( CHANGING writer = writer ).
    DATA(result) = writer->get_output( ).
    out->write_xml( result
       )->next_section( 'JSON' ).
    writer = cl_sxml_string_writer=>create(
      type = if_sxml=>co_xt_json ).
    call_transformation( CHANGING writer = writer ).
    result = writer->get_output( ).
    out->write_json( result
      )->display( ).

Description

This example passes various types of numeric ABAP data including the time stamp to the transformation DEMO_ST_DECIMALS_OPTION and provides the result for XML and JSON. The transformation applies the option decimals to the ABAP data:

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  <tt:root name="INTEGER"/>
  <tt:root name="PACK"/>
  <tt:root name="DECF"/>
  <tt:root name="BINF"/>
  <tt:root name="UTCLONG"/>
  <tt:root name="TIMESTMPL"/>
  <tt:root name="DATETIMEL"/>
  <tt:template>
    <array>
      <object>
        <str name="decimals(2) for INTEGER">
          <tt:value option="decimals(2)"
                    ref="INTEGER"/>
        </str>
        <str name="decimals(2) for PACK">
          <tt:value option="decimals(2)"
                    ref="PACK"/>
        </str>
        <str name="decimals(2) for DECF">
          <tt:value option="decimals(2)"
                    ref="DECF"/>
        </str>
        <str name="decimals(2) for BINF">
          <tt:value option="decimals(2)"
                    ref="BINF"/>
        </str>
        <str name="decimals(2) for TIMESTMPL">
          <tt:value option="decimals(2)"
                    ref="TIMESTMPL"/>
        </str>
        <str name="decimals(2) for DATETIMEL">
          <tt:value option="decimals(2)"
                    ref="DATETIMEL"/>
        </str>
        <str name="decimals(-1) for INTEGER">
          <tt:value option="decimals(-1)"
                    ref="INTEGER"/>
        </str>
        <str name="decimals(-1) for PACK">
          <tt:value option="decimals(-1)"
                    ref="PACK"/>
        </str>
        <str name="decimals(-1) for DECF">
          <tt:value option="decimals(-1)"
                    ref="DECF"/>
        </str>
        <str name="decimals(-1) for BINF">
          <tt:value option="decimals(-1)"
                    ref="BINF"/>
        </str>
        <str name="decimals(0) for UTCLONG">
          <tt:value option="decimals(0)"
                    ref="UTCLONG"/>
        </str>
        <str name="decimals(3) for UTCLONG">
          <tt:value option="decimals(3)"
                    ref="UTCLONG"/>
        </str>
        <str name="format(uri1),decimals(3) for UTCLONG">
          <tt:value option="format(uri1),decimals(3)"
                    ref="UTCLONG"/>
        </str>
        <str name="decimals(-6) for TIMESTMPL">
          <tt:value option="decimals(-6)"
                    ref="TIMESTMPL"/>
        </str>
        <str name="decimals(3) for TIMESTMPL">
          <tt:value option="decimals(3)"
                    ref="TIMESTMPL"/>
        </str>
        <str name="decimals(3) for DATETIMEL">
          <tt:value option="decimals(3)"
                    ref="DATETIMEL"/>
        </str>
        <str name="format(dateTime),decimals(3) for TIMESTMPL">
          <tt:value option="format(dateTime),decimals(3)"
                    ref="TIMESTMPL"/>
        </str>
        <str name="format(ticks),decimals(3) for TIMESTMPL">
          <tt:value option="format(ticks),decimals(3)"
                    ref="TIMESTMPL"/>
        </str>
        <str name="format(uri1),decimals(3) for TIMESTMPL">
          <tt:value option="format(uri1),decimals(3)"
                    ref="TIMESTMPL"/>
        </str>
      </object>
    </array>
  </tt:template>
</tt:transform>

The transformation creates JSON-XML to represent both XML and JSON. The time stamp in packed number datetimel is typed with the special domain XSDDATETIME_LONG_Z. This time stamp is still handled as such after the handling by decimals. For the number timestmpl of type p, the corresponding effect is obtained by using the additional time stamp formats specified with format. Time stamps in time stamp fields of the type utclong are handled as such by default.