In this recipe, we will see how we can create transformations that correspond to a nested structure defined within an ABAP program. We will create a transformation, then call the transformation from a program using the CALL TRANSFORMATION
statement and pass it to a populated ABAP structure corresponding to the root element of the transformation. We will then see how serialization will generate the XML stream.
We will now see the steps needed to create a transformation corresponding to a structure:
XSLT_TOOL
. Then, enter a suitable name for your transformation. We gave it the name ZST6_FOR_STRUCTURE
.struc
. It has a field field1
and contains another structure nest1
, comprising of the fields field1
and field2
.xml_string
and call the transformation using the CALL TRANSFORMATION
statement. The result of the CALL TRANSFORMATION
statement corresponding to the passed structure is returned in xml_string
.The transformation created is comprised of a structure that will be passed during serialization via the root variable struc
. Within the XML literal elements X1
, X3
, and X4
, the current node is set using the reference of the data root struc
. For X1
, we include the field field1
of struc
. For X3
, we address the field1
field of the nest1
structure contained within struc
.
The ABAP program calls the transformation using the CALL TRANSFORMATION
statement. Since it is serialization, we passed a populated ABAP structure struc
as the SOURCE
structure. The result is read into xml_string
. The contents of the string xml_string
may be viewed in the ABAP debugger, as shown in the following screenshot:
18.116.14.245