SAP CALL TRANSFORMATION ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• CALL TRANSFORMATION ABAP Statement

CALL TRANSFORMATION
Short Reference

ABAP_SYNTAX
CALL TRANSFORMATION ID
$| trans$|(name)
$[PARAMETERS ${p1 = e1 p2 = e2 ...$}$|(ptab)$]
$[ OPTIONS options$]
SOURCE ${XML src_xml$}
$| ${${bn1 = e1 bn2 = e2 ...$}$|(stab)$}
RESULT ${XML rslt_xml$}
$| ${ ${bn1 = f1 bn2 = f2 ...$}$|(rtab) $}.

ABAP_ALTERNATIVES:
1 ... ID ...
2 ... trans$|(name) ...

ABAP Addition
1A ... SOURCE ${XML src_xml$}$|${${bn1 = e1 bn2 = e2 ...$}$|(stab)$}
1B ... RESULT ${XML rslt_xml$}$|${${bn1 = f1 bn2 = f2 ...$}$|(rtab)$}
2 ... PARAMETERS ${${p1 = e1 p2 = e2 ...$}$|(ptab)$}

What does it do?
This statement calls the specified XSL transformation (XSLT) or a Simple Transformation (ST). The source of the transformation is specified behind SOURCE and the result is stored as specified behind RESULT. PARAMETERS can be used to pass parameters to the transformation. The addition OPTIONS can be used to specify transformation options options. The possible transformation types are:
from XML to XML (for XSLT only)
from XML to ABAP (for XSLT and Simple Transformations only)
from ABAP to XML (for XSLT and Simple Transformations only)
from ABAP to ABAP (for XSLT only)
JSON-XML, which maps JSON data to XML, can be used to execute all categories of transformations for JSON that are also possible for XML. For more information, see Transformations for JSON.



Latest notes:

The characters < , >, , ', and ', which have a separate meaning in XML syntax, are handled automatically for XML data. When XML data is written, the required XML notation lt;, lt;, gt;, amp;, quot;, or apos; is automatically created in values of elements or attributes. When XML data is read, the XML notation is transformed to the corresponding characters. It is not usually necessary to apply the escape character function escape or a similar method to character-like XML results of the statement CALL TRANSFORMATION and would produce incorrect results. An exception to this rule is creating HTML data with XSLT if it contains JavaScript parts.
When JSON data is written, special characters in character-like values are prefixed automatically with the escape character . Conversely, the escape character is removed from character-like values when JSON data is read.
NON_V5_HINTS
When a transformation is performed, methods from the class libraries for XML are used internally.
In the case of XSLT, a DOM is always needed as a source. This DOM is constructed and processed using the iXML Library. In the case of the identity transformation ID, the iXML Library is used only if the corresponding objects are specified as source or target.
ST is processed serially, using the sXML Library . The library that is used affects the character set that is supported. The iXML Library supports UCS-2 and the sXML Library supports UTF.
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The transaction Standard SAP Help forEMO demonstrates various transformations from ABAP data to XML and JSON.
ABAP_EXAMPLE_END
• ID CALL TRANSFORMATION

ABAP Alternative 1 ... ID ...
BEGIN_SECTION ID CALL-TRANSFORMATION-ID

What does it do?
Specifies the identity transformation ID directly. This transformation exists as an XSL transformation in the repository but is executed by the runtime framework in an optimized ID engine, depending on the transformation source or target. For more information, see:
Identity transformation
Identity Transformation for JSON

ABAP_EXAMPLE_ABEXA
Executable Example of an Identity Transformation
ABAP_EXAMPLE_END
END_SECTION ID CALL-TRANSFORMATION-ID

ABAP Alternative 2 ... trans$|(name) ...
BEGIN_SECTION ID CALL-TRANSFORMATION

