ABAP Keyword Documentation → ABAP − Reference → Data Interfaces and Communication Interfaces → ABAP and XML → Transformations for XML → asXML - Canonical XML Representation
asXML - Mapping Additional XML Schema Data Types
As well as the XML schema data types required for mapping elementary ABAP types, there are additional XML schema data types that cannot be mapped directly to built-in ABAP types. To enable type-friendly deserialization of these external types to ABAP data objects, a special domain is implemented in ABAP Dictionary for each required XML schema data type. The name of the domain starts with XSD. Any elementary ABAP data objects whose data type is defined using a data element that refers to a domain of this type are mapped to the appropriate XML schema data type, both when serialized and when deserialized. The required conversions are performed internally. This applies to both XSL transformations and to simple transformations.
The following table provides a summary of the XML schema data types supported by domains, as well as other supported types (UUID, currCode and unitCode).
XML Schema Type | XML Representation | Domain | ABAP Representation |
---|---|---|---|
xsd:boolean | true, false | XSDBOOLEAN | X, " " |
xsd:date | 2007-10-01 | XSDDATE_D | 20071001 |
xsd:time | 11:55:00 | XSDTIME_T | 115500 |
xsd:dateTime | 2006-07-27T17:03:34Z | XSDDATETIME_Z, XSDDATETIME_LONG_Z, XSDDATETIME_OFFSET, XSDDATETIME_LOCAL, XSDDATETIME_LOCAL_DT | 20060727170334 |
xsd:QName | prefix:name | XSDQNAME | |
UUID | 00505691‑3e2f‑1ed5‑b8ba‑87b9ac1248c9 | XSDUUID_RAW, XSDUUID_CHAR, XSDUUID_BASE64 | 005056913E2F1ED5B8BA87B9AC1248C9, 051MaJul7jMukeUvh198oG |
xsd:language | EN, DE | XSDLANGUAGE | D, E |
currCode | EUR, USD | XSDCURRCODE | EUR, USD |
unitCode | KMT, SMI | XSDUNITCODE | KM, MI |
The following sections describe the domains and their mappings in more detail.
The following applies to all domains:
- in deserializations of an empty XML element in an ABAP data object (which is typed with reference to this type of domain), the initial value of the associated elementary ABAP type is assigned as usual.
- The transformation option
initial_components
for suppressing initial values in serializations has the same effect as for normal data types. This can lead to unexpected behavior in deserializations, if the transformation optionclear
is not used with the value "all".
Other versions: 7.31 | 7.40 | 7.54
Notes
- With the exception of XSDQNAME, all domains are also supported in transformations for JSON. See the associated executable example.
- By specifying format in the attribute option of the ST command tt:value, many of the formats here can also be applied to ABAP data objects that are not typed with a domain of this type.
- By specifying regime in the attribute option of the ST command tt:value, the effect of the domains shown here is disabled.
- Exceptions that occur when mapping the domains displayed here can in some cases be suppressed by specifying noError in the attribute option of the ST command tt:value.
- 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.
boolean
The domain XSDBOOLEAN has the data type CHAR with length 1 and therefore supports the usual ABAP representation of a truth value using "X" for true and " " for false. These values are entered as fixed values for the domain and are checked when an ABAP data object linked to this domain is serialized. The serialization creates the values "true" and "false" in XML. A deserialization also accepts the non-canonical XML values "1" and "0". Any other values raise the exception CX_SY_CONVERSION_NO_BOOLEAN. An empty element creates the value " " in deserializations.
Notes
- By specifying noError in the attribute option of the ST command tt:value, an exception for invalid ABAP values in serialization can be avoided. All values except " " are interpreted as true.
- The transformation option
initial_components
suppresses components of type XSDBOOLEAN in serializations, if the components contain the value " " for "false". Therefore this option should be used carefully.
- The return value of the Boolean function
xsdbool
has the type XSDBOOLEAN.
date
The XML schema data type date for dates is supported by both the built-in
ABAP type d
and the domain XSDDATE_D. This domain has the data type DATS. When data
is serialized and deserialized, the validity of the date is also checked, which is not the case with the built-in ABAP type d
. An empty element creates the value "00000000" in deserializations.
Note
By specifying noError in the attribute option of the ST commandtt:value, an exception for an invalid date in serialization can be avoided.
dateTime
The XML schema data type dateTime supports the representation of dates and times in a field, based on ISO 8601. An XML value of this type is either in UTC format, contains a time zone, or represents a local time. Five domains are assigned to this schema data type:
- The domains XSDDATETIME_Z and XSDDATETIME_LONG_Z have the data types DEC with length 15 or 21. XSDDATETIME_Z has no decimal places and XSDDATETIME_LONG_Z has seven decimal places. These domains support the long and short form of time stamps in packed numbers, which is always processed as the current UTC reference time. The serialization generates values in the UTC format (yyyy-mm-ddThh:mm:ss.fffffffZ) in XML. Only significant decimal places are written to XML. A deserialization accepts XML values in UTC format (closed by Z) or with time zones (closed by {+|-}hh:mm). The time zones are converted to the appropriate UTC value. No precision may be lost in deserializations. This means that only XML values with a maximum of seven decimal places can be deserialized. An empty element creates the value 0 in deserializations.
- The domain XSDDATETIME_OFFSET has the data type CHAR with length 18. It permits mappings to XML values in which a time zone is specified (yyyy-mm-ddThh:mm:ss{+|-}hh:mm). The defined format for an ABAP data object of type XSDDATETIME_OFFSET is yyyymmddhhmmss{+|-}mmm. In a deserialization, the time zone of the XML value specified in hours and minutes is converted to a three-figure number of minutes. An empty element creates an empty string in deserializations.
- The domain XSDDATETIME_LOCAL has the data type CHAR with length 14. The domain XSDDATETIME_LOCAL_DT has the data type NUMC with length 14. They enable mappings to XML values that specify a local time (yyyy-mm-ddThh:mm:ss). This means that they do not exist in UTC format and no time zone is specified. The defined format for an ABAP data object of type XSDDATETIME_LOCAL or XSDDATETIME_LOCAL_DT is yyyymmddhhmmss. The main difference between the two data types are their initial values. An empty element creates an empty string in deserializations.
Invalid values raise the exception CX_SY_CONVERSION_NO_DATE_TIME.
Note
Time stamp fields with time stamp type are mapped to the format yyyy-mm-ddThh:mm:ss.fffffffZ by default.
Example
Serialization and deserialization of a time stamp field of the type utclong
and a time stamp in a packed number of the type XSDDATETIME_LONG_Z. The generated XML is as follows:
<asx:values>
<TS>2019-04-15T11:22:10.1230000Z</TS>
<TSP>2019-04-15T11:22:10.123Z</TSP>
</asx:values>
</asx:abap>
The element <TS> and element <TSP> can be deserialized in both time stamp fields and in packed numbers of the type XSDDATETIME_LONG_Z.
DATA(ts) =
CONV utclong( '2019-04-15 11:22:10,123' ).
DATA(tsp) =
CONV xsddatetime_long_z( cl_abap_tstmp=>utclong2tstmp( ts ) ).
CALL TRANSFORMATION id
SOURCE ts = ts
tsp = tsp
RESULT XML DATA(xmlstr).
CALL TRANSFORMATION id
SOURCE XML xmlstr
RESULT ts = ts
tsp = ts.
CALL TRANSFORMATION id
SOURCE XML xmlstr
RESULT ts = tsp
tsp = tsp.
QName
The domain XSDQNAME has the data type STRING. The XML schema data type QName represents qualified names. In XML, a qualified name can have a prefix that is separated by a colon. A prefix of this type must be associated with a URI in a namespace declaration of the current element or a higher-level element. In ABAP, a name of this type is represented as the content of a string in the form "{URI}name".
When an ABAP object of the type XSDQNAME is serialized, the URI specified in curly brackets is used to create the associated prefix. If there is no namespace declaration for the URI in the right context, it is inserted in the current element, with the resulting namespaces containing the names "n0", "n1", ... If the URI is associated with the default namespace, no prefix is created. If no URI is specified in curly brackets, again no prefix is created. This latter case is possible only if the default namespace is not used simultaneously in the current element. Otherwise, the exception CX_ST_INVALID_XML is raised (which can occur only in simple transformations).
When a value with a prefix is deserialized to an ABAP data object of the type XSDQNAME, the system searches for a URI in an associated namespace declaration. If no URI is found, the exception CX_SY_CONVERSION_NO_QNAME is raised. If a value without prefix is deserialized, the URI of the default namespace is used (if available) or only the name is placed in the string.
An initial data object of the type XSDQNAME creates an empty element when serialized, and back when deserialized. In both serializations and deserializations, the correctness of the specified name with respect to the valid naming conventions is checked. If violated, an exception of the class CX_SY_CONVERSION_NO_QNAME is raised.
The class CL_ABAP_XSDTYPE_HELPER contains the methods TO_XSDQNAME and FROM_XSDQNAME for the conversion of URIs and names to the type XSDQNAME, and back.
Executable Example
asXML, Mapping of Qualified Names
time
The XML schema data type time for times is supported by both the built-in
ABAP type t
and the domain XSDTIME_T. This domain has the data type TIMS. When data
is serialized and deserialized, the validity of the time is also checked, which is not the case with the built-in ABAP type t
. An empty element creates the value "000000" in deserializations.
Note
By specifying noError in the attribute option of the ST commandtt:value, an exception for an invalid time in serialization can be avoided.
UUID
The domains have the following meaning:
- XSDUUID_RAW has the data type RAW with length 16 for 16-byte UUIDs in binary format.
- XSDUUID_CHARhas the data type CHAR with length 32 for 16-byte UUIDs in hexadecimal format.
A serialization creates the hexadecimal XML schema representation from data objects of these types, with hyphens and lowercase letters. Deserializations accept uppercase letters as well. A character-like UUID of type XSDUUID_CHAR can contain only uppercase letters in serializations. Invalid UUIDs raise the exception CX_SY_CONVERSION_NO_UUID. An empty element creates byte strings or character strings filled with hexadecimal zeroes or blanks in deserializations.
Note
UUIDs can be generated in ABAP data objects from the class CL_SYSTEM_UUID.
Example
Serialization of a 16-byte UUID in base64 format.
DATA uuid TYPE xsduuid_base64.
uuid = cl_uuid_factory=>create_system_uuid( )->create_uuid_c22( ).
CALL TRANSFORMATION id SOURCE uuid = uuid
RESULT XML DATA(xml).
cl_demo_output=>display_xml( xml ).
Executable Example
language
The domain XSDLANGUAGE has the data type LANG with length 1. It permits mappings of one-character internal language codes to the associated two-character external ISO codes and back. The rule for the mapping is specified in the columns SPRAS (single-character code) and LAISO (two-character code) of the database table T002. In serializations, the single-character code is found in the table T002 and the associated two-character code is used as an XML value. The opposite happens in deserializations. In deserializations, lowercase letters are transformed to uppercase letters first. If no code is found in the table T002, the following relationship is evaluated:
Here, Y is the 16-bit Unicode value of the single-character code and X1 and X2 are the 7-bit ASCII values of the two characters in the two-character code.
- In serializations, a two-character code is created (if possible), that satisfies this relationship. If this is not possible, the exception CX_SY_CONVERSION_UNKNOWN_LANGU is raised.
- In deserializations, the single-character code is calculated in accordance with this formula. The exception CX_SY_CONVERSION_UNKNOWN_LANGU is raised if the XML value is longer than two characters (except when the third character is a hyphen; in this case only the first two characters are used) or if the 7-bit ASCII values of the characters are less than 0x20 or greater than or equal to 0x80.
Note
By specifying noError in the attribute option of the ST command tt:value, an exception for an unknown language in serialization can be avoided. In this case, no conversion is performed.
Example
Serializes a language code with transformation in accordance with table T002.
DATA language TYPE xsdlanguage VALUE 'E'.
cl_demo_input=>request( CHANGING field = language ).
TRY.
CALL TRANSFORMATION id SOURCE language = language
RESULT XML DATA(xml).
cl_demo_output=>display_xml( xml ).
CATCH cx_transformation_error INTO DATA(exc_trafo).
MESSAGE exc_trafo TYPE 'I' DISPLAY LIKE 'E'.
IF exc_trafo->previous IS NOT INITIAL.
MESSAGE exc_trafo->previous TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
ENDTRY.
currCode
The domain XSDCURRCODE has the data type CUKY with length 5. It permits mappings of SAP-specific currency codes to external ISO currency codes and back. The rule for the mapping is specified in the columns WAERS (SAP code) and ISOCD (ISO code) of the database table TCURC. In serializations, the SAP code is found in the table TCURC and the associated ISO code is used as an XML value. The opposite happens in deserializations. If a code is not found in the table TCURC, the exception CX_SY_CONVERSION_UNKNOWN_CURR is raised.
Note
By specifying noError in the attribute option of the ST command tt:value, an exception for an unknown SAP code in serialization can be avoided. In this case, no conversion is performed.
Example
Serializes a currency code with transformation in accordance with table TCURC.
DATA currcode TYPE xsdcurrcode VALUE 'EUR'.
cl_demo_input=>request( CHANGING field = currcode ).
TRY.
CALL TRANSFORMATION id SOURCE currcode = currcode
RESULT XML DATA(xml).
cl_demo_output=>display_xml( xml ).
CATCH cx_transformation_error INTO DATA(exc_trafo).
MESSAGE exc_trafo TYPE 'I' DISPLAY LIKE 'E'.
IF exc_trafo->previous IS NOT INITIAL.
MESSAGE exc_trafo->previous TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
ENDTRY.
unitCode
The domain XSDUNITCODE has the data type UNIT with length 3. It permits mappings of SAP-specific unit codes to external ISO unit codes and back. The rule for the mapping is specified in the columns MSEHI (SAP code) and ISOCODE (ISO code) of the database table T006. In serializations, the SAP code is found in the table T006 and the associated ISO code is used as an XML value. The opposite happens in deserializations. If a code is not found in the table T006, the exception CX_SY_CONVERSION_UNKNOWN_UNIT is raised.
Note
By specifying noError in the attribute option of the ST command tt:value, an exception for an unknown SAP code in serialization can be avoided. In this case, no conversion is performed.
Example
Serializes a unit of measurement with transformation in accordance with table T006.
DATA unitcode TYPE xsdunitcode VALUE 'TON'.
cl_demo_input=>request( CHANGING field = unitcode ).
TRY.
CALL TRANSFORMATION id SOURCE unitcode = unitcode
RESULT XML DATA(xml).
cl_demo_output=>display_xml( xml ).
CATCH cx_transformation_error INTO DATA(exc_trafo).
MESSAGE exc_trafo TYPE 'I' DISPLAY LIKE 'E'.
IF exc_trafo->previous IS NOT INITIAL.
MESSAGE exc_trafo->previous TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.
ENDTRY.