IBM Books

Net.Data Reference Guide

HTML IF Statement

Purpose

The HTML IF statement performs conditional string processing and is used in the HTML part of the Net.Data macro. You can use the HTML IF statement in the HTML block, the REPORT block, and the ROW block. Numeric values are treated as strings for comparisons.

Syntax

                             +-----------------------+
                             V                       |
>>-%if--| condition list |-----+--------------------++---------->
                               +-exec_sql statement-+
                               +-variable reference-+
                               +-function call------+
                               +-string-------------+
                               +-HTML statement-----+
 
>--| else_if spec |--%endif------------------------------------><
 
condition list
 
|--(--+-(--condition list--)----------------+-)----------------|
      +-condition list--&&--condition list--+
      +-condition list--||--condition list--+
      +-!--condition list-------------------+
      +-| condition |-----------------------+
      +-| term |----------------------------+
 
condition
 
|--term--+-<--+-term-------------------------------------------|
         +->--+
         +-<=-+
         +->=-+
         +-!=-+
         +-==-+
 
term
 
|--+-variable reference-+--------------------------------------|
   +-"--string--"-------+
   +-variable name------+
 
else_if spec
 
|--+----------------------------------------------------------------+->
   |    +-------------------------------------------------------+   |
   |    |                             +-----------------------+ |   |
   |    V                             V                       | |   |
   +--+--%elif--(--condition_list--)----+--------------------++-+-+-+
      |                                 +-exec_sql statement-+    |
      |                                 +-variable reference-+    |
      |                                 +-function call------+    |
      |                                 +-string-------------+    |
      |                                 +-HTML statement-----+    |
      |        +-----------------------+                          |
      |        V                       |                          |
      +-%else----+--------------------++--------------------------+
                 +-exec_sql statement-+
                 +-variable reference-+
                 +-function call------+
                 +-string-------------+
                 +-HTML statement-----+
 
>--------------------------------------------------------------|
 

Parameters

%if

The keyword that specifies conditional string processing. Numeric values are treated as strings for comparisons.

condition list:

condition list

Compares values and variable values. The list can contain conditions and terms. Condition lists can be connected using boolean operators. A condition list can be nested inside another condition list.

condition

A comparison between two terms using comparison operators. Net.Data compares only strings; a variable or a string representing a numerical value is evaluated as a string of characters, not as a numerical value.

term

A variable name, string, or variable reference.

exec_sql statement

A DB2WWW Release 1 language element supported for compatibility. See Appendix A. "DB2 WWW Connection" or DB2 World Wide Web Release 1 documentation.

variable reference

Returns the value of a previously defined 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 previously defined %FUNCTION blocks with specified arguments. See Function call (@) for syntax and examples.

string

Any sequence of alphabetic and numberic characters and punctuation, except a tabulator, newline character, or a space.

HTML statement

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

%elif

A keyword that starts the alternative processing path, and can contain condition lists and most Net.Data macro statements.

%endif

A keyword that closes the %IF block.

%else

A keyword that executes associated statements if all other condition lists are not satisfied.

Context

Can be found in these contexts:

Restrictions

Can contain these elements:

Examples

Example 1:

%IF ($RETURN_CODE) == $(failure_rc))
   <P> The function call failed with failure code $(RETURN_CODE).
%ELIF ($(RETURN_CODE) == $(warning_rc))
   <P> The function call succeeded with warning code $(RETURN_CODE).
%ELIF ($(RETURN_CODE) == $(success_rc))
   <P>The function call was successful.   
%ELSE
   P>The function call returned with unknown return code $(RETURN_CODE).
%ENDIF

Example 2:

%IF (name == "world!")
<H2>Hello world!</H2>
%ENDIF


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