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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-1.png?ezimgfmt=rs:651x559/rscb204/ng:webp/ngcb204)
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
![Java Transformation in Informatica 2](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-2.png?ezimgfmt=rs:703x327/rscb204/ng:webp/ngcb204)
Create Informatica Java Transformation 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
![Java Transformation in Informatica 3](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-3.png?ezimgfmt=rs:702x342/rscb204/ng:webp/ngcb204)
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.
![Java Transformation in Informatica 4](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-4.png?ezimgfmt=rs:703x486/rscb204/ng:webp/ngcb204)
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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-5.png?ezimgfmt=rs:701x319/rscb204/ng:webp/ngcb204)
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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-6.png?ezimgfmt=rs:740x314/rscb204/ng:webp/ngcb204)
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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-7.png?ezimgfmt=rs:740x314/rscb204/ng:webp/ngcb204)
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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-8.png?ezimgfmt=rs:740x384/rscb204/ng:webp/ngcb204)
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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-9.png?ezimgfmt=rs:740x385/rscb204/ng:webp/ngcb204)
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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-10.png?ezimgfmt=rs:740x268/rscb204/ng:webp/ngcb204)
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.
![Java Transformation in Informatica 11](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-11.png?ezimgfmt=rs:585x505/rscb204/ng:webp/ngcb204)
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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-12.png?ezimgfmt=rs:600x505/rscb204/ng:webp/ngcb204)
To create new fields under the input section, select the INPUT, and then click the New field button.
![Java Transformation in Informatica 13](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-13.png?ezimgfmt=rs:601x504/rscb204/ng:webp/ngcb204)
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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-14.png?ezimgfmt=rs:601x596/rscb204/ng:webp/ngcb204)
Let me rename the Field names as per the Source Definition
![Java Transformation in Informatica 15](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-15.png?ezimgfmt=rs:626x595/rscb204/ng:webp/ngcb204)
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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-16.png?ezimgfmt=rs:690x596/rscb204/ng:webp/ngcb204)
Let me write a simple code for this Informatica Java Transformation
![Java Transformation in Informatica 17](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-17.png?ezimgfmt=rs:691x581/rscb204/ng:webp/ngcb204)
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; if(in_Occupation.equals("Management")) { NewIncome = in_YearlyIncome + 45750; } else { NewIncome = in_YearlyIncome + 25009; } generateRow();
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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-18.png?ezimgfmt=rs:740x332/rscb204/ng:webp/ngcb204)
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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-19.png?ezimgfmt=rs:740x338/rscb204/ng:webp/ngcb204)
Before we close the Mapping, Let us Save, and Validate the mapping by going to Mapping Menu bar, and select the Validate option.
Create Informatica Java Transformation 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 Informatica 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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-20.png?ezimgfmt=rs:740x342/rscb204/ng:webp/ngcb204)
It opens a Create Workflow window. Please provide a unique name (wf_JavaEmp) and leave the default settings.
![Java Transformation in Informatica 21](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-21.png?ezimgfmt=rs:528x592/rscb204/ng:webp/ngcb204)
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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-22.png?ezimgfmt=rs:740x403/rscb204/ng:webp/ngcb204)
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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-23.png?ezimgfmt=rs:737x576/rscb204/ng:webp/ngcb204)
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
![Java Transformation in Informatica 24](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-24.png?ezimgfmt=rs:740x474/rscb204/ng:webp/ngcb204)
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
![Java Transformation in Informatica 25](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-25.png?ezimgfmt=rs:740x472/rscb204/ng:webp/ngcb204)
Next, navigate to Workflows Menu and select the Validate option to validate the Workflow.
![Java Transformation in Informatica 26](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-26.png?ezimgfmt=rs:740x378/rscb204/ng:webp/ngcb204)
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](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-27.png?ezimgfmt=rs:739x343/rscb204/ng:webp/ngcb204)
Let us open the SQL Server Management Studio and write following SQL Query.
![Java Transformation in Informatica 28](/Apps/Informatica/Informatica-odbc-connection/Java-Transformation-in-Informatica-28.png?ezimgfmt=rs:624x554/rscb204/ng:webp/ngcb204)