Chapter 5

Expression Transformation
This chapter includes the following topics:
♦ ♦

Overview, 142 Creating an Expression Transformation, 143


Transformation type: Passive Connected

Use the Expression transformation to calculate values in a single row before you write to the target. For example, you might need to adjust employee salaries, concatenate first and last names, or convert strings to numbers. Use the Expression transformation to perform any nonaggregate calculations. You can also use the Expression transformation to test conditional statements before you output the results to target tables or other transformations.
Note: To perform calculations involving multiple rows, such as sums or averages, use the

Aggregator transformation. Unlike the Expression transformation, the Aggregator lets you group and sort data. For more information, see “Aggregator Transformation” on page 37.

Calculating Values
To use the Expression transformation to calculate values for a single row, you must include the following ports:

Input or input/output ports for each value used in the calculation. For example, when calculating the total price for an order, determined by multiplying the unit price by the quantity ordered, the input or input/output ports. One port provides the unit price and the other provides the quantity ordered. Output port for the expression. You enter the expression as a configuration option for the output port. The return value for the output port needs to match the return value of the expression. For more information about entering expressions, see “Working with Expressions” on page 10. Expressions use the transformation language, which includes SQL-like functions, to perform calculations.

Adding Multiple Calculations
You can enter multiple expressions in a single Expression transformation. As long as you enter only one expression for each output port, you can create any number of output ports in the transformation. In this way, use one Expression transformation rather than creating separate transformations for each calculation that requires the same set of data. For example, you might want to calculate several types of withholding taxes from each employee paycheck, such as local and federal income tax, Social Security and Medicare. Since all of these calculations require the employee salary, the withholding category, and/or the corresponding tax rate, you can create one Expression transformation with the salary and withholding category as input/output ports and a separate output port for each necessary calculation.


Chapter 5: Expression Transformation

Creating an Expression Transformation
Use the following procedure to create an Expression transformation.
To create an Expression transformation: 1.

In the Mapping Designer, click Transformation > Create. Select the Expression transformation. Enter a name for it (the convention is EXP_TransformationName) and click OK. Create the input ports. If you have the input transformation available, you can select Link Columns from the Layout menu and then drag each port used in the calculation into the Expression transformation. With this method, the Designer copies the port into the new transformation and creates a connection between the two ports. Or, you can open the transformation and create each port manually.
Note: If you want to make this transformation reusable, you must create each port


manually within the transformation.
3. 4.

Repeat the previous step for each input port you want to add to the expression. Create the output ports (O) you need, making sure to assign a port datatype that matches the expression return value. The naming convention for output ports is OUT_PORTNAME. Click the small button that appears in the Expression section of the dialog box and enter the expression in the Expression Editor. To prevent typographic errors, where possible, use the listed port names and functions. If you select a port name that is not connected to the transformation, the Designer copies the port into the new transformation and creates a connection between the two ports. Port names used as part of an expression in an Expression transformation follow stricter rules than port names in other types of transformations:
♦ ♦


A port name must begin with a single- or double-byte letter or single- or double-byte underscore (_). It can contain any of the following single- or double-byte characters: a letter, number, underscore (_), $, #, or @.


Check the expression syntax by clicking Validate. If necessary, make corrections to the expression and check the syntax again. Then save the expression and exit the Expression Editor.

7. 8. 9.

Connect the output ports to the next transformation or target. Select a tracing level on the Properties tab to determine the amount of transaction detail reported in the session log file. Click Repository > Save.

Creating an Expression Transformation



Chapter 5: Expression Transformation

Sign up to vote on this title
UsefulNot useful