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) (2) | +-define statement-----------+ | (1) | +-function block-------------+ +-function call--------------+ | (1) | +-HTML block-----------------+ | (2) | +-HTML statement-------------+ +-if block-------------------+ +-include 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:
Values
If either condition is not true, a normal string comparison is performed.
Context
The IF block can be found in these contexts:
Restrictions
The IF block can contain these elements when located outside of any other block in the declaration part of the Net.Data macro:
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:
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