MACRO_FUNCTION Block

Purpose

Defines a subroutine that can be invoked from the Net.Data macro. The executable statements in a MACRO_FUNCTION block must be Net.Data macro language source statements.

Syntax

>>-%MACRO_FUNCTION--function_name--| parm passing spec |-------->
 
>-----| returns spec |--{--| function body |----%}-------------->
 
      .---------------------.
      V                     |
>--------+---------------+--+--%}------------------------------><
         '-report block--'
 
parm passing spec
 
|---(--+-----------------------------+---)----------------------|
       |  .-,---------------------.  |
       |  |      (1)              |  |
       |  V .-IN-------.          |  |
       '----+----------+---name---+--'
            +-OUT------+
            '-INOUT----'
 
returns spec
 
|---+----------------------+------------------------------------|
    '-RETURNS--(--name--)--'
 
function body
 
    .--------------------------.
    V                          |
|------+--------------------+--+--------------------------------|
       +-variable reference-+
       +-if block-----------+
       +-function call------+
       +-HTML statement-----+
       +-include statement--+
       '-while block--------'
 

Notes:

  1. The default parameter type of IN applies when no parameter type is specified at the beginning of the parameter list. A parameter without a parameter type uses the type most recently specified in the parameter list, or type IN if no type has been specified. For example, in the parameter list (parm1, INOUT parm2, parm3, OUT parm4, parm5), parameters parm1, parm3, and parm5 do not have parameter types. The parameter parm1 has a type of IN because no initial parameter type has been specified. The parameter parm3 has a type of INOUT because it is the most recently specified parameter type. Similarly, the parameter parm5 has a type of OUT because it is the most recently specified type in the parameter list.

Values

%MACRO_FUNCTION
The keyword that specifies a subroutine that can be invoked from the Net.Data macro. The executable statements in a MACRO_FUNCTION block must contain language statements that Net.Data directly interprets.

function_name
The name of the function being defined. An alphabetic or numeric string that begins with an alphabetic character or underscore and contains any combination of alphabetic, numeric, or underscore characters.

parm passing spec:

IN
Specifies that Net.Data passes input data to the language environment. IN is the default.

OUT
Specifies that the language environment returns output data to Net.Data.

INOUT
Specifies that Net.Data passes input data to the language environment and the language environment returns output data to Net.Data.

name
An alphabetic or numeric string beginning with an alphabetic character or underscore and containing any combination of alphabetic, numeric, or underscore characters. name can represent a Net.Data table or a result set.

returns spec:

RETURNS
Declares the variable that contains the function value after the function completes.

function body:

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.

if block
The IF block. Performs conditional string processing. String values in the condition list are treated as numeric for comparisons if they represent integers and have no leading or trailing white space. They might have one leading plus (+) or minus (-) sign.

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.

HTML statement
Includes any alphabetic or numeric characters, as well as HTML tags to be formatted for the client's browser.

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

while block
The WHILE block. Performs looping with conditional string processing. See WHILE Block for syntax and examples.

report block
The REPORT block. Formatting instructions for the output of a function call. You can use header and footer information for the report. See REPORT Block for syntax and examples.

Context

The MACRO_FUNCTION block can be found in these contexts:

Restrictions

The MACRO_FUNCTION block can contain these elements:

Examples

Example 1: A macro function that specifies message handling

%MACRO_FUNCTION setMessage(IN rc, OUT message) {
%IF (rc == "0")
  @dtw_assign(message, "Function call was successful.")
%ELIF (rc == "-1")
  @dtw_assign(message, "Function failed, out of memory.")
%ELIF (rc == "-2")
  @dtw_assign(message, "Function failed, invalid parameter.")
%ENDIF
%}

Example 2: A macro function that specifies header information

%MACRO_FUNCTION setup(IN browserType) {
%{ call this function at the top of each HTML block in the macro %}
%INCLUDE "header_info.html"
@dtw_rdate()
%IF (browserType == "IBM")
  @setupIBM()
%ELIF (browserType == "MS")
  @setupMS()
%ELIF (browserType == "NS")
  @setupNS()
%ELSE
  @setupDefault()
%ENDIF
%}
 

Example 3: A macro function that contains a REPORT block

%MACRO_FUNCTION myfunc (INOUT table) {
   %REPORT {
      <table>
      %ROW {
         <tr><td>$(V1)</td><td>$(V2)</td></tr>
      %}
      </table>
   %}
%}

Example 4: A macro function that uses the RETURNS keyword

%MACRO_FUNCTION myfunc () RETURNS(VALUE)  {
   @DTW_ASSIGN(VALUE, "Success...")
%}


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