Executing a sub-transformation

There are two dedicated steps to use or execute a sub-transformation: Mapping (sub-transformation) step and Simple Mapping (sub-transformation) step. To execute a sub-transformation like the one created earlier, we will use the second one.

In this example, we will read a file that looks like the following one:

student_code;name;writing;reading;speaking;listening
80711-85;William Miller;81;83;80;90
20362-34;Jennifer Martin;87;76;70;80
75283-17;Margaret Wilson;99;94;90;80
83714-28;Helen Thomas;89;97;80;80
61666-55;Maria Thomas;88;77;70;80
...

After reading the file, we will call the sub-transformation to split the student's name.

Before starting, get the sample files from the book site. You will find several files, all of them with the same structure. Alternatively, you can create your own file with any sample data.

Here are the instructions:

  1. Create a Transformation.
  2. With a Text file input step, read the exam1.txt file that comes with the code bundle for the chapter.
  3. From the Mapping category of steps, drag to the work area a Simple Mapping (sub-transformation) step (we will call it Mapping for short). Create a link from the Text file input step toward this new step.
  4. Double-click on the Mapping step to configure it.
  5. In the Transformation: textbox, type the full path for your sub-transformation, for example, ${Internal.Entry.Current.Directory}/subtransformations/split_word.ktr.
  1. Select the Input tab, and fill the grid as shown:
Configuring an Input tab
  1. Select the Output tab, and fill the grid as shown:
Configuring an Output tab
  1. Close the window.
  2. After the Mapping step, add a Dummy step.
  1. With the Dummy step selected, run a preview. You will see this:
Previewing the output of a sub-transformation

As you can deduce, the key to call a sub-transformation is to establish a relationship between the fields in your main Transformation and the fields in the sub-transformation. You do it by filling the Input and Output tabs in the Mapping step dialog window.

Let's start by explaining the input. In the input specification of the sub-transformation, you can see that it expects a field named word. In your Transformation, the field that you want to transform is called name. Therefore, in the Input tab of the Mapping step dialog window, you defined the mapping between name and word.

On the other end, the sub-transformation creates two new fields: first_word and other_words. These fields will be added as fields to the main Transformation. If you want to give them a different name, you do it in the Output tab of the Mapping step dialog window, just as you did in the tutorial.

Before going on with advanced features, let's remark two things about sub-transformations: