Foreach
The foreach task (foreach
) executes template based tasks for each element of the provided collection. For each row of the collection, the provided task templates get interpolated with the collection columns to be then added to the Ianus execution queue.
The collections can be loaded from:
- SQL Queries
- CSV data (with column headers)
- Directory content
- Repository content
- Excel sheets
- Resources
Column values are expressed as ${column_name}
and loaded from:
- Query column names as returned by the database
- CSV column header, that must be embedded in the CSV text
- Excel sheet column header specified on the first row of the sheet
- Directory and Repository listing (files only). The following variables are defined:
FULLNAME
full file name, including directory and extensionFILENAME
file name, including extensionNAME
file name, without extensionEXT
file extensionPATH
directory name
- Resources. The following variable are defined:
VALUE
value of the resouerce itemKEY
key of the item, for dictionary type resource only
Column names are alwyas case sensitive.
The foreach tasks runs always in single thread mode.
The following attributes configure the foreach element:
Attribute | Type | Purpose | Default |
---|---|---|---|
verbose | bool | If set to true , extra diagnostic is produced in the log file |
false |
stoponloaderror | bool | If set to true , load errors of refenced XML do not cause a fatal error |
false |
suffixindex | bool | If set to true , the name of the generated task is suffixed by the occurrence number |
false |
The following elements configure the foreach task:
Element | Purpose |
---|---|
collection | Defines the source of the collection being processed. Refer to Collection for detailed description. |
execute | Contains the tasks templates to be executed |
Collection
The collection
element defines the collection to be processed.
The following attributes configure the collection element:
Attribute | Type | Purpose | Default |
---|---|---|---|
type | string | Defines the source type. Refer to Collection Types for detailed description. | query |
source | string | (query only) Defines the datasource name for query type collections | |
delimiter | string | (csv only) Defines the CSV delimiter. | , (comma) |
qualifier | string | (csv only) Defines the CSV string qualifier. | " (double quote) |
path | string | (directory only) Defines the path of the directory to be listed | |
pattern | string | (directory only) Defines the file search pattern | |
exactmatch | bool | (directory only) When false , "?" char is interpreted as "zero or one character", otherwise as "one character" |
true |
file | string | (excel only) Path to the excel file | |
sheet | string | (excel only) Name of the excel sheet to use | First sheet in the file |
name | string | (resource only) Name of the resource to use |
Collection Types
Value | Description |
---|---|
query | SQL query result |
csv | CSV file |
directory | Directory listing |
repository | Repository listing |
excel | Excel sheet |
resource | Resource |
Execute Element
The execute
element contains the template task(s) to be execute.
The following attributes configure the execute element:
Attribute | Type | Purpose | Default |
---|---|---|---|
file | string | Executes the template task(s) stored at specified location | |
source | bool | If true , Ianus interpolates the collection variables in the template task(s) |
true |
Example
<job>
<foreach name="FOREACH_QUERY">
<collection type="query" source="QS">
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA='DBO'
AND TABLE_NAME IN ('TEST01', 'TEST02')
</collection>
<execute>
<log>COMPARING ${TABLE_NAME} vs ${TABLE_NAME}</log>
<tablecompare name="CMPQ_" left="SRC" right="QS">
<left>${TABLE_SCHEMA}.${TABLE_NAME}</left>
<right>${TABLE_SCHEMA}.${TABLE_NAME}</right>
</tablecompare>
</execute>
</foreach>
<foreach name="FOREACH_CSV">
<collection type="csv" delimiter=";">
LEFT_TABLE;RIGHT_TABLE
dbo.TEST01;dbo.TEST01
dbo.TEST02;dbo.TEST02
</collection>
<execute>
<log name="CSVLOG">PRINTING [${LEFT_TABLE}], ${RIGHT_TABLE}</log>
<tablecompare name="CMPC_" left="SRC" right="QS">
<left>${LEFT_TABLE}</left>
<right>${RIGHT_TABLE}</right>
</tablecompare>
</execute>
</foreach>
<foreach name="FOREACH_DIR">
<collection type="directory" path="C:\tmp" pattern="*.xlsx"/>
<execute>
<log name="DIRLOG">Listing [${FULLNAME}], ${NAME} ${EXT} ${PATH}</log>
</execute>
</foreach>
<foreach>
<collection type="repository" name="REPOEBCDIC"
pattern="IANUS.TEST.SEQ??.EBCDIC.DAT"/>
<execute>
<filecopy name="CONV" source="REPOEBCDIC" target="TMPE" mode="binary">
<source recfmt="fixed" reclen="80">${FILENAME}</source>
<target recfmt="fixed" reclen="80">${FILENAME}</target>
</filecopy>
</execute>
</foreach>
<foreach name="LINUX" enabled="true">
<collection type="repository" name="REMOTE_EBCDIC"
pattern="IANUS.TEST.SEQ??.EBCDIC.DAT"/>
<execute>
<filecopy name="CONV" source="REMOTE_EBCDIC" target="TMPE" mode="binary">
<source recfmt="fixed" reclen="80">${FILENAME}</source>
<target recfmt="fixed" reclen="80">${FILENAME}</target>
</filecopy>
</execute>
</foreach>
<foreach name="ZOS">
<collection type="repository" name="REPO_HERCULES"
pattern="IANUS.TEST.?B??"/>
<execute>
<filecopy name="CONV" source="REPO_HERCULES" target="TMPE" mode="binary">
<source recfmt="fixed" reclen="80">${FILENAME}</source>
<target recfmt="fixed" reclen="80">${FILENAME}</target>
</filecopy>
</execute>
</foreach>
</job>
Status codes
Status | Status code | Description |
---|---|---|
Ready | -1 | Task is initialized, but not yet started |
Running | -2 | Task is running |
Success | 0 | Task completed successfully |
Warnings | 1 | Task completed with warnings |
Errors | 2 | Task completed with errors |
Aborted | 9 | Task cannot be executed |