<defblock>
A <defblock> is very similar to <block> code,
except the Macro Language code associated with a <defblock> will not execute
in the macro until it is referenced with an <insert> call.
Description
The contents of a <defblock> are not executed until the
<defblock> is called by an <insert> tag within the
macro. If <defblock> appears within a <library> tag
(in which case you must use <import> to make that library available in
your current query), it can be called exactly like a <block> and will be
executed at the time it is called.
Syntax
<defblock name="[NAME_OF_DEFBLOCK]"
[USER_DEFINED_VAR_1]="[VALUE_1]" ...
[USER_DEFINED_VAR_N]="[VALUE_N]">
<note>Macro Language code with parameterized variables goes here</note>
</defblock>
Attributes
name- The name of the
<defblock>.The name must begin with an alphabetic character and consist only of alphanumeric characters, digits, and/or underscores. In addition, the name must be unique; that is, no other block in the macro may have the same name.
[USER_DEFINED_VAR_x]- Accepts a string that will act as a user-defined variable. The variable name must
begin with a lowercase alphabetic character and consist only of lowercase alphanumeric
characters, digits, and/or underscores.
The block element may include any number of additional attributes, which may be used as parameters in the Macro Language code contained within the element. The value of a user-defined variable (e.g.,
my_var) is substituted wherever a scalar expression containing a reference to it (e.g.,{@my_var}) appears within the block element.
Example
In this example, the base table is pub.demo.retail.item. The goal is to
force the selection of three separate values for three columns in the table. If any one
value is not specified, the <defblock> will return a message asking for
the value to be selected.
<base table="pub.demo.retail.item"/> <defblock name="defblockexample" store_select="" sku_select="" account_select=""> <switch> <case when="{@store_select=''}"> <signal msg="You must select a store value"/> </case> <case when="{@sku_select=''}"> <signal msg="You must select a product"/> </case> <case when="{@account_select=''}"> <signal msg="You must select an account"/> </case> <else> <sel value="store={@store_select} & sku={@sku_select} & account={@account_select}"/> </else> </switch> </defblock> <insert block="defblockexample" store_select="3" sku_select="'A96'" account_select="523"/>
In the example above, the <defblock> may appear anywhere within a
macro. However, it will not be executed until it is called by an
<insert> tag after the <defblock> is
defined.
