Show TOC

Syntax documentationElementary Data Objects Locate this document in the navigation structure

The following ST command is used to serialize and deserialize elementary data objects:

Syntax Syntax

  1. <tt:value [ref="node"] [map="mapping_list"] 
  2.                        [length|minLength|maxLength="length"]
                            [validation] />
End of the code.

The optional attribute ref can be used to define the current node for the command. If ref is not specified, the current node of the surrounding element is used.

  • The mapping of elementary ABAP values to XML values (and the reverse direction) is subject to the general mapping rules that apply between ABAP and XML (asXML).

  • You can use map to specify a mapping list that maps multiple values to a single value.

  • You can use length, minLength, or maxLength to specify a length.

  • The value can be validated by specifying validation.

Serialization

If you do not specify map, the value of the elementary ABAP data object that is bound to the current node is inserted into the XML document in place of the command during serialization.

The special features listed in the ABAP keyword documentation apply to the serialization of elementary ABAP values to asXML.

Deserialization

During deserialization, the current value of the XML inbound stream is passed to the ABAP data object. The end of the XML value is determined either by the end of the text node (for example, at the element end) or by the beginning of a literal text following directly in the ST program. The XML value must correspond to the type of the data object and must lie within its value range.

The special features listed in the ABAP keyword documentation apply to the deserialization of elementary asXML values to ABAP data objects.

Example

The following ST program shows the mapping of elementary ABAP data types for date, time, and time stamp to XML and the reverse direction:

Syntax Syntax

  1. <?sap.transform simple?>
  2. <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  3.   <tt:root name="DATE"/>
  4.   <tt:root name="TIME"/>
  5.   <tt:root name="DATETIME"/>
  6.   <tt:template>
  7.     <Date_and_Time>
  8.       <Date>
  9.         <tt:value ref="DATE"/>
  10.       </Date>
  11.       <Time>
  12.         <tt:value ref="TIME"/>
  13.       </Time>
  14.       <DateTime>
  15.         <tt:value ref="DATETIME"/>
  16.       </DateTime>
  17.     </Date_and_Time>
  18.   </tt:template>
  19. </tt:transform>
End of the code.

The following ABAP program can call the transformation. Note that time_stamp is defined with the special type XSDDATETIME_Z from ABAP Dictionary. This type ensures that a special mapping rule is used for the time stamp.

Syntax Syntax

  1. DATA: dat         TYPE d,
  2.       tim         TYPE t,
  3.       time_stamp  TYPE xsddatetime_z,
  4.       tz          TYPE ttzz-tzone VALUE IS INITIAL,
  5.       xml_xstring TYPE xstring.
  6. dat = sy-datum.
  7. tim = sy-uzeit.
  8. CONVERT DATE dat TIME tim INTO TIME STAMP time_stamp TIME ZONE tz.
  9. CALL TRANSFORMATION ... SOURCE date = dat
  10.                                time = tim
  11.                                datetime = time_stamp
  12.                         RESULT XML xml_xstring.
  13. cl_abap_browser=>show_xml( xml_xstring = xml_xstring
  14.                            modal       = 'X' ).
End of the code.

The result of the transformation is as follows:

Syntax Syntax

  1. <?xml version="1.0" encoding="utf-8" ?> 
  2. <Date_and_Time>
  3.   <Date>2006-08-30</Date> 
  4.   <Time>09:02:23</Time> 
  5.   <DateTime>2006-08-30T09:02:23Z</DateTime> 
  6. </Date_and_Time>
End of the code.

The transformation is symmetrical.