DEFINE Block or Statement

Purpose

The DEFINE section defines variables names in the declaration part of the macro and can be either a statement or a block.

The variable definition can be on a single line, using double quotes (""), or can span multiple lines, using brackets and a percent sign ({ %}). After the variable is defined, you can reference it anywhere in the macro.

Syntax

>>-%DEFINE----+----------------------------+-------------------->
              |             (1)            |
              '-(--+-STATIC---------+---)--'
                   |           (1)  |
                   '-TRANSIENT------'
 
>-----+-| define entry |--------------------------+------------><
      '-{--+------------------------------+---%}--'
           |  .------------------------.  |
           |  V                        |  |
           '----+-define entry------+--+--'
                '-include statement-'
 
define entry
 
                             .--------------------------.
                             V                          |
|---+-variable name--=--+-"-----+--------------------+--+---"---+-+->
    |                   |       +-string-------------+          | |
    |                   |       +-variable reference-+          | |
    |                   |       '-function call------'          | |
    |                   |    .--------------------------.       | |
    |                   |    V                          |       | |
    |                   +-{-----+--------------------+--+---%}--+ |
    |                   |       +-string-------------+          | |
    |                   |       +-variable reference-+          | |
    |                   |       +-function call------+          | |
    |                   |       '-new_line-----------'          | |
    |                   +-exec statement------------------------+ |
    |                   +-table statement-----------------------+ |
    |                   +-envvar statement----------------------+ |
    |                   +-| conditional variable |--------------+ |
    |                   '-| abbreviated conditional variable |--' |
    '-list statement----------------------------------------------'
 
>---------------------------------------------------------------|
 
conditional variable
 
|---variable name---?------------------------------------------->
 
           .--------------------------.
           V                          |
>-----+-"-----+--------------------+--+---"---+----------------->
      |       +-string-------------+          |
      |       +-variable reference-+          |
      |       '-function call------'          |
      |    .--------------------------.       |
      |    V                          |       |
      '-{-----+--------------------+--+---%}--'
              +-string-------------+
              +-variable reference-+
              '-function call------'
 
                .--------------------------.
                V                          |
>-------:--+-"-----+--------------------+--+---"---+------------|
           |       +-string-------------+          |
           |       +-variable reference-+          |
           |       '-function call------'          |
           |    .--------------------------.       |
           |    V                          |       |
           '-{-----+--------------------+--+---%}--'
                   +-string-------------+
                   +-variable reference-+
                   '-function call------'
 
abbreviated conditional variable
 
              .--------------------------.
              V                          |
|---?----+-"-----+--------------------+--+---"---+--------------|
         |       +-string-------------+          |
         |       +-variable reference-+          |
         |       '-function call------'          |
         |    .--------------------------.       |
         |    V                          |       |
         '-{-----+--------------------+--+---%}--'
                 +-string-------------+
                 +-variable reference-+
                 '-function call------'
 

Notes:

  1. STATIC and TRANSIENT are keywords for persistent macros, which are currently available on the OS/400 operating system, only.

Values

%DEFINE
A keyword that defines variables.

STATIC
A keyword that specifies that the variable retains its value across macro invocations within a persistent transaction. This is the default for persistent macros.

TRANSIENT
A keyword that specifies that this variable does not retain its value across macro invocations. This is the default for non-persistent macros.

define entry:

variable name
A name that identifies a variable. See Variable Name for syntax information.

string
Any sequence of alphabetic and numeric characters and punctuation. If the string appears within double quotes, the new-line character is not allowed.

variable reference
Returns the value of a variable and is specified with $ and (). For example: if VAR='abc', then $(VAR) returns the value 'abc'. See Variable Reference for syntax information.

function call
Invokes one or more FUNCTION or MACRO_FUNCTION blocks, or a Net.Data built-in function with specified arguments. See Function Call (@) for syntax and examples.

exec statement
The EXEC statement. The name of an external program that executes when a variable is referenced or a function is called. See EXEC Block or Statement for syntax and examples.

table statement
The TABLE statement. Defines a collection of related data containing an array of identical records, or rows, and an array of column names describing the fields in each row. See TABLE Statement for syntax and examples.

envvar statement
The ENVVAR statement. Refers to environment variables. See ENVVAR Statement for syntax and examples.

conditional variable
Sets the value of a variable based on whether another variable or string is empty.

abbreviated conditional variable
Sets the value of a variable based on whether another variable or string is empty. A shorter form of the conditional variable.

list statement
The LIST statement. Defines variables that are used to build a delimited list of values. See LIST Statement for syntax and examples.

include statement
The INCLUDE statement. Reads and incorporates a file into the Net.Data macro. See INCLUDE Statement for syntax and examples.

Context

The DEFINE block or statement must be in an IF block or outside all other blocks in the declaration part of the Net.Data macro.

Restrictions

Examples

Example 1: Simple variable definitions

%DEFINE var1 = "orders"
%DEFINE var2 = "$(var1).html"

During run time, the variable reference $(var2) is evaluated as orders.html.

Example 2: Quotes inside a string

%DEFINE hi = "say ""hello"""
%DEFINE empty = ""

When displayed, the variable hi has the value say "hello". The variable empty contains the empty string.

Example 3: Definition of multiple variables

%DEFINE{  DATABASE = "testdb"
          home = "http://www.ibm.com/software"
          SHOWSQL = "YES"
          PI = "3.14150"
%}

Example 4: Multiple-line definition of a variable

%DEFINE text = {This variable definition
            spans two lines
%}

Example 5: This example of a conditional variable demonstrates how the variable var takes the resulting value inside the quotations marks ("") if the resulting value does not contain any NULL values.

%DEFINE var = ? "Hello! $(V)@MyFunc()"
%}


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