<block>

Blocks of Macro Language code defined with <block> allow for parameterized variables, block-control forms, and code reusability.

Description

The contents of a <block> are executed (after any parameter substitutions), unless the block appears within a <library> tag (in which case you must use <import> to make that library available in your current query). Within a block (and only within a block), special forms such as <if> and <foreach> may be used.

Blocks can be called using <call> or <insert> and specifying the name of the block as well as any user-defined variables.

Syntax

<block name="[NAME_OF_BLOCK]" 
       [USER_DEFINED_VAR_1]="[VALUE_1]" ...
          [USER_DEFINED_VAR_N]="[VALUE_N]">
    <note>Macro Language code with parameterized variables goes here</note>
</block>

Attributes

name
The name of the block. 

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. To parameterize the value of our selection for the store column, we declare the variable storechoice as an attribute in the <block> named storeselection.

<base table="pub.demo.retail.item"/>
<block name="storeselection" storechoice="2">
    <sel value="store={@storechoice}"/>
</block>

We can then insert this block (using the <insert> operation) and effectively pass in a value for storechoice.