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 complex code inside this transformation. In this article we will show you, How to use Java Transformation to alter the transformation data with example.
For this 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 Destination table is Empty.
Java Transformation in Informatica Example
In this example we will show you, How to create and configure Java Transformation in Informatica. Before we start configuring, First let me connect with the Informatica repository service. In order to do so, we have to provide the Informatica Admin Console credentials. So, Please provide the appropriate Username and Password, and click the Connect button.
TIP: Here you have to provide the Admin Username and password that you specified while installing the Informatica Server.
Step 1: Create Source Definition for Java Transformation in Informatica
Once you connected successfully, Please navigate to Source Analyzer and define your Sources. In this example, we are using SP Source table from SQL Server database as our source definitions. Please refer Database Source in Informatica to understand the steps involved in creating source definition
Step 2: Create Target Definition
Please navigate to Target Designer to define the Target. In this example, we are using the existing SQL table (SP Destination) as our target definition. You can refer Create Informatica Target table using Source Definition to understand the process of creating target definition
Step 3: Create Mapping for Java Transformation
To create a new mapping, Please navigate to Mappings menu in Menu Bar and select the Create.. option.
Once you select the Create.. option, a new Mapping Name window will be opened as shown below. Let me provide m_Java as the mapping name and click OK button.
TIP : Please refer Informatica Mapping article to understand the procedure to create Mapping
Drag and drop the SP Source from Sources folder to the mapping designer. Once you drag the source, Power Center Designer will automatically create the source qualifier transformation (default transformation) for you. I suggest you to refer Source Qualifier Transformation article.
Step 3(a): Create Informatica Java Transformation
In order to create Java transformation in Informatica, Please navigate to Transformation menu in Menu Bar. Next, select the Create.. option.
Selecting the Create.. option will open the Create Transformation window as shown below. Please select the Java Transformation from drop down list and provide the unique name (Java_Employees) for this transformation and click on Create button
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.
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.
Double click on the Java transformation to see, and alter the properties. Below screenshot show you the list of available properties in Transformation tab:
- Select Transformation: By default it will select 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 about this transformation.
Below screenshot show you the list of available columns in the Ports tab. As you can all the columns that are 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.
In order to create new fields under the input section. Please select the INPUT and then click the New field button as we shown below.
In our source definition we have 7 columns so let me created 7 new fields under the INPUT section. We also need an extra output column for the New Income filed in our target table
Let me rename the Field names as per the Source Definition
Java Code Tab: This is used to write custom Java code. Here, Left side window is a Navigator window – Which holds all Input, Output ports that are available in Java transformation, and few regularly used functions.
Let me write a simple Java code
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.
Next, Drag and drop the target definition (SP Destination) from Targets folder to the mapping designer. Next, connect the Output Fileds of a Java Transformation with the target definition. You can use Autolink.. option to connect them.
Before we close the Mapping, Let us Save, and Validate the mapping by going to Mapping Menu bar, and select the Validate option.
Step 4: Create Workflow for Java Transformation
After you finish creating the Mapping, we have to create the workflow for it. PowerCenter Workflow Manager provides two approaches to create workflow.
In this example we will create the Workflow manually. To do so, Please navigate to Workflows Menu and select the Create option.
This will open Create Workflow window as shown below. Please provide the unique name (wf_JavaEmp) and leave the default settings.
Once we created the workflow, our next step is to create session task for our mapping.
Step 4(a): Create Session for Java Transformation
There are two types of sessions in informatica:
For this example we created a Non-reusable Session. In order to create Non-reusable Session, Please navigate to Tasks Menu and select the Create option as shown below.
Please provide a unique name for this session. Here, we are naming it as s_JavaEmp. Once you click on the Create button, a new window called Mappings will be opened. Here you have to select the mapping that you want to associate with this session i.e., m_Java.
Double click on the Session task will open 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. With in the Connections, click on the Arrow button beside the Relational type, and select the Database Object (Database Name) i.e., Informatica Source
Now, we have to configure the Target Connection. So, click on the SPDestination present in the Targets folder. With in the Connections, click on the Arrow button beside the Relational type, and select the Database Object (Target Database Name) i.e., Informatica Target
Next, navigate to Workflows Menu and select the Validate option to validate the Workflow.
Now, Let me start the Workflow. To do so, navigate to Workflows menu, and select the Start Workflow option.
Thank You for Visiting Our Blog