The #IF compiler command causes the compiler to evaluate the condition that follows the statement. This command is used in conjunction with the #ELSE and #ENDIF commands.
If the condition is true, the statements following the #IF command (prior to an #ELSE command) are executed. If the condition is false, the statements following the #ELSE command and prior to the #ENDIF command are executed.
Use #IF and #ELSE commands to wrap code sections that are based on static institutional parameters. The most effective way to eliminate database IO is to eliminate code that contains database IO. In the following example, the ResultSet in the #IF block is eliminated from the generated code if the #IF condition is false:
#IF CUVAR.%MCP
type ResultSet rs = Db.select("CRCD","UTBLCRCD")
while rs.next() set crcd(rs.getRow()) = ""
#END
PSL supports multiple, nested #IF/#ELSE code blocks.
|
If the #IF condition is not met, the compiler does not evaluate or validate the code between the #IF and #ENDIF statements. For example, the following code will not compile because the DEP table does not contain a column named ABCDEFG. However, if the #IF condition is not evaluated, the compilation error is not identified. #IF $$YEAR^SCADAT(CUVAR.TJD)=2000 Type RecordDEP dep=Db.getRecord("DEP,":CID") Set x=dep.ABCDEFG #ENDIF
To ensure that the compiler evaluates and validates conditional code, write the code without the conditional #IF (or comment it out) to test compile. After all code compiles cleanly, include the #IF and #ENDIF statements. |
Syntax
#IF condition
Parameters
condition |
PSL code that is evaluated to determine if true or false. The condition can evaluate a table.column value, expression, etc. |
When Became Available
Profile v6.3
Example #1
#IF CUVAR.%mcp
set X = 5
#ELSE
set X = 6
#ENDIF
Example #2 – Nested #IF/#ELSE blocks
#IF CUVAR.%MCP
set crcd = dep.crcd
#IF CUVAR.SPLTDAY
set bal = dep.balavl
#ELSE
set bal = dep.bal
#END //End 2nd #IF/#ELSE
#END //End 1st #IF