The Transaction Control Transformation in Informatica allows you to control the Transactions within the Transformation. Using this transformation you can Commit or Rollback the records (or rows) passing through it.
In this article, we will show you, How to use Transaction Control Transformation to Rollback the passing records with an 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.
TIP: We explained everything about the Transactions and its functionalities in SQL Server tutorial. I suggest you refer SQL Transaction article to understand the topic.
Transaction Control Transformation in Informatica Example
In this example, we will show you, How to use Transaction Control Transformation in Informatica to perform Rollback Transaction. 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: Source Definition for Transaction Control 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 for Informatica Transaction Control Transformation
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 to Create Informatica Target Table to understand the process of creating a target definition
Step 3: Create Mapping for Transaction Control Transformation in Informatica
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_Transaction 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 refer the Source Qualifier Transformation article.
Step 3(a): Create Informatica Transaction Control Transformation
In order to create Transaction Control 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 Transaction Control Transformation from the drop-down list and provide a unique name (Tran_Employee) and click on Create button
By clicking OK will create a Transaction Control Transformation for you.
Let me drag all the fields that are available in source definition to Transaction Control Transformation. Next, Drag and drop the target definition (SP Destination) from Targets folder to the mapping designer. Lastly, connect the Transaction Control Transformation fields with the target definition. You can use the Autolink.. option to connect them.
Double click on the Transaction Control Transformation to edit or configure the transformation. Please go to the Properties tab, and click on the Arrow beside the Transaction Control Condition to apply transactions at the mapping level.
Once you click the Arrow, an expression window will be opened as we shown below. The Expression window in Transaction Control Transformation uses the IIF Function to test each row against the condition.
Transaction Control provides the following built-in variables to apply transactions. For the demonstration purpose, let us take the above specified SP Source table and condition is EmpID = 5.
- TC_CONTINUE_TRANSACTION: This is the default value for this option. This does not perform any change for this row.
- TC_COMMIT_BEFORE: This is nothing but a Commit transaction in any relational database. If the condition is true then it will first Commit the transaction. Next, it will begin a new transaction and writes current row. Example: It will commit records up to EmpID 4 and begin a new transaction to commit records from 5
- TC_COMMIT_AFTER: If the condition is true then it will first write current row and Commit the transaction. Next, it will begin a new transaction. Example: It will write and commit records up to EmpID 5 and begin a new transaction to commit records from 6
- TC_ROLLBACK_BEFORE: This is nothing a Rollback transaction in any relational database. If the condition is true then it will first Rollback the transaction. Next, it will begin a new transaction and writes current row. Example: It will rollback records up to EmpID 4 and begin a new transaction to commit records from 5
- TC_ROLLBACK_AFTER: If the condition is true then it will first write current row and then Rollback the transaction. Next, it will begin a new transaction. Example: It will rollback records up to EmpID 5 and begin a new transaction to commit records from 6
Click Apply and then click OK to close the transformation window.
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 a Workflow for Transaction Control Transformation in Informatica
After you finish creating the Mapping, we have to create the workflow for it. PowerCenter Workflow manager provides two approaches to create a 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_Transaction) and leave the default settings.
Once we created the workflow, our next step is to create a session task for our mapping.
Step 4(a): Create a Session for Transaction Control Transformation in Informatica
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_Transaction. 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_Transaction.
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. Within 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. Within the Connections, click on the Arrow button beside the Relational type, and select the Database Object (Target Database Name) i.e., Informatica Target
Please change the Target Load Type to Normal or Bulk as per your requirements. Let me checkmark the Truncate target table option as well.
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 the Workflows menu, and select the Start Workflow option.
Let us open the SQL Server Management Studio and write following SQL Query to check whether we successfully transferred the data from a source or not. As you our target table is displaying records where EmpID = 10 because Rollback will start before processing the record whose EmpID, is 10
This time we will use the TC_ROLLBACK_AFTER as the second argument in IIF. It means Rollback option will be performed after passing the EmpID 10.
As you can see, our target table is displaying records where EmpID is greater than 10
Thank You for Visiting Our Blog