Lean Informatica Power Center : www.info-etl.

com

Java Transformation
Applies to:
Informatica PowerCenter

Summary
This article briefs about implementing FOR loop in Informatica using Java Transformation.

Learn Informatica Power Center: www.info-etl.com

1

..................................................................................................................................................................................................................................................................................................................................................................................................................................................... 4 EXPRESSION TRANSFORMATION ..... 4 JAVA TRANSFORMATION ........................................................................................................................................................................................................................................................................................................................info-etl......................................................................................................................................... 3 SOLUTION OVERVIEW ......................................................................... 6 ADVANTAGES .............................................................................................com 2 ............................................................................................................................... 4 SOLUTION STEPS............................Implementing FOR loop in Informatica PowerCenter Table of Contents INTRODUCTION ................................. 8 Learn Informatica Power Center: www......... 3 TARGET.. 6 OUTPUT ........................ 7 DISCLAIMER AND LIABILITY NOTICE ................. 4 SOURCE .................................................................................................................................................................................. 5 TARGET............................................................................................................................................................................................................................................................. 3 REQUIREMENT ....................................................... 3 SOURCE ........................................

Implementing FOR loop in Informatica PowerCenter INTRODUCTION This article briefs about implementing FOR loop in Informatica using Java Transformation.com 3 . SOURCE Salesperson Name | Tour from Date | Tour to Date | Place Sukumar | 20091117 | 20091119 | Chennai Ram | 20091117 | 20091119 | Bangalore Sukumar | 20091120 | 20091122 | Bangalore Ram | 20091120 | 20091122 | Chennai Our requirement is to generate Tour Table TARGET that contains the following TARGET Salesperson Name Date Place Sukumar 20091117 Chennai Sukumar 20091118 Chennai Sukumar 20091119 Chennai Sukumar 20091120 Bangalore Sukumar 20091121 Bangalore Sukumar 20091122 Bangalore Ram 20091117 Bangalore Ram 20091118 Bangalore Ram 20091119 Bangalore Ram 20091120 Chennai Ram 20091121 Chennai Ram 20091122 Chennai Learn Informatica Power Center: www. REQUIREMENT Consider that we are receiving a ‘|’ delimited flat file that contains the sales person’s tour information.info-etl.

SOLUTION STEPS SOURCE Delimited Flat File TourInfo.YYYYMMDD) ToDate_out Date time O To_date(ToDate. Place String(20) O Use the substring. FromDate_out Date time O To_date(FromDate.Implementing FOR loop in Informatica PowerCenter SOLUTION OVERVIEW To achieve the above requirement we will be using the Java Transformation available in Informatica PowerCenter.info-etl.txt Salesperson Name | Tour from Date | Tour to Date | Place Sukumar | 20091117 | 20091119 | Chennai Ram | 20091117 | 20091119 | Bangalore Sukumar | 20091120 | 20091122 | Bangalore Ram | 20091120 | 20091122 | Chennai EXPRESSION TRANSFORMATION Port Name Data Type Type Expression Description String(255) I Salesperson Name String(50) O Use the substring. instr function to retrieve the sales person name using the | delimiter. instr function to retrieve the ’From Date’ using the | delimiter. FromDate String(20) V Use the substring.YYYYMMDD) Expression transformation is used for retrieving the values from the flat file source and assigns values to individual ports. Learn Informatica Power Center: www. instr function to retrieve the ‘To Date’ name using the | delimiter.com 4 . ToDate String(20) V Use the substring. instr function to retrieve the ‘Place’ using the | delimiter.

getInstance ( ) .compareTo ( endCal ) <= 0. startCal.*.com 5 . Date date_end=new Date(ToDate.setTime ( date_start) .DAY_OF_WEEK.add (Calendar. FromDate_out =formatter.format(FromDate). Port Name Data Type Type Salesperson Name String(50) I/O FromDate String(20) I ToDate String(20) I Place String(20) I/O FromDate_out Date time O ToDate_out Date time O TourDate DateTime O Link the FromDate_out. Calendar endCal = Calendar. c.setTime ( date_end) .util. Calendar startCal = Calendar. Import Package tab place the below code: Import java. This is to import relevant java packages.longValue()). ToDate_out =formatter. formatter = new SimpleDateFormat("dd-MMM-yy"). • Create the following ports.info-etl. Date date_start=new Date(FromDate.getInstance ( ) . 1 ) ) { Learn Informatica Power Center: www.longValue()). toDate_out from the Expression Transformation to the From Date and To Date ports of the Java transformation.Implementing FOR loop in Informatica PowerCenter JAVA TRANSFORMATION • Drag the java transformation into the Mapping.*. • Under the Java code tab. Import java.text. • Under "On InputRow " tab place the following code DateFormat formatter . for ( Calendar c = startCal.format(ToDate). c. endCal.

Implementing FOR loop in Informatica PowerCenter TourDate= formatter.format(c. • You can see for loop construction based on the from date and the to date. TARGET Relational Table TOUR Description DataType Sales Person name String Tour Date Date time Place String OUTPUT Source: Sukumar | 20091117 | 20091119 | Chennai Target: Salesperson Name Date Place Sukumar 20091117 Chennai Sukumar 20091118 Chennai Sukumar 20091119 Chennai Java transformation takes the ‘from date’ and ‘to date’ as input and a FOR loop is constructed. Learn Informatica Power Center: www. } • The above code snippet uses the java calendar function.getTime ()). For each input row based on the ‘from date’ and ‘to date’ java transformation will generate multiple rows. generateRow().info-etl. • We need to link the salesperson name. Tour Date and Place ports from this java transformation to the target.com 6 . In our case for a single row in source we will be generating 3 rows in target.

.Implementing FOR loop in Informatica PowerCenter ADVANTAGES • Java transformation can be used to generate multiple rows based on a condition. • Normalizer can generate rows based on the ‘Occurs’ clause where we will specify a static number but if you want to generate multiple rows based on a dynamic value then go for java transformation.

Sign up to vote on this title
UsefulNot useful