Sunteți pe pagina 1din 9

Working with Informatica Flatfiles

Published on Sunday, 18 December 2011 12:06 Written by Saurav Mitra inShare1 In this article series we will try to cover all the possible scenarios related to flatfiles in Informatica. Requirement 1: Let us look into the first requirement: Generate respective flatfiles containing employee information for each department. So for each and every department we will generate flatfiles in a dynamic manner from our employee database table. 1. Select Source Analyzer and Import the Relational database table emp. 2. Next open the Target Designer.Select the EMP table, from the Sources of your Informatica folder found on the Repository Navigator.Just drag and drop the EMP table to the Target Designer. Next Edit the target definition as follows. o Rename the Select table to FF_EMP_DEPTNO. o Change the Database type to Flat File. o Change the desired Flat file information fields. In this case we set it to Delimited. o Click on Advanced Flat file information and set the Column Delimiters as , o Next select the Columns tab. On the right-hand corner click the icon Add FileName column to this table. A new port or column FileName with string datatype is created.

Apply the above target definition changes.

So our source table EMP and target flatfile instance FF_EMP_DEPTNO are now ready, so we are good to go to set the mapping logic to generate dynamic flatfiles per department. 3. Find the mapping screenshot below:

4. First of all sort the employee records based on the deptno in the source qualifier.

5. Next in the expression transformation we need to flag records based on the change in deptno. In the expression transformation add the following ports: o FileName as Output Port o COMP_DEPTNO as Variable Port o FLAG as Output Port o PREV_DEPTNO as Variable Port

Now find the expressions for all the above ports of the expression transformation.
FileName:'FF_DEPT_' || TO_CHAR(DEPTNO) || '.csv' COMP_DEPTNO:IIF(DEPTNO PREV_DEPTNO, 1, 0) FLAG:COMP_DEPTNO PREV_DEPTNO:DEPTNO

6. Now find the Transaction Control Condition, based on which the commit is issued to place the end of file for one dept and opens to write new file.
7. 8. IIF(FLAG = 1, TC_COMMIT_BEFORE, TC_CONTINUE_TRANSACTION) 9.

So when there is change in the deptno, then the commit is issued to end the current file and a new file is open to write emp information of new deptno. Also note that with the introduction of Transaction Control Transformation the Commit Type is set to User Defined.

We are done with our first requirement. Requirement 2: Now we try the reverse scenario i.e. load the database employee table with the information in the form of flatfiles received from source systems. These flatfiles have employee information based on each department; Also the number of files or departments is not know in Advance. Note, that the part of the flatfile name bears the dept information that also need to be mapped to deptno column of the employee table. Here we go: 1. Select Source Analyzer to Import FlatFile definition. o Select the option Import from File. o Next select the file FF_DEPT_10.csv in TgtFiles directory, considering that the file we generated from our previous example will be the source definition in this case. o Next select Flat File Type as Delimited. o Enter FF_EMP_DEPTNO as the name of this source definition. o Select start import at row 1, since we dont have any header record. o Next select the delimiter as Comma. o Next modify the field names and corresponding datatypes accordingly. o Next in the Properties tab check the option Add Currently Processed Flat File Name Port. When this option is selected, a port specifying currently processed file name gets added to the source definition.

Apply the above source definition changes.

Our Source flat file definition is ready. There are also other easy ways to create this source file definition like export/import and modify emp table or create flatfile option. 2. Next import the EMP table in the Target Designer. Alternatively you can drag and drop the source definition of EMP imported in the earlier example. So our source flatfile definition FF_EMP_DEPTNO and target table instance EMP are now ready, so we are good to go to set the mapping logic to extract employee information from different department specific flatfiles. 3. Find the mapping screenshot below:

4. Next in the expression transformation we will extract the deptno information contained in the filename. Also note we have treated hiredate as varchar2(10) in source flatfile definition. Hence we need to convert it to date before loading to EMP target table. In the expression transformation add the following ports: o OUT_HIREDATE as Date/Time Output Port o DEPTNO as Output Port

Now find the expressions for all the above ports of the expression transformation.
OUT_HIREDATE:TO_DATE(HIREDATE, 'MM/DD/YYYY') DEPTNO:TO_DECIMAL( SUBSTR(CurrentlyProcessedFileName, INSTR(CurrentlyProcessedFileName, 'FF_DEPT_', 1) ) )

5. Next let us look at Mapping tab of the Session property. o Set Source filetype as Indirect. o Set Source file directory as $PMTargetFileDir\, as this is currently where our file resides. o Set Source filename as FF_EMP_DEPTNO.txt

Next comes the question of setting the filelist in the Indirect file, from where Integration service will read the files. We can use pre-session command to write the list of files present in the directory in the indirect file. 6. Use a Pre-Session Command to generate the Indirect file with the list of files at runtime.

Find below a sample Windows command to do the same


dir /b /on $PMTargetFileDir\FF_DEPT*>$PMTargetFileDir\FF_EMP_DEPTNO.txt

S-ar putea să vă placă și