SAP ABAP XSLT ASXML ELEMENTARY

Get Example source ABAP code based on a different SAP table
  


ARTICLE

asXML - Mapping of Elementary ABAP Types
The asXML representation of elementary ABAP types is used in XSL transformations and in Simple Transformations. In both cases, the elementary values or the elementary components of complex structures are converted in accordance with this mapping.
For elementary data objects with predefined ABAP types, the as representation is based on the canonical representation of XML schema data types from the namespace xsd='http://www.w3.org/2001/XMLSchema', where dates and times are represented in accordance with ISO-8601 and binary data is represented in accordance with Base64. The mapping of ABAP types to the XML schema data types is not fully bijective, due to the different value ranges. For example, you can specify a time zone for the XML schema data type xds:date, whereas this is not possible for the ABAP type d.
The following tables show a summary of the mappings:

Numeric Data Types ABAP TypeABAP RepresentationXML Schema Type XML Representation
b123xsd:unsignedByte123
s-123xsd:short-123
i-123xsd:int-123
int8-123xsd:long-123
p-1.23xsd:decimal-1.23
decfloat16123E+1precisionDecimal, totalDigits = 161.23E+3
decfloat34-3.140...0E+02precisionDecimal, totalDigits = 34-314.0...0
f-3.140...0E+02xsd:double-3.14E2

Note
The type precisionDecimal is not yet an official XML schema type.

Character-Like Data Types ABAP TypeABAP RepresentationXML Schema Type XML Representation
c' Hi'xsd:string_Hi
string' Hello 'xsd:string _Hello_
n'001234'xsd:string (pattern [0-9]+) 001234
d'20020204'xsd:date2002-02-04
t'201501'xsd:time20:15:01

Byte-Like Data Types ABAP TypeABAP RepresentationXML Schema Type XML Representation
xABCDEFxsd:base64Binaryq83v
xstring456789ABxsd:base64BinaryRweJqw==

Differences in Serialization
In serializations, ABAP values are converted to the appropriate character-like XML format. Deserializations operate in the opposite direction. Note the following differences to the usual conversion rules that apply in ABAP.
For the serialization of decimal floating point numbers, the same format as for their conversion to type string is generated.
When data objects with the type x are serialized, closing bytes with the value hexadecimal 0 are handled in the same way as closing blanks with data type c and are ignored.
When the following ABAP data objects are serialized to asXML, some checks are made to see whether the ABAP data object has a valid value:
A data object with the type n can contain only numbers.
A data object with the type p must represent a valid packed number.
A data object with the type d or t cannot contain any leading or closing blanks or the corresponding separator ('-' or ':') It can contain parentheses, signs and the following operators:
Any violations of these rules raise handleable exceptions, some of which can be avoided by specifying a transformation option after the OPTIONS addition of the CALL TRANSFORMATION statement.

Note
To check the validity of dates and times, you can use the domains XSDDATE_D and XSDTIME_T instead of the data types d and t.

Special Features of Deserialization
For deserialization to decimal floating point numbers, the conversion rule for source fields of the type c is used.
Serializations to an ABAP data object must retain the precision of the XML value:
Numeric types cannot lose decimal places .
In character-like or byte-like data types with fixed lengths (c, n, x), the target object must have enough places for the entire content, unless only leading and closing blanks in data type c and leading zeros in data type n are affected.
Structures cannot be converted to elementary data objects.
Deserializations fill data objects of the type c or x with blanks or hexadecimal 0 on the right (as usual) if fewer characters or bytes are passed than can fit in the data object.
If the required XML element does not exist when the system is deserializing in an elementary data object, then the elementary data object retains its previous value. If an empty element is assigned to an elementary data object, it is set to its type-specific initial value. To initialize the data object in either case, you can use the transformation option clear with the value 'all'.
Any violations of these rules raise handleable exceptions such as CX_SY_CONVERSION_DATA_LOSS, some of which can be avoided by specifying a transformation option after the OPTIONS addition of the CALL TRANSFORMATION statement.

Note
Exceptions from mappings cannot be handled directly. Instead, the exception CX_TRANSFORMATION_ERROR (or one of its subclasses) from statement CALL TRANSFORMATION can be handled. The attribute PREVIOUS then contains a reference to the original exception.

Example
See asXML, Mapping of Elementary Data Types