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 Invalid Values
This example demonstrates how ABAP types are mapped using invalid values.
Other versions:
7.31 | 7.40 | 7.54
Source Code
FIELD-SYMBOLS <hex> TYPE x.
num = CONV d( ` 1234 ` ).
pack = -1234.
ASSIGN pack TO <hex> CASTING.
REPLACE SECTION OFFSET 7 LENGTH 1 OF <hex> WITH
CONV xstring( '40' ) IN BYTE MODE.
boolean = '1'.
date = 'XXXXXXXX'.
time = 'XXXXXX'.
langu = '�'.
currcode = '�����'.
unitcode = '�����'.
TRY.
CALL TRANSFORMATION demo_st_noerror_option
SOURCE n = num
p = pack
boolean = boolean
xsddate_d = date
xsdtime_t = time
xsdlanguage = langu
xsdcurrcode = currcode
xsdunitcode = unitcode
RESULT XML DATA(xml).
CATCH cx_transformation_error INTO DATA(exc).
cl_demo_output=>display( exc->get_text( ) ).
RETURN.
ENDTRY.
cl_demo_output=>display_xml( xml ).
Description
This example passes various types of ABAP data to the transformation DEMO_ST_NOERROR_OPTION and provides the result for XML. The transformation applies the option noError to the ABAP data:
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="N"/>
<tt:root name="P"/>
<tt:root name="BOOLEAN"/>
<tt:root name="XSDDATE_D"/>
<tt:root name="XSDTIME_T"/>
<tt:root name="XSDLANGUAGE"/>
<tt:root name="XSDCURRCODE"/>
<tt:root name="XSDUNITCODE"/>
<tt:template>
<array>
<object>
<str name="n">
<tt:value option="noError" ref="N"/>
</str>
<str name="p">
<tt:value option="noError" ref="P"/>
</str>
<bool name="boolean">
<tt:value option="noError" ref="BOOLEAN"/>
</bool>
<str name="xsddate_d">
<tt:value option="noError" ref="XSDDATE_D"/>
</str>
<str name="xsdtime_t">
<tt:value option="noError" ref="XSDTIME_T"/>
</str>
<str name="xsdlanguage">
<tt:value option="noError" ref="XSDLANGUAGE"/>
</str>
<str name="xsdcurrcode">
<tt:value option="noError" ref="XSDCURRCODE"/>
</str>
<str name="xsdunitcode">
<tt:value option="noError" ref="XSDUNITCODE"/>
</str>
</object>
</array>
</tt:template>
</tt:transform>
The transformation creates JSON-XML to represent both XML and JSON. The example passes an invalid value to the transformation for each of the types used. If the option noError were not specified, each of the invalid types would raise an exception.