Variable TypesThere are four kinds of variables in
Command line arguments can be used anywhere. Variables can be used after declaration. Column values must be contained within an area associated with the corresponding datastream. They must be elements of the targetlist for that datastream. The containment area need not be the immediate enclosing area but may be in a parent area. Built-in arguments are documented in the Built-in Arguments and in Using CSV files.
Column valuesColumn variables are defined to be the target list of each datastream. The value of the variable is the value of the column of the current row. Column values are usually used in repeated areas, for example:
<table> <TR><TH>Team</TH><TH>Region</TH></TR> <area name=detail datastream=teams break=teamname> <TR><TD>_teamname_</TH><TH>_region_</TH></TR> </area>
Column variables must be used in areas defining the datastream from which they originate.
Command Line Arguments and VariablesCommand line arguments are simply name=value pairs passed on the command line invoking
% ere tablelist tablename=users
Command line arguments and declared variables are embedded by name. The name is enclosed in colons. They can be used anywhere in the report, including the SQL.
... AND datefield = :datearg:
Using Declared variablesSimple declared variables are usually declared in the report header section like this:
<var name=title value="Hattie's Kitchen" /var>These are usually constants, useful when you are using a single report template as the basis of a variety of reports.
Declared variables are much more useful when the value is based on a command line variable. Declared variables have an extra twist in that they can be set or unset based on the values of command line arguments. If the value of any command line argument used in a declared variable evaluates to an empty string, then the declared variable value will also be set to an empty string. This is used to create optional clauses in the SQL statement based on command line arguments.
For example, report myreport.xml declares two variables that are used as additional qualifiers in the SQL statement. When the report is run, only one of the command line variables, lastname, is passed in.
% cat myreport.xml ... <Var name=quallname value="AND lastname = ':lastname:' " /Var> <Var name=qualfname value="AND firstname = ':firstname:' " /Var> ... <SQL> select .... where .... :quallname: :qualfname: order by .... </SQL> ... % ere myreport lastname=HowardWhen the variable quallname is evaluated, it will have the value "AND lastname = 'Howard'". When the variable qualfname is evaluated it will be an empty string. The variables can be used in the SQL statement so that it can qualify on "lastname" and not "firstname" based on the arguments passed in at runtime.