Elementary Data Objects
The following ST command is used to serialize and deserialize elementary data objects:
<tt:value [ref="node"] [map="mapping_list"]
[length|minLength|maxLength="length"] />
The optional attribute ref can be used to define the current node for the command. If refis 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.
If you do not specify map, during serialization the value of the elementary ABAP data object, which is bound to the current node, is inserted into the XML document in place of the command.
The special features listed in the ABAP keyword documentation apply to the serialization of elementary ABAP values to asXML.
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.
The following ST program shows the mapping of elementary ABAP data types for date, time, and time stamp to XML and the reverse direction:
<?sap.transform
simple?>
<tt:transform
xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="DATE"/>
<tt:root name="TIME"/>
<tt:root
name="DATETIME"/>
<tt:template>
<Date_and_Time>
<Date>
<tt:value ref="DATE"/>
</Date>
<Time>
<tt:value ref="TIME"/>
</Time>
<DateTime>
<tt:value ref="DATETIME"/>
</DateTime>
</Date_and_Time>
</tt:template>
</tt:transform>
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 guarantees that a special mapping rule is used for the time stamp.
DATA:
dat
TYPE d,
tim
TYPE t,
time_stamp TYPE
xsddatetime_z,
tz
TYPE ttzz-tzone VALUE IS INITIAL,
xml_xstring TYPE xstring.
dat = sy-datum.
tim = sy-uzeit.
CONVERT DATE dat TIME tim INTO TIME STAMP
time_stamp TIME ZONE tz.
CALL TRANSFORMATION ... SOURCE date = dat
time = tim
datetime = time_stamp
RESULT XML xml_xstring.
cl_abap_browser=>show_xml( xml_xstring = xml_xstring
modal = 'X'
).
The result of the transformation is as follows:
<?xml version="1.0" encoding="utf-8" ?>
<Date_and_Time>
<Date>2006-08-30</Date>
<Time>09:02:23</Time>
<DateTime>2006-08-30T09:02:23Z</DateTime>
</Date_and_Time>
The transformation is symmetrical.