What does it do?
Specifies any transformation. The transformation addition can be specified either statically or dynamically:
trans If static, the transformation is specified directly as trans.
(name)
BEGIN_SECTION ID CALL-TRANSFORMATION-DYNAMIC If dynamic, the transformation is specified as the uppercase content of a parenthesized character-like data object name.
END_SECTION ID CALL-TRANSFORMATION-DYNAMIC
The specified transformation must exist as an XSLT program or as a Simple Transformation in the repository. If a dynamically specified transformation is not found, an exception of the class CX_INVALID_TRANSFORMATION is raised.

ABAP_EXAMPLE_ABEXA
Executable Example of a Simple Transformation
ABAP_EXAMPLE_END
END_SECTION ID CALL-TRANSFORMATION
• SOURCE CALL TRANSFORMATION
• XML CALL TRANSFORMATION SOURCE

ABAP Addition e2 ... $}$|(stab)$}

What does it do?
Specifying the source.
Transformation of XML Data
When XML src_xml is specified, the XML data contained in src_xml is transformed. src_xml can exist in the following forms:
As a data object with the type string or as a standard table with a flat character-like line type, which can contain the following data:
Character-like XML data in XML 1.0 format.
Character-like JSON data. When any transformation trans$|(name) is used, the JSON data is converted to the associated JSON XML format and passed to this transformation. The predefined identity transformation ID handles the JSON data directly.
As a data object with the type xstring or as a standard table with a flat byte-like line type, which can contain the following data:
Byte-like representation of the characters in XML data in XML 1.0 format, in accordance with a code page such as UTF-8.
XML data in Binary XML format.
Byte-like representation of the characters in JSON data, in accordance with a code page such as UTF-8. When any transformation trans$|(name) is used, the JSON data is converted to the associated JSON XML format and passed to this transformation in this way. The predefined identity transformation ID handles the JSON data directly.
BEGIN_SECTION VERSION 5 OUT
As an interface reference variable for objects in the iXML Library (XSLT only):
Interface reference variable with the type IF_IXML_ISTREAM that points to an input stream that reads XML data.
Interface reference variable with the type IF_IXML_NODE that points to a node or an entire XML document in DOM representation.
END_SECTION VERSION 5 OUT
As a reference variable of the type
BEGIN_SECTION VERSION 5 OUT IF_SXML_READER or
END_SECTION VERSION 5 OUT CL_SXML_READER for XML Reader in the sXML Library. The transformation moves the reader by one node and processes the entire matching subtree. If the transformation is successful, the reader is located at the end of the processed data. Any valid reader can be specified:
XML readers for XML data in XML 1.0 format.
XML readers for XML data in Binary XML format.
XOP readers for XML data in XOP format.
JSON readers for JSON data. When any transformation trans$|(name) is used, the JSON reader returns the JSON data in JSON-XML format. When a predefined identity transformation ID is used, the JSON data is handled directly.



Latest notes:

