Developer Transformation Guide > Expression Transformation > Dynamic Expressions
  

Dynamic Expressions

When you configure an expression in a dynamic output port, the expression becomes a dynamic expression. A dynamic expression can generate multiple output ports.
You can reference a port selector or a dynamic port in a dynamic expression. When the port selector or dynamic port contains multiple ports, the dynamic expression runs against each port.
When you configure a dynamic expression, the Developer tool does not validate if the generated ports are valid types for the expression. For example, if you reference a port selector that contains decimal type ports in an expression that requires string types, the expression appears as valid at design time.

Example

An Expression transformation has the following generated input ports:
EMPNO Decimal
NAME String
SALARY Decimal
DEPTNO Decimal
The transformation contains a dynamic output port called MyDynamicPort. The output port returns the results of a dynamic expression. The dynamic expression multiplies the value of each port in a port selector by 100. The expression runs one time for each port in the port selector. Each instance can return a different result. The Expression transformation generates a separate output port for each result.
The Decimal_Selector port selector has a selection rule that includes the ports that are of decimal data type:
EMPNO Decimal
SALARY Decimal
DEPTNO Decimal
The following image shows a dynamic expression that references the Decimal_Selector port selector:
The Dynamic Expression dialog box has a tab for Functions, Ports, Parameters, Port Selectors. An expression is in the editor. The expression says Decimal_Selector *100.
Edit the output port settings to change output port names and output port properties. You can also choose the base port.

Output Port Settings

You can indicate which ports you want to use as input to a dynamic expression. Select the ports in the Base Port area.
If you select the Decimal_Selector port selector as the base port, the dynamic expression returns decimal type ports. The dynamic expression does not generate a port for the NAME port because it is a string.
The following image shows the generated ports in the transformation:
The ports tab shows generated ports beneath the From_Read_Emp dynamic port. Beneath the dynamic output port are the 3 decimal type output ports.
Although the From_Read_Emp dynamic port is an input-output port, the transformation returns just the ports in the MyDynamicPort dynamic output port.
You can configure how you want to name the output ports. The default output port name is the input port name and the suffix _OUT.
You can change the base port to a port selector.
The following image shows the output port settings in the Expression Editor:
Output port settings are: Base Port: From_Read_Emp. Output Port Name: Primary input port name + Suffix. Type, Precision, Scale: Inherit from primary input
If you configure the base port as From_Read_EMP, you select the dynamic port that contains all the generated input ports. The Data Integration Service runs the dynamic expression against all the ports in From_Read_EMP.
The following image shows the generated output ports based on the From_Read_Emp input:
The ports tab shows generated ports beneath the From_Read_Emp dynamic port. Beneath the dynamic output port are the 3 decimal type output ports and a string port too.
The generated output ports include an output port called NAME_OUT, which is a string type.
The Data Integration Service generates output ports for each dynamic expression. If you create a dynamic expression that generates 15 ports and you define another dynamic expression that generates 5 ports, the Data Integration Service generates 20 output ports. Each dynamic output port generates a different group of ports.

Creating a Dynamic Expression

Create a dynamic expression in an Expression transformation to run the expression one time for each port in a dynamic port or a port selector. The dynamic expression returns the results to a separate generated port for each instance.
    1. In the Expression transformation, go to the Properties view and click the Ports tab.
    2. Click New Dynamic Port.
    The Developer tool creates a dynamic port with default properties.
    3. Rename the dynamic port and disable the input option.
    The dynamic port must be an output port.
    4. In the Expression column for the dynamic output port, click the Open button ("").
    The Dynamic Expression dialog box appears:
    5. In the Expression editor, enter an expression. The expression can include a port selector or a dynamic port.
    For example, LTRIM(RTRIM(Dynamic_Customer)), where Dynamic_Customer is a dynamic port.
    6. Click Validate to validate the expression.
    7. Click OK to exit the Validate Expression dialog box.
    8. In the Output Port Settings area, select the dynamic output port from the Base Port list or choose a port selector that you referenced in the expression.
    The Developer tool generates output ports based on what you select.
    9. Use the following steps to rename the output ports:
    1. a. Click Edit Output Port Settings.
    2. The Output Port Settings dialog box appears.
    3. b. In the Name list, select one of the options and enter a value for the prefix or suffix. If you selected Fixed string + Auto-number, enter the text for output port name. For example, if you enter TRIM for the output port name, the output port names appear as TRIM1, TRIM2, TRIM3.
    4. c. Optionally, choose Specify settings in the Other Settings area to change the type, precision, and scale for the output ports. By default, the output ports use the settings of the base ports.
    5. d. Click OK.
    10. Click OK to exit the Dynamic Expression editor.