Reference
Purpose
Performs conditional string processing. The IF block provides the
ability to test one or more conditions, and then to perform a block of
statements based on the outcome of the condition test. You can use the
IF block in the declaration part of a Net.Data macro, the HTML block,
the MACRO_FUNCTION block, the REPORT block, the WHILE block, and the ROW
block, as well as nest it inside another IF block.
String values in the condition list are treated as numeric for comparisons
if they are strings that represent integers and have no leading or trailing
white space. They can have a single leading plus (+) or minus (-)
sign.
Restriction: Net.Data does not support numerical
comparison of non-integer numbers; for example, floating point
numbers.
Nested IF blocks: The rules for IF block syntax are
determined by the block's position in the macro. If an IF block is
nested within an IF block that is outside of any other block in the
declaration part, it can use any element that the outside block can
use. If an IF block is nested within another block that is in an IF
block, it takes on the syntax rules for the block it is inside.
In the following example, the nested IF block must follow the rules used
when it is inside an HTML block.
%IF block
...
%HTML block
...
%IF block
You can nest up to 1024 IF blocks.
Syntax
>>-%IF--| condition list |-------------------------------------->
>-----| statement_block |--| else_if spec |--%ENDIF------------><
condition list
|---(--+-(--condition list--)----------------+---)--------------|
+-condition list--&&--condition list--+
+-condition list--||--condition list--+
+-!--condition list-------------------+
+-| condition |-----------------------+
'-| term |----------------------------'
statement_block
.---------------------------------.
V |
|------+---------------------------+--+-------------------------|
| (1) |
+-define block--------------+
| (1) |
+-define statement----------+
| (2) |
+-exec_sql statement--------+
| (1) |
+-function block------------+
+-function call-------------+
| (1) |
+-HTML block----------------+
| (2) |
+-HTML statement------------+
+-if block------------------+
+-include statement---------+
+-include_url statement-----+
| (1) |
+-macro_function block------+
| (1) |
+-message block-------------+
| (2) |
+-string--------------------+
| (2) |
+-variable reference--------+
| (2) |
'-while block---------------'
condition
|---term--+-<--+---term-----------------------------------------|
+->--+
+-<=-+
+->=-+
+-!=-+
'-==-'
term
|---+-variable_name-----------------------+---------------------|
+-variable reference------------------+
+-function call-----------------------+
| .-------------------------. |
| V | |
'-"----+-string-------------+--+---"--'
+-variable reference-+
'-function call------'
else_if spec
|---+---------------------------------------------------------------+->
| .----------------------------------------------------. |
| V | |
'--+----%ELIF--(--condition_list--)--| statement_block |---+-+--'
'-%ELSE--| statement_block |------------------------------'
>---------------------------------------------------------------|
Notes:
- This language construct is valid when the IF block is located outside of
any other block in the declaration part of the macro.
- This language construct is valid when the IF block is located in an HTML
block, MACRO_FUNCTION block, REPORT block, ROW block, or WHILE block.
Values
- %IF
- The keyword that specifies conditional string processing.
- condition list
- Compares the values of conditions and terms. Condition lists can be
connected using Boolean operators. A condition list can be nested
inside another condition list.
- statement_block
- The following valid Net.Data macro constructs. Please see
diagram notes and restrictions to determine the context in which the macro
constructs are valid.
- define statement
- The DEFINE block or statement. Defines variables and sets
configuration variables. Variable names must begin with a letter or
underscore (_) and contain any alphanumeric characters or underscore.
See DEFINE Block or Statement for syntax and examples.
- exec_sql statement
- A DB2WWW Release 1 language element that is supported for
compatibility. See Appendix B, DB2 WWW Connection or DB2 World Wide Web Release 1
documentation.
- function block
- A keyword that specifies a subroutine that can be invoked from the
Net.Data macro. The executable statements in a FUNCTION block
can contain language statements that are directly interpreted by a language
environment, or they can indicate a call to an external program. See FUNCTION Block for syntax and examples.
- 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 block
- Includes any alphabetic or numeric characters, as well as HTML tags to be
formatted for the client's browser.
- HTML statement
- Includes any alphabetic or numeric characters, and HTML tags to be
formatted for the client's browser.
- if block
- The IF block. Performs conditional string processing. String
values in the condition list are treated as numeric for comparisons if they
are strings that represent integers and have no leading or trailing white
space. They can have a single leading plus (+) or minus (-)
sign.
- include statement
- The INCLUDE statement. Reads and incorporates a file into the
Net.Data macro. See INCLUDE Statement for syntax and examples.
- include_url statement
- The INCLUDE_URL statement. Reads and incorporates another file into
the Net.Data Web macro where the statement is specified. The
specified file can exist on a local or remote server. See INCLUDE_URL Statement for syntax and examples.
- macro_function block
- A keyword that specifies a subroutine that can be invoked from the
Net.Data macro. The executable statements in a MACRO_FUNCTION
block can contain Net.Data macro language source statements. See
MACRO_FUNCTION Block for syntax and examples.
- message block
- The MESSAGE block. A set of return codes, the associated messages,
and the actions Net.Data takes when a function call is returned.
See MESSAGE Block for syntax and examples.
- string
- Any sequence of alphabetic and numeric characters and punctuation.
If the string is in the term of the condition list, it can contain any
character except the new-line character. If the string is in the
executable block of code, it can contain any character, including the new-line
character.
- 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.
- while block
- The WHILE block. Performs looping with conditional string
processing. See WHILE Block for syntax and examples
- condition
- A comparison between two terms using comparison operators. An IF
condition is treated as a numeric comparison if both of the following
conditions are true:
- The condition operator is one of the following operators:
<,<=,>,>=,==,!=
- Both terms are strings representing valid integers, where a valid integer
is a string of digits, optionally preceded by a plus (+) or minus (-) sign,
and no other white space.
If either condition is not true, a normal string comparison is
performed.
- term
- A variable name, string, variable reference, or function call.
- %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
The IF block can be found in these contexts:
- Outside of any other block in the declaration part of a Net.Data
macro
- HTML block
- IF block
- MACRO_FUNCTION block
- REPORT block
- ROW block
- WHILE block
Restrictions
The IF block can contain these elements when located outside of any other
block in the declaration part of the Net.Data macro:
- Comment block
- DEFINE block
- DEFINE statement
- FUNCTION block
- Function call
- HTML block
- IF block
- INCLUDE statement
- INCLUDE_URL statement
- MACRO_FUNCTION block
- MESSAGE block
- Variable reference
The IF block can contain these elements when located in the HTML block,
MACRO_FUNCTION block, REPORT block, ROW block, or WHILE block of the
Net.Data macro:
- Comment block
- EXEC_SQL statement
- Function calls
- IF block
- INCLUDE statement
- INCLUDE_URL statement
- HTML statement
- String
- Variable reference
- WHILE block
You can nest up to 1024 IF blocks.
Examples
Example 1: An IF block in the declaration part of a Net.Data
macro
%DEFINE a = "1"
%DEFINE b = "2"
...
%IF ($(DTW_HTML_TABLE) == "YES")
%define OUT_FORMAT = "HTML"
%ELSE
%define OUT_FORMAT = "CHARACTER"
%ENDIF
%HTML(REPORT) {
...
%}
Example 2: An IF block inside an HTML block
%HTML(REPORT) {
@myFunctionCall()
%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 3: A numeric comparison
%IF (ROW_NUM < "100")
<p>The table is not full yet...
%ELIF (ROW_NUM == "100")
<p>The table is now full...
%ELSE
<p>The table has overflowed...
%ENDIF
A numeric comparison is done because the implicit table variable ROW_NUM
always returns an integer value, and the value that is being compared is also
an integer.
Example 4: Nested IF blocks
%IF (MONTH == "January")
%IF (DATE = "1")
HAPPY NEW YEAR!
%ELSE
Ho hum, just another day.
%ENDIF
%ENDIF
[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]