One of the most used transformation that I use as part of SSIS is the Foreach loop which *gasp* just isn’t there in Informatica out-of-the-box. In this post, let’s look at how it’s done.
Test Data
I have three files named StudentsData001.txt, StudentsData002.txt, StudentsData003.txt. In each of the file, there are two columns – Id, Name such as
Id,Name 1,Karthik 2,Pratap
Our goal is to integrate all the data from all the three files into a table Students which has two columns Id and Name.
Steps to be done
Open the PowerCentre Designer. Go to Source and click on Import from file as shown below –
Chose one of file from the source folder and in the next window, ensure to check on ‘Import field names from first line’. –
Accept the defaults and complete the wizard by setting the appropriate size for the ‘Name’ column. Once the source is set-up, we would need to set-up the destination. Go to ‘Tools’->’Target Designer’ and then go to – ‘Targets’ -> ‘Import from Database’ as shown below and connect to the ‘Students’ table where you want all the data to be imported-
Go to ‘Tools’ -> ‘Mapping Designer’ and then go to – ‘Mappings’->’Create’. Drag and drop both the source and destination on to the mapping designer and then connect the source data on to the destination as shown below for ‘Source’ –
Connect both the columns from ‘Source Qualifier’ and connect to ‘Destination’ by dragging and the dropping the columns.
Once it is set, generate the workflow by going to ‘Mappings’ -> ‘Generate Workflow’. Just follow the wizard and click on ‘Next’ till it finishes.
What we have done so far is a basic set-up just like in SSIS when we do the DFT containing the Flat File Source to the OLE-DB Destination (or whichever destination). The actual work of looping is now to be done at the session level. Even before we get to that, what we need to remember is – Informatica has two modes of handling Flat Files – Direct and Indirect Mode. We need to use Indirect Mode to handle the multiple files list.
First thing is we need to create a file containing the list of all the file names in it. I created a file called ImportFileList.txt as shown below –
Open the PowerCentre Workflow. Open the worfklow wf_m_FF_To_Database and then double-click on the session – s_m_FF_To_Database. ‘Edit Tasks’ window would open up as shown below –
Go to Mappings tab and under ‘Sources’ click on the ‘SQ_StudentsData001’. In the bottom most window set the following properties –
- Source filetype – Indirect
- Source file directory – Path of the directory where the InputFileList.txt is present.
- Source filename – ImportFileList.txt
That’s about it. Those are the basic changes that are to be done. Save the workflow after performing the above changes. Also ensure, under Connections tab the , Students – DB Connection connection name is valid.
The next step is to start the workflow by going to – Workflows -> Start Workflow. Once it is successful you would see that all files are processed and the ImportFileLIst.txt is no longer existing, The results post-processing are shown below –
Next Steps –
- How do go about automating this file generation file? Am guessing we would need to have a command task in workflow reading the files and generating the file.
- How does it change from DEV to say UAT i.e. basically how do we localize it?
in SSIS you dont need to give any file name in informatica you need to create file list file
is there any way in which we can auto generate file list to give as file list as indirect file
Hi Kumar, Yes, we should be able to generate the file list automatically as I indicated in my post using command line tools within Informatica mappings. I will come back with a link (or) post new article explaining how to do.
can you share the link on how to automate