Vous êtes sur la page 1sur 12

Flat File Validation Using Informatica

Table of Contents
1. 2. 3. 4. 5. Assumption Summary Objective Source definition 3 Target definition 5.1 Target T_FILE_PROCESS_STATUS 5.2 Target EMPLOYEE 6. 4 Mappings. 6.1 Mapping to validate the source file: m_ValidateSourceFile 6.1.1 Transformations used 6.2 Mapping to load source file: m_LoadFile 6.2.1 Transformations used 7. 5 Sessions 8. 6 Workflow

Assumptions: Assume that the flat file is having one header (stats with H) and one trailor (Starts with T). Flat file should exist in the local directory. File size should not be zero (if it zero we have option to check file size at informatica level). File is having some records more than two (Including header and trailor)

Flat file validation process Summary: The intention of this case study is to give an idea about validation of a flat file source using information in file trailor. File will contain total record count in trailor and same will be verified with actual record count received in file before loading to target. If file is found to be valid, loading will be done else a record will be inserted in status table indicating that file to be processes is invalid.

1. Objective The intention of this case study is to give an idea about validation of a flat file source using information in file trailor. File will contain total record count in trailor and same will be verified with actual record count received in file before loading to target. If file is found to be valid, loading will be done else a record will be inserted in status table indicating that file to be processes is invalid. Other scenarios:

2. Source Definition: Sample flat file source is a comma separated values file having employee records. In addition file is having a header (starting with H) and a trailor (starting with T). Header record contains file sequence number and trailor record contains total number of records in file (including header and trailor record). In sample file total records in file are 14 (including header and trailor). File trailor is T14. Data records are having columns empno, ename, job, mgr, hiredate, sal, comm, and deptno.

3. Target Definition 3.1 Target T_FILE_PROCESS_STATUS First target is relational table (oracle) T_FILE_PROCESS_STATUS and has below structure.

This table will be used to load file information when the file is not valid. In case of a valid file nothing will be loaded in this table. Example data in this table for invalid & valid file will be as shown below.

Process_Date 01/12/2010 02/12/2010

Header_SeqNo 1500 1500

Trailor_count 12 14

File_Record_count 14 14

Is_File_Valid N Y

3.2 Target EMPLOYEE Second target is EMPLOYEE table with below structure.

4. Mappings 4.1 Mapping to validate the source file: m_ValidateSourceFile Below shown is a prototype of the mapping to check if total record count of file matches with record count specified in trailor. If there is a mismatch then a status record will be inserted in T_FILE_PROCESS_STATUS. For a valid record count in trailor, no record will be inserted in target table.

4.1.1 Transformations used a) exp_Header_Trailor: This expression is used after Source Qualifier to identify file header and file trailor. In this expression total number of records in file is also calculated.

In expression define following variable ports and output ports. Eg; Input column; empno

Please see the below expression used in different Variable ports: Port Name Expression

v_HeaderSeqNo

IIF (SUBSTR (Empno, 1, 1) ='H', SUBSTR (Empno, 2), NULL)

v_TrailorRecCnt

IIF SUBSTR (Empno, 1, 1) ='T', SUBSTR (Empno, 2), NULL)

v_FileRecCnt

v_FileRecCnt + 1

O_ProcessDate

SYSDATE

Variable to extract header sequence number is v_HeaderSeqNo, variable to extract trailor record count is v_TrailorRecCnt and variable to count total number of records in file is v_FileRecCnt. b) AGG_HEADER_TRAILOR_ROWCOUNT Aggregator is used to make a single row for header sequence number, trailor record count and file record count. Port Name O_ HeaderSeqNo Datatype string Precision 10 Scale 0 I Y O Y V Expression Group By

O_TrailorRecCnt O_File_Rec_Cnt O_Prosess_date O_File_header O_file_trailor O_File_rec_count

string interger Date/time interger interger interger

10 10 29 10 10 10

0 0 0 0 0 0

Y Y Y

Y Y Y Y Y Y Max(O_ HeaderSeqNo) Max (O_TrailorRecCnt ) Max(O_File_Rec_Cnt) Y

Port o_ProcessDate is specified as Group By port. C) exp_VALIDATE_ROCCOUNT This expression is used to compare trailor record count with file record count.

Output port o_IsFileValid uses below expression to check if trailor record count matches with file record count. If there is a mismatch then o_IsFileValid flag is set to N. Port Name O_isFile_Valid Expression IIF (o_FileTrailor != o_FileRecCount,'N')

d) FIL_INVALID_FILE This filter will pass the row only when o_IsValidFile flag is N i.e. trailor record count does not match with file record count. Filter condition is o_IsFileValid = 'N'. 4.2 Mapping to load source file: m_LoadFile This is simple source to target mapping with a filter in place to skip file header and trailor.

4.2.1 Transformations used FIL_HEADER_TRAILOR Filter is used to skip file header and trailor. Only data records will be passed and loaded to target T_EMPLOYEE. Filter condition used is SUBSTR (Empno, 1, 1)! = H AND SUBSTR (Empno, 1, 1) != 'T' 5. Sessions Session tasks will be created corresponding to each mapping. Session s_ValidateSourceFile is for mapping m_ValidateSourceFile. Session s_LoadFile is for mapping m_LoadFile. As date in source file is in DD-MON-YY format, DateTime Format String is changed from default to DD-MON-YY. All other settings are default.

6. Workflow (wf_LoadFile): Simple workflow as shown below is created using a start task and two session tasks.

Condition to execute session wf_LoadFile is defined as below expression. IIF ($s_ValidateSourceFile.TgtSuccessRows = 0, $s_ValidateSourceFile.Status = succeeded, $s_ValidateSourceFile.Status = failed) With this condition is place, session s_LoadFile will execute only when no row is being inserted to target by session s_ValidateSourceFile. As per the mapping logic, m_ValidateSourceFile will insert the row in target only when file is failed for validation. So no row inserted in target means file is valid and should be loaded to EMPLOYEE table using m_LoadFile mapping. Using sample flat file to execute this workflow will insert no row in T_FILE_PROCESS_STATUS. 12 rows will be inserted to EMPLOYEE table.