Variable Reference

Purpose:

Returns the value of a variable and is specified with $ and (). For example: if VAR = 'front', $(VAR) returns the value 'front'. Variable references are evaluated during run time. When a variable is defined for an EXEC statement or block, Net.Data runs the specified action when it reads the variable reference.

You can dynamically generate a variable reference by including variable references, strings, and function calls within a variable reference. For example: if frontside = 'blue', $($(VAR)side) returns the value 'blue'. If you reference a dynamcially-generated variable that does not follow the variable name rules, Net.Data resolves the reference to an empty string.

Restrictions:

Syntax:

>>---$--(--+-function_call------+---)--------------------------><
           |        (1)         |
           +-string-------------+
           '-variable_reference-'
 

Notes:

  1. String can contain only the characters that are allowed in variable names: alphanumeric characters, underscores (_), hash marks (#), or periods (.).

Example 1: Variable reference

If you have defined a variable homeURL:

%DEFINE homeURL="http://www.ibm.com/"

You can refer to the homepage as $(homeURL) and create a link:

<a href="$(homeURL)">Home page</a>

Example 2: Dynamically-generated variable reference

You can dynamically generate variable references that in turn dynamically reference a field value in a row:

%define{
var1="value1"
var2="value2"
var3="value3"
@DTW_ASSIGN (INDEX, "1")
%}
%WHILE (INDEX < 3) {
 $(var$(INDEX))
 @DTW_ADD(INDEX, "1", INDEX)
 %}

Returns:

value1
value2
value3

Example 3: A dynamic variable reference with nested variable references and a function call

%define my = "my"
%define u = "lower"
%define myLOWERvar = "hey"
 
 
$($(my)@dtw_ruppercase(u)var)   

The variable reference returns the value of hey.


[ Top of Page | Previous Page | Next Page | Index ]