In this example, you will use the iterator operator to
run the data flow for each file in the directory. If there is no file
in the directory, the iteration ends and the control flow executes
successfully, without executing the data flow.
About this exampleThe data flow in
this example reads a source file, transforms the data, and writes
the data to a target database. You want this one data flow to run
a number of times in succession, each time with a different source
file. One way to do this is to design one data flow for each source
file that you want to read. A more efficient way to do this is to
design a control flow that uses an iterator.
If the data flow
fails, you want an e-mail sent to an operator.
ProcedureTo
define an iterator operator for the files in a directory:
- In your data flow, define File Name as a variable
for your file import.
Tip: You define this variable when
you create the data flow in the data flow editor.
- In your control flow, place an iterator operator in the canvas.
- Define the properties for the iterator.
- Select the following type of iteration: Repeat loop
for each file in a directory.
- Select the directory that contains the source files.
- Click
to select the File Name variable.
- Place a data flow operator in the canvas and define the data flow
to be the one that you created in the Design Studio.
- Connect the main processing loop to the iterator and end iterator
operators.
- Connect the loop port of the iterator operator to the input port
of the data flow operator.
Figure 1. Loop port of an iterator operator
connected to the input port of a data flow operator
- Connect the On-success port of the data flow operator to the input
port of the end iterator.
Figure 2. On-success port of a data flow
operator connected to the input port of an end iterator.
- Define the error processing loop.
- Place the e-mail operator in the canvas and define its properties.
- Connect the on-failure port of the data flow operator to the input
port for the e-mail operator.
Figure 3. On-failure port of a data
flow operator connected to the input port for an e-mail operator
When the control flow is run, the data flow is run one time
for each source file.