The interface IF_SXML_READER and the class CL_SXML_READER are part of the API of the sXML Library, whose objects can be accessed using CALL TRANSFORMATION.
Transformations of XML data in XOP format are only possible with an XOP reader in the sXML Library. All other formats can be also specified in appropriate strings or internal tables.
When XML data is specified in strings or internal tables, it is best to use byte strings or byte-like line types and the UTF-8 code page for the representation.
The methods CONVERT of the interfaces IF_ABAP_CONV_IN and IF_ABAP_CONV_OUT of objects created using the class CL_ABAP_CONV_CODEPAGE can be used to transform character-like XML data or JSON data to a byte-like representation in accordance with a code page and vice versa.
NON_V5_HINTS
The interfaces IF_IXML_ISTREAM and IF_IXML_NODE are part of the API of the iXML Library, whose objects can be accessed using CALL TRANSFORMATION.
For compatibility reasons, src_xml can also be a class reference variable of the type CL_FX_READER. The class CL_FX_READER, however, is scheduled for replacement by CL_SXML_READER.
ABAP_HINT_END
Transformation of ABAP Data
bn1 = e1 ... or (stab) is used to specify the ABAP data e1 e2 ... to be transformed.
When the identity transformation ID is called, the ABAP data is either serialized to the canonical XML format asXML or to the canonical JSON format asJSON, depending on the target.
When an XSLT program is called, the ABAP data is serialized to the canonical XML representation, which is then used as the source of the XSL transformation. bn1 bn2 ... is used to specify the names of the XML elements that represent the ABAP data objects in the canonical XML representation.
When a Simple Transformation is called, the transformation has read-only access to the ABAP data using the names bn1 bn2 ....
Instead of using a static parameter list, the data objects can be passed dynamically as value pairs in the columns of an internal table stab that has the type abap_trans_srcbind_tab from the type pool ABAP.
Serializations convert the elementary components of the ABAP data objects to asXML or asJSON, in accordance with the mappings for built-in ABAP types or for further XML schema data types . This can raise the exceptions described there, some of which can be bypassed by using transformation options.
The case of the names in the XML data or JSON data depends on how they are specified in the ABAP runtime framework. If specified statically ( b1, b2, ...), uppercase is used and if specified dynamically in stab, the case used there is used.



Latest notes:

When a Simple Transformation is called, the serialization always creates an internal XML writer, which can be addressed using the interface IF_SXML_WRITER from sXML Library. The object is accessed using attributes of the ST statement tt:call-method.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLES_ABEXA
For an overview of all possible XML sources, see XML Sources of Transformations .
For deserializations of ABAP data from an XML reader in the sXML Library, see sXML-Library, Transformation from XML Reader.
ABAP_EXAMPLE_END
• RESULT CALL TRANSFORMATION
• XML CALL TRANSFORMATION RESULT

ABAP Addition f2 ...$}$|(rtab)$}

What does it do?
Specifying the target.
Transformation to XML Data
When XML rslt_xml is specified, a transformation to XML data takes place and this data is passed to rslt_xml. rslt_xml can exist in the following forms:
As a variable with the type string or as a standard table with a flat character-like line type. The XML data returned by the transformation is stored in XML 1.0 format as a character string in the string or in the table. Here, a byte order mark (BOM) is used as a prefix.
As a variable with the type xstring or as a standard table with a flat byte-like line type. The XML data returned by the transformation is stored in XML 1.0 format as a byte string in the string or table. The byte string represents the characters of the XML data in accordance with the code page UTF-8. A byte order mark (BOM) is not used as a prefix.
As an inline declaration DATA(var) or FINAL(var), where a variable with the type xstring is created.
BEGIN_SECTION VERSION 5 OUT
As an interface reference variable for objects in the iXML Library (XSLT only):
Interface reference variable with the type IF_IXML_OSTREAM that points to an output stream that writes XML data.
Interface reference variable with the type IF_IXML_DOCUMENT that points to an XML document in DOM representation.
END_SECTION VERSION 5 OUT
As a reference variable with the type
BEGIN_SECTION VERSION 5 OUT IF_SXML_WRITER or
END_SECTION VERSION 5 OUT CL_SXML_WRITER for XML writers in the sXML Library. The result of the transformation is added to the current element of the writer as a subtree. Any valid writer can be specified:
XML writers for XML data in XML 1.0 format.
XML writers for XML data in Binary XML format.
XOP writers for XML data in XOP format.
JSON writers for JSON data. A transformation trans$|(name) must create XML data in JSON-XML format. The predefined identity transformation ID creates the appropriate data directly.



Latest notes:

