Generate
The generate task (generate
) generates text files merging a template with data of the provided collection.
For each row of the collection, the text templates get interpolated with the collection columns and written to the output file(s).
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 output can be generated on a single or multiple files. In the latter case, a file each row of collection is generate. The output file name is assigned interpolating values on the filename.
The following elements configure the generate task:
Element | Purpose |
---|---|
collection | Defines the source of the collection being processed. Refer to Collection for detailed description. |
template | Contains the file templates to be used |
output | Defines the output file(s) |
head | Defines an optional header text (applies only to single output) |
tail | Defines an optional trailer text (applies only to single output) |
The following attributes configure the task:
Attribute | Type | Purpose | Default |
---|---|---|---|
removeemptylines | bool | When true , empty lines are removed from output |
false |
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 |
Template Element
The template
element contains the template to be used.
Output Element
The output
element contains the template to be used.
The following attributes configure the output element:
Attribute | Type | Purpose | Default |
---|---|---|---|
multi | bool | If true the ouput is generated on multiple files |
false |
repository | string | If specified, the output file is created in the specified file repository |
Example
<?xml version="1.0" encoding="utf-8"?>
<job multithread="false">
<generate name="INSTREAM.SQL.SINGLE">
<collection type="query" source="QS">
SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='DBO'
AND TABLE_NAME IN ('TEST01', 'TEST02')
</collection>
<output>C:\TMP\TMPA\INSTREAM.SQL.SINGLE.txt</output>
<template><![CDATA[
//TESTASM1 JOB 'TESTUL',CLASS=A
//TEST01 EXEC PGM=TESTUL
//SYSOUT DD SYSOUT=*
//FILEOUT DD DSN=UNLOAD.${TABLE_SCHEMA}.${TABLE_NAME}.DAT,
// DISP=(NEW,KEEP,DEL)
//SYSIN DD *
UNLOAD ${TABLE_SCHEMA}.${TABLE_NAME} FROM DB2
//*
]]>
</template>
</generate>
<generate name="EXTERN.SQL.SINGLE">
<collection type="query" source="QS">
SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA='DBO'
AND TABLE_NAME IN ('TEST01', 'TEST02')
</collection>
<output>C:\TMP\TMPA\EXTERN.SQL.SINGLE.txt</output>
<template>
<include type="text">TEMPLATE.jcl</include>
</template>
</generate>
<generate name="INSTREAM.CSV.SINGLE">
<collection type="csv" delimiter=";">
FILE_NAME;TABLE_NAME
FILE.UNLOAD.TEST01;TEST01
FILE.UNLOAD.TEST02;TEST02
FILE.UNLOAD.TABELLA03;TABELLA03
</collection>
<output>C:\TMP\TMPA\INSTREAM.CSV.SINGLE.txt</output>
<template><![CDATA[
//TESTASM1 JOB 'TESTUL',CLASS=A
//TEST01 EXEC PGM=TESTUL
//SYSOUT DD SYSOUT=*
//FILEOUT DD DSN=${FILE_NAME},
// DISP=(NEW,KEEP,DEL)
//SYSIN DD *
UNLOAD ${TABLE_NAME} FROM DB2
//*
]]>
</template>
</generate>
<generate name="INSTREAM.DIR.SINGLE">
<collection type="directory" pattern="*.xml" path="%IANUS_HOME%\Test\Config"/>
<output>C:\TMP\TMPA\INSTREAM.DIR.SINGLE.txt</output>
<template><![CDATA[
copy ${FULLNAME} ${NAME}.bak
]]>
</template>
</generate>
<generate name="INSTREAM.XLS.SINGLE.2">
<collection type="excel" file="%IANUS_HOME%\Test\Config\Generate.xlsx"/>
<output>C:\TMP\TMPA\INSTREAM.XLS.SINGLE.txt</output>
<template><![CDATA[
convert.sh --format ${Recfmt} --length ${Reclen} ${File}
]]>
</template>
</generate>
<generate name="INSTREAM.XLS.SINGLE.2">
<collection type="excel" sheet="Lista" file="%IANUS_HOME%\Test\Config\Generate.xlsx"/>
<output>C:\TMP\TMPA\INSTREAM.XLS.SINGLE.SHEET.txt</output>
<template><![CDATA[
convert.sh --format ${Recfmt} --length ${Reclen} ${File}
]]>
</template>
</generate>
<generate name="INSTREAM.XLS.MULTI">
<collection type="excel" file="%IANUS_HOME%\Test\Config\Generate.xlsx" sheet="tables"/>
<output multi="true">C:\TMP\TMPA\INSTREAM.CSV.MULTI.${TABLE_NAME}.txt</output>
<template><![CDATA[
//TESTASM1 JOB 'TESTUL',CLASS=A
//TEST01 EXEC PGM=TESTUL
//SYSOUT DD SYSOUT=*
//FILEOUT DD DSN=${FILE_NAME},
// DISP=(NEW,KEEP,DEL)
//SYSIN DD *
UNLOAD ${TABLE_NAME} FROM DB2
//*
]]>
</template>
</generate>
<generate name="INSTREAM.DIR.SINGLE">
<collection type="directory" pattern="*.xml" path="%IANUS_HOME%\Test\Config"/>
<output multi="true" repository="TMPA">_00_${FILENAME}.txt</output>
<template>${FULLNAME}</template>
</generate>
<generate name="copycheck.single" enabled="true">
<collection type="query" source="GENERATE_DB">
select data_file,
copybook
from FLR
where conv_mode like 'COPY%' and multi_layout='No'
</collection>
<output multi="false">copycheck.xml</output>
<template>
<include type="text">templates/copycheck.single.xml</include>
</template>
<head><![CDATA[<job>]]></head>
<tail><![CDATA[</job>]]></tail>
</generate>
</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 |