Creating transformations for internal tables

In this recipe, we will see how we can create transformations for internal tables. We will use the transformation editor to define the transformation for the internal table, ITAB, comprising of two fields, FIELD1 and FIELD2.

How to do it...

We will now see the steps for creating a transformation corresponding to internal tables:

  1. Create a simple transformation using the steps shown in the previous recipe. We will give it the name zst6_internal_table.
  2. Enter the following code in the transformation editor:
    How to do it...
  3. Next, we will write the code of the ABAP program that calls the transformation and supplies it with an ABAP internal table.
  4. We create an internal table with the name itab with fields field1 and field2 and fill it with the necessary data.
    How to do it...
  5. Finally, the CALL TRANSFORMATION statement is called, the internal table is passed, and the result is stored in xml_string.
    How to do it...

How it works...

The transformation contains a root element representing the internal table by the name of ITAB. Within the template, the XML literal element, itab, is defined to show the contents of the internal table. The tt:loop command is included. This command addresses each line of the table itab (since ref=".ITAB" is used as the current node). For each record of the table, the content of the XML element line is included in the XML file. Within the XML elements FIELD1 and FIELD2, the contents of the FIELD1 and FIELD2 fields of the relevant line of the table itab is written. Since the current node is the row of the internal table in question, including FIELD1 and FIELD2 it will print the right contents.

We create the program and pass the necessary data for itab. After the serialization, the resulting XML file appears as shown in the following screenshot:

How it works...
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.2.240