The interface IF_SXML_WRITER and the class CL_SXML_WRITER are part of the API of the sXML Library, whose objects can be accessed using CALL TRANSFORMATION.
Transformations to formats other than XML 1.0 are only possible with the corresponding writers in the sXML Library.
When XML data is stored in strings or internal tables, it is best to use byte strings or byte-like line types and the UTF-8 code page for the representation.
XML data that is written to Unicode systems as character-like data cannot be processed as character-like data in a non-Unicode system due to the byte order mark (BOM) that is predefined by the XML standard.
The methods CONVERT of the interfaces IF_ABAP_CONV_OUT and IF_ABAP_CONV_IN of objects created using the class CL_ABAP_CONV_CODEPAGE can be used to transform character-like XML data or JSON data to a byte-like representation in accordance with a code page.
NON_V5_HINTS
The interfaces IF_IXML_OSTREAM and IF_IXML_DOCUMENT are part of the API of the iXML Library, whose objects can be accessed using CALL TRANSFORMATION.
For compatibility reasons, rslt_xml can also be a class reference variable of the type CL_FX_WRITER. However, the class CL_FX_WRITER is replaced by CL_SXML_WRITER.
ABAP_HINT_END

ABAP_HINT_SEC
If HTML data containing JavaScript is created using the output method html of an XSL transformation, the syntax characters < , blank, , ', and ' in the JavaScript parts are not transformed to their XML notation. To prevent cross site scripting (XSS) in HTML data that contains dynamic JavaScript parts, appropriate measures must be taken. These measures are best applied in the XSL transformation that creates the data.
NON_V5_HINTS
ABAP_HINT_END
Transformation to ABAP Data
bn1 = f1 ... or (rtab) are used to specify the ABAP target fields f1 f2 ... into which the XML data is to be transformed.
When the identity transformation ID is called, the source must either be a canonical XML representation or a canonical JSON representation of ABAP data. The canonical representation is deserialized into the ABAP data objects. bn1 bn2 ... is used to specify the names of the XML elements that represent the ABAP data objects in the canonical XML representation, and f1 f2 ... is used to specify ABAP data objects that are appropriate to the data type into which they are deserialized.
When an XSLT program is called, the result of the XSL transformation must represent a canonical XML representation that is deserialized into the ABAP data objects, as with the identity transformation.
When a Simple Transformation is called, the transformation performs writes on the ABAP data using the names bn1 bn2 ....
Instead of using a static parameter list, the data objects can be passed dynamically as value pairs to the columns of the internal table rtab that has the type abap_trans_resbind_tab from the type pool ABAP.
Deserialization converts the elementary XML or JSON values to elementary ABAP data types in accordance with the mappings for built-in ABAP types or for further XML schema data types . This can raise the exceptions described there, some of which can be bypassed by using transformation options.
The case used in the XML or JSON data must match exactly the case in the ABAP runtime framework. If specified statically (b1, b2 , ...), uppercase is used and if specified dynamically in rtab, the case used there is used.
When deserializing from a canonical representation, if no corresponding asXML element or asJON object component exists for an ABAP object, the data object retains its previous value. If an empty XML element or an empty JSON array is assigned to an elementary or tabular ABAP data object, the ABAP data object is set to its type-dependent initial value. If an empty XML element or empty JSON object is assigned to a structure, this has the same effect as non-existent elements on the structure components. The structure components retain their previous values. The transformation option clear with the value all can be used to initialize all data objects that have nonexistent or empty elements assigned to them.
In the case of the deserialization of internal tables with non-unique table keys, the order of the duplicate lines in relation to these keys is not retained.



Latest notes:

When a Simple Transformation is called, deserialization always creates an internal XML reader object, which can be addressed using the interface IF_SXML_READER from the sXML Library . The object is accessed using attributes of the ST statement tt:call-method.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLES_ABEXA
For an overview of all possible XML sources, see XML Sources of Transformations .
For transformations of XML data to DOM representation in the iXML Library, see iXML Library, DOM Representation .
For transformations of ABAP data to an XML writer in the sXML Library, see sXML Library, Transformation to XML Writer.
For deserializations of missing or empty asXML elements or asJSON object components, see:
Deserializing Missing Elements
Deserializing Empty Elements
For transformations of syntax characters to XML targets, see Transformation of Syntax Characters .
ABAP_EXAMPLE_END
• PARAMETERS CALL TRANSFORMATION

