Use the IF block for conditional processing in a Net.Data macro. The IF block is similar to IF statements in most high-level languages because it 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 specify IF blocks almost anywhere in a macro and can nest them. The syntax of an IF block is shown in the language constructs chapter in Net.Data Reference.
IF Block Rules: The rules for IF block syntax are determined by the block's position in the macro. The elements allowed in the executable block of statements of an IF block depend on the location of the IF block itself.
%HTML block ... %IF block ... %INCLUDE ... %WHILE ... %ENDIF %}
%IF ... %DEFINE ... %FUNCTION ... %ENDIF
For example, a nested IF block must follow the rules used when it is inside an HTML block.
%IF ... %HTML { ... %IF ... %ENDIF %} ... %ENDIF
Exception: Do not specify a ROW block in an IF block.
IF Block String Comparison
Net.Data processes the IF block condition list in one of two ways based on the contents of the terms making up the conditions. The default action is to treat all terms as strings, and to perform string comparisons as specified in the conditions. However, if the comparison is between two strings representing integers, then the comparison is numeric. Net.Data assumes a string is numeric if it contains only digits, optionally preceded by a '+' or '-' character. The string cannot contain any non-digit characters other than the '+' or '-'. Net.Data does not support numerical comparison of non-integer numbers.
+1234567890 -47 000812 92000
- 20 (contains blank characters) 234,000 (contains a comma) 57.987 (contains a decimal point)
Net.Data evaluates the IF condition at the time it executes the block, which can be different than the time it is originally read by Net.Data. For example, if you specify an IF block in a REPORT block, Net.Data does not evaluate the condition list associated with the IF block when it reads the FUNCTION block definition containing the REPORT block, but rather when it calls the function and executes it. This is true for both the condition list part of the IF block and the block of statements to be executed.
IF Block Example: A macro containing IF blocks inside other blocks
%{ This macro is called from another macro, passing the operating system and version variables in the form data. %} %IF (platform == "AS400") %IF (version == "V3R2") %INCLUDE "as400v3r2_def.hti" %ELIF (version == "V3R7") %INCLUDE "as400v3r7_def.hti" %ELIF (version == "V4R1") %INCLUDE "as400v4r1_def.hti" %ENDIF %ELSE %INCLUDE "default_def.hti" %ENDIF %MACRO_FUNCTION numericCompare(IN term1, term2, OUT result) { %IF (term1 < term2) @dtw_assign(result, "-1") %ELIF (term1 > term2) @dtw_assign(result, "1") %ELSE @dtw_assign(result, "0") %ENDIF %} %HTML(report){ %WHILE (a < "10") { outer while loop #$(a)<BR> %IF (@dtw_rdivrem(a,"2") == "0") this is an even number loop<BR> %ENDIF @DTW_ADD(a, "1", a) %} %}