The Command Task in Informatica is used to run Unix or Shell commands during the Workflow. You can use this task to Move, Copy or Remove files after the data is loaded etc. In this article we will show you, How to use Command Task in Informatica with example.
For this example, we are going to use below show text file data (Employee table). From the below screenshot you can see that the Source table has 15 records
and the Destination table is Employee File. As you can see, it is an Empty table
Command Task in Informatica Example
Before we start configuring the Command Task in Informatica to Load Data from Flat File to SQL Server. 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 Informatica Command Task
Once you connected successfully, Please navigate to Source Analyzer to define your Sources. As we said before, we are using Employee table present in the local File System as our source definitions. So, Please navigate to Source menu and select the Import from File.. option as shown below
Once you select the Import from File.. option, a new window called Open Flat File will be opened as shown below. Please select the Employee.txt file from your local file system and click Open button. I suggest you to refer Flat File Source in Informatica article to under the following steps.
From the below screenshot you can observe that, you can see our newly created Flat File source in Informatica
TIP : We already explained the steps involved in importing Text file in our previous article. So, Please refer Flat File Source in Informatica to understand the same.
Step 2: Create Target Definition for Command Task in Informatica
Please navigate to Target Designer to define the Target. In this example, we are using the existing SQL table (Employee File) as our target definition. You can refer Create Informatica Target Table to understand the process of creating target definition
Step 3: Create Mapping for Command Task 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_SQLEmp 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 Employee source definitions from Flat File Sources folder to the mapping designer. Once you drag the source, Power Center designer will automatically create the source qualifier for you. I suggest you to refer Source Qualifier Transformation article
Next, Drag and drop the target definition (Employee File) from Targets folder to the mapping designer. Next, connect the source qualifier with the target definition. Please use the 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 a Workflow for Command Task in Informatica
After we 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_CommandEx) 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 a Session for Command Task 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_CommandEx. 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_CommandEx.
Double click on the Session task will open the Edit Tasks window. Within the mappings tab, we have to configure the Source, and Target Connections. First, let us configure the Target connection by clicking on the EmployeeFile.
With in the Connections, click on the Arrow button beside the Relational type, and Select the Target Database (Informatica Target)
Now, we have to configure the Source Connection. Please click on the SQ_Employee present in the Sources folder.
- Source File directory: Informatica will use the default directory but you can change the directory by giving full path.
- Source filename: It will automatically detect. If not, Please specify the file name along with the extension.
Next, navigate to Workflows Menu and select the Validate option to validate the Workflow.
Step 4(b): Create a Command Task in Informatica
In order to create a Command Task, First go to the Task Developer Tab. Next, navigate to Tasks Menu and select the Create option as shown below.
Once you select the Create option, a new window called Create Task will be opened as we shown below. First select the Command Task from the drop down list. Next, provide a unique name for this task and click on the Create button. Here, we are naming it as cmd_CopyFile.
Click on the Create button will create a Command task for you
Double click on the Command Task will open the following window. Within the General Tab, we can rename the Command Task to more meaningful name. Please do not forget to provide the valid description about the Task.
Within the Properties Tab, there is one property called :
- Fail Parent if this task fails: Please check mark this option. If this Command Task fails then it will fail the workflow.
Within the Commands Tab, you have to provide the command that you are going to use in this workflow. Please click on New button to add new command
We renamed the field as the Copy Command. Next, click on the Arrow to add the command
This will open an empty space to write your command. For this example, we are using the Copy command to copy the Employee File from Source Files to target files
Next, navigate to Workflows Menu and select the Validate option to validate the Workflow. If you observe the workflow, First we are starting the Workflow, Next it will run the Session task to load data from text file to SQL table. Once the data is transferred, Command Task will copy Employee File from Source to target
Now, Let me start the Workflow. To do so, navigate to Workflows menu, and select the Start Workflow option.
Now you can see the Employee file in Informatica default target location.
Command Task in Informatica Example 2
Instead of creating a Separate command task, you can also apply the functionality within the Session Task. Let me remove the Command task from the workflow to demonstrate the same.
Double click on the Session task, and go to the Components tab as we shown below
- Pre-Session Command : This command will be executed before the Session
- Post-Session Command : This command is executed after the Session complete
- Post-Session Failure Command : This command will be executed, if the session task fails
For this example, we are going to create a command that has to execute after the Session is complete (Post-Sessin). Under the Type drop down we have three option. Let me select the Non-reusable command
Click on the New field
next, click the Arrow field to write a command
For this example, we are using the Move command to move the Employee File from Source Files to target files
Let me run the workflow and see. As you can see there is no Employee under the Source folder
and the destination folder has this employee file
Thank You for Visiting Our Blog