ABAP Addition ...$}$|(ptab)$}

What does it do?
This addition can be used to bind ABAP data objects e1 e2 ... to the parameters p1 p2 ... of an XSL transformation or a Simple Transformation. All elementary data objects and object references are allowed.
Instead of using a static parameter list, the parameters can be specified dynamically as value pairs in the columns of the internal table ptab that has one of the following types from the type pool ABAP:
abap_trans_parmbind_tab for specifying strings,
abap_trans_objbind_tab for specifying object references (for XSLT only),
abap_trans_parm_obj_bind_tab for specifying data references (for XSLT only).
Parameter Passing to XSL Transformations
The specified parameters must be defined as input parameters in an XSL transformation as follows:
<(><<)>xsl:param name='...' sap:type='...' />
The parameter name must be specified for the attribute name. Before a binding can take place, the case used in the XML document must match exactly the case specified in the ABAP runtime framework. If specified statically (b1, b2, ...), uppercase is used and if specified dynamically in rtab, the case used there is used.
For the optional attribute type, one of the type names string , number, boolean, nodeset, xstring, or object(...) can be specified, with a global ABAP class specified in parentheses behind object. The namespace before type must be defined as xmlns:sap='http://www.sap.com/sapxsl', with the prefix sap proposed as a convention.
If no type is specified in the transformation, the data types of elementary parameters are mapped to XSL types in accordance with the following table. ABAP Data TypeXSL Parameter Type
c, d, n, stringstring
i (b, s), f, pnumber
x, xstringstring, where the content is represented in Base 64.
If the XSL types shown in the table above are specified explicitly in the XSL transformation, appropriate elementary ABAP parameters must be specified that can be converted to the XSL type:
The XSL type boolean expects ABAP parameters of the type c with the length one. A blank is interpreted as false and any other character as true.
The XSL type xstring expects ABAP parameters of the type x or xstring and the content is represented as hexadecimal.
The XSL types nodeset and object expect an object reference variable that points to an instance of a class. The type nodeset expects appropriate object properties.
If a parameter does not match the XSL type, an uncatchable exception is raised. If a parameter defined in the XSL transformation is not passed, it is set to a default value in the transformation. Any specified parameters that are not defined in the XSL transformation are ignored.



Latest notes:

The XSL types string, number, boolean, and nodeset are standard XSL types, where xstring and object represent special SAP enhancements. The type xstring enables byte strings to be represented in hexadecimal instead of base 64. The type object enables ABAP methods to be called from the XSLT program.
The special addition OBJECTS can be used to pass object references, but this addition is replaced by PARAMETERS.
NON_V5_HINTS
ABAP_HINT_END
Parameter Passing to ST Programs
In an ST program, the parameters must be defined as follows as parameters of the main template outside of a template:
< tt:parameter name='...' $[kind='...'$]
$[$[s-val='...'$]$[d-val='...'$]$]$|$[val='...'$] />
When an ST program is called, output parameters and input/output parameters are supported as well as input parameters. The type of the parameter is defined using kind in the ST program, where in , out, and inout can be specified. inout is the default. The val attributes can be used to define replacement values.



Runtime Exceptions



