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 Regime

The example demonstrates the display of ABAP types when using regimes.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    time = sy-timlo.
    boolean = abap_true.
    numtext = '255'.

    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 ABAP data to the transformation DEMO_ST_REGIME_OPTION and provides the result for XML and JSON. The transformation applies the option regime to the ABAP data:

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  <tt:root name="TIME"/>
  <tt:root name="BOOLEAN"/>
  <tt:root name="NUMTEXT"/>
  <tt:template>
    <array>
      <object>
        <str name="TIME">
          <tt:value ref="TIME"/>
        </str>
        <str name="regime(num) for TIME">
          <tt:value option="regime(num)"
                    ref="TIME"/>
        </str>
        <str name="regime(num),decimals(2) for TIME">
          <tt:value option="regime(num),decimals(2)"
                    ref="TIME"/>
        </str>
        <str name="BOOLEAN">
          <tt:value ref="BOOLEAN"/>
        </str>
        <str name="regime(char) for BOOLEAN">
          <tt:value option="regime(char)"
                    ref="BOOLEAN"/>
        </str>
        <str name="regime(char),format(boolean) for BOOLEAN">
          <tt:value option="regime(char),format(boolean)"
                    ref="BOOLEAN"/>
        </str>
        <str name="NUMTEXT">
          <tt:value ref="NUMTEXT"/>
        </str>
        <str name="regime(bin) for NUMTEXT">
          <tt:value option="regime(bin)"
                    ref="NUMTEXT"/>
        </str>
        <str name="regime(bin),format(uri1) for NUMTEXT">
          <tt:value option="regime(bin),format(uri1)"
                    ref="NUMTEXT"/>
        </str>
      </object>
    </array>
  </tt:template>
</tt:transform>

The transformation creates JSON-XML to represent both XML and JSON. The example shows the following:

  • Source Field of Type t
  • Normal asXML display according to the XML schema type xsd:time.
  • Applying regime(num) gives the number of days since 01.01.0001.
  • Applying regime(num),decimals(2) appends two decimal places.
  • Source field with reference to the special domain XSDBOOLEAN
  • Special display of the value X in the XML schema type xsd:boolean as true.
  • Applying regime(char) removes the effect of the domain and X is displayed according to the XML schema type xsd:string.
  • Applying regime(char),format(boolean) restores the display true.
  • Source field of type n with length 3
  • Normal asXML display according to the XML schema type xsd:string (pattern [0-9]+).
  • Applying regime(bin) converts the number in the source field to its binary representation and displays it in the XML schema type xsd:base64Binary.
  • Applying regime(bin),format(uri1) displays the binary value hexadecimally and adds quotation marks and a prefix.