Java Transformation in Informatica

The Java Transformation in Informatica provides an opportunity to write a custom Java code within the transformation. If you are familiar with Java programming, then you can write a complex code inside this transformation.

For this Informatica Java Transformation example, we are going to use SP Source and Destination tables. From the below screenshot, you can see that the Source table has 15 records, and the Destination table is Empty.

Source and Destination 1

Java Transformation in Informatica Example

In this example, we show how to create and configure Java Transformation in Informatica. Before we start configuring, First, let me connect with the Informatica repository service.

To do so, we have to provide the Admin Console credentials. So, Please provide the appropriate Username and Password you specified while installing the Server.

Create Source Definition for Java Transformation in Informatica

Once you connected successfully, Please navigate to Source Analyzer and define your Sources. In this Informatica Java Transformation example, we are using the SP Source table from the SQL Server database as our source definitions. Please refer to Database Source to understand the steps in creating a source definition

Source analyzer 2

Create Java Target Definition

Please navigate to Target Designer to define the Target. In this Informatica Java Transformation example, we are using the existing SQL table (SP Destination) as our target definition. You can refer to Create Target table using Source Definition to understand the creation of a target definition

target Designer 3

Create Informatica Java Transformation Mapping

To create a new mapping for Informatica Java Transformation, Please navigate to the Mappings menu in Menu Bar. Next, select the Create.. option.

Create a Mapping 4

Once you select the Create.. option, a new Mapping Name window opens. Let me provide m_Java as the mapping name and click the OK button.

Java Transformation in Informatica 5

Drag and drop the SP Source from Sources folder to the mapping designer. Once you drag the source, Power Center Designer automatically creates the Source Qualifier Transformation (default transformation) for you.

Java Transformation in Informatica 6

Create Informatica Java Transformation

To create Java transformation in Informatica, Please navigate to the Transformation menu in Menu Bar. Next, select the Create.. option.

Java Transformation in Informatica 7

Selecting the Create.. option opens the Create Transformation window. Please select the Java Transformation from the drop-down list and provide the unique name (Java_Employees) for this transformation and click on Create button

Java Transformation in Informatica 8

Clicking the Create button will pop up a new window called Active or Passive. Please select whether you want to use this Java Transformation as an Active transformation or passive Transformation.

Java Transformation in Informatica 9

By clicking OK will create a Java Transformation for you. Let me drag all the fields that are available in source definition to Java transformation.

Java Transformation in Informatica 10

Double click on the Informatica Java transformation to see and alter the properties. Below screenshot shows you the list of available properties in the Transformation tab:

  • Select Transformation: By default, it selects the transformation you selected (or clicked on).
  • Rename: This button helps you to rename the transformation name.
  • Description: Use this place to provide a valid description.
Rename it 11

The below screenshot shows you the list of available columns in the Ports tab. As you can, all the columns dragged from the source definition are in the OUTPUT section.

TIP: Few people may not drag fields from Source Qualifier at this point. They will create both Input and Output fields on their own, and then they point them to Source Qualifier.

Java Transformation in Informatica 12

To create new fields under the input section, select the INPUT, and then click the New field button.

Java Transformation in Informatica 13

In our Informatica Java Transformation source definition, we have 7 columns. So let me create 7 new fields under the INPUT section. We also need an extra output column for the New Income filed in our target table

Java Transformation in Informatica 14

Let me rename the Field names as per the Source Definition

Java Transformation in Informatica 15

Java Code Tab: This is used to write custom Java code. Here, the Left side window is a Navigator window – Which holds all Input, Output ports that are available in Java transformation, and few regularly used functions.

Java Transformation in Informatica 16

Let me write a simple code for this Informatica Java Transformation

Java Transformation in Informatica 17

Within the above code, we used the If Else Statement along with Equals method to check whether the Occupation of an employee is Management or not. If it is TRUE then we are adding 45750 to yearly income otherwise we added 25009. Code that we used is:

EmpID = in_EmpID;
FirstName = in_FirstName;
LastName = in_LastName;
Education = in_Education;
Occupation = in_Occupation;
YearlyIncome = in_YearlyIncome;
Sales = in_Sales;
	NewIncome = in_YearlyIncome + 45750;
	NewIncome = in_YearlyIncome + 25009;

Once you finish configuring the Java Transformation, you have to map the Source qualifier with the Java Transformation Input fields.

Java Transformation in Informatica 18

Next, Drag and drop the target definition (SP Destination) from the Targets folder to the mapping designer. Next, connect the Output Fileds of a Java Transformation with the target definition using the Autolink.. option.

Java Transformation in Informatica 19

Before we close the Mapping, Let us Save, and Validate the mapping by going to Mapping Menu bar, and select the Validate option.

Create Java Workflow

After you finish creating the Informatica Java Transformation Mapping, we have to create the workflow for it. PowerCenter Workflow Manager provides two approaches to create a workflow.

In this Java Transformation example, we will create the Workflow manually. To do so, Please navigate to Workflows Menu and select the Create option.

Java Transformation in Informatica 20

It opens a Create Workflow window. Please provide a unique name (wf_JavaEmp) and leave the default settings.

create a workflow 21

Once we created the workflow, our next step is to create a session task for our mapping.

Create Java Transformation Session

There are two types of sessions:

For this Informatica Java Transformation example, we created a Non-reusable Session. To create Non-reusable Session, Please navigate to Tasks Menu and select the Create option as shown below.

Java Transformation in Informatica 22

Please provide a unique name (s_JavaEmp) for this session. Once you click on the Create button, a new window called Mappings will open. Here you have to select the mapping that you want to associate with this session, i.e., m_Java.

Java Transformation in Informatica 23

Double click on the Session task opens the Edit Tasks window. Within the mappings tab, we have to configure the Source, Target Connections.

First, let us configure the source connections by clicking on the SQ_SPSource source present in the Sources folder. Within the Connections, click on the Arrow button beside the Relational type, and select the Database Object (Database Name), i.e., Informatica Source

source connection 24

Now, we have to configure the Target Connection for this Informatica Java Transformation. So, click on the SPDestination present in the Targets folder. Within the Connections, click on the Arrow button beside the Relational type. Next, select the Database Object (Target Database Name), i.e., Informatica Target

target connection 25

Next, navigate to Workflows Menu and select the Validate option to validate the Workflow.

Java Transformation in Informatica 26

Now, Let me start the Informatica Java Transformation Workflow. To do so, navigate to the Workflows menu and select the Start Workflow option.

Java Transformation in Informatica 27

Let us open the SQL Server Management Studio and write following SQL Query.

Destination Table 28