Catchable Exceptions
CX_TRANSFORMATION_ERROR
Reason for error:
Common superclass of all transformation-specific exception classes for CALL TRANSFORMATION. The direct subclasses are CX_ST_ERROR for Simple Transformations and CX_XSLT_EXCEPTION for XSL transformations. When the statement CALL TRANSFORMATION is executed, exceptions of the class CX_TRANSFORMATION_ERROR and almost all its subclasses can be handled. The resumability of an exception of the subclass CX_ST_DESERIALIZATION_ERROR can be defined using the transformation option exceptions = 'resumable' . In addition, the following exceptions may be raised when a transformation is executed:
Exceptions like those raised in mappings from ABAP data types to asXML cannot be handled directly. These exceptions raise exceptions of the class CX_TRANSFORMATION_ERROR (or its subclasses) and can be handled using these.
Exceptions raised in ABAP methods called in transformations, such as transformations of objects using the methods SERIALIZE_HELPER and DESERIALIZE_HELPER or when accessing ABAP Objects from ST, raise exceptions of the class CX_TRANSFORMATION_ERROR (or its subclasses), if they are declared in the interface of the method RAISING. The resumability of the original exception is applied here. Non-declared exceptions, on the other hand, raise the exception CX_SY_NO_HANDLER, which cannot be handled using CX_TRANSFORMATION_ERROR (or its subclasses).
The exception CX_SY_STRING_SIZE_TOO_LARGE can also occur but does not raise an exception of the class CX_TRANSFORMATION_ERROR. It must be handled directly (see below). The attribute PREVIOUS of the associated exception object always contains a reference to the original exception. If an exception of this type is not handled, the short dump shows the original exception.
Subclasses of CX_ST_ERROR
CX_ST_CALL_ERROR
Reason for error:
Error when calling the transformation
CX_ST_CALL_METHOD_ERROR
Reason for error:
Exception in an ABAP method called from the transformation
CX_ST_CONDITION
Reason for error:
Error in a transformation condition
CX_ST_CONSTRAINT_ERROR
Reason for error:
Data object to be serialized or deserialized is too long.
CX_ST_DESERIALIZATION_ERROR
Reason for error:
Error in the deserialization
CX_ST_FORMAT_ERROR
Reason for error:
Format error in a node
CX_ST_INVALID_XML
Reason for error:
A serialization would produce invalid XML.
CX_ST_MATCH
Reason for error:
Deserialization match failed
CX_ST_REF_ACCESS
Reason for error:
Error in data node access
CX_ST_RUNTIME_ERROR
Reason for error:
Error in execution of the transformation
CX_ST_SERIALIZATION_ERROR
Reason for error:
Error in the serialization
CX_ST_VALIDATION_ERROR
Reason for error:
Failed validation with the attribute xsd-type in the ST statements tt:value, tt:write, or tt:read. This exception cannot be caught directly.
Subclasses of CX_XSLT_EXCEPTION
CX_XSLT_ABAP_CALL_ERROR
Reason for error:
Error when calling an ABAP method from XSLT
Runtime error:
XSLT_METH_ERROR
CX_XSLT_DESERIALIZATION_ERROR
Reason for error:
Error in the deserialization
Runtime error:
XML_NOT_SUPPORTED
CX_XSLT_FORMAT_ERROR
Reason for error:
Document is not in asXML format
Runtime error:
XML_FORMAT_ERROR
CX_XSLT_RUNTIME_ERROR
Reason for error:
Error in XSLT processor
Runtime error:
UNCAUGHT_EXCEPTION
CX_XSLT_SERIALIZATION_ERROR
Reason for error:
Error in the serialization
Runtime error:
XML_NOT_SUPPORTED
Other exception classes
CX_SY_STRING_SIZE_TOO_LARGE
Reason for error:
During a transformation, an operation with a string exceeds its maximum size. This exception does not raise an exception of the class CX_TRANSFORMATION_ERROR but must be handled directly. It can be handled for all kinds of transformations in the following cases:
The target specified behind RESULT is of type xstring or string.
The target specified behind RESULT is a reference variable that points to an object of the class CL_SXML_STRING_WRITER. It cannot be handled in the following cases:
BEGIN_SECTION VERSION 5 OUT
The target specified behind RESULT is an interface reference variable with the type IF_IXML_OSTREAM.
Methods of the iXML Library or sXML Library are involved that are implemented as kernel methods.
END_SECTION VERSION 5 OUT In these cases, a runtime error always occurs.

Return to menu