#IF
Syntax
#IF {txt_lit|num_lit}comparison_operator {txt_lit|num_lit}
Description
Indicates that the commands following #IF are to be compiled when the expression is TRUE. (#IF is a compiler directive.)
SQR has five compiler directives that enable different pieces of SQR code to be compiled, depending on the existence or value of substitution variables (not program variables, such as string, numeric, or date).
Substitution variables defined automatically for each -DEBUGxxx letter can also be used with the #IF, #IFDEF, and #IFNDEF directives. They can enable or disable entire sections of an SQR program from the command line, depending on the -DEBUGxxx flag.
You can nest #IF, #IFDEF, and #IFNDEF directives to a maximum of 10 levels.
The #IF, #IFDEF, and #IFNDEF directives cannot be broken across program lines.
The following table lists the compiler directives.
| Directive | Example | Description |
|---|---|---|
|
#IF |
#IF {option}='A' |
Compiles the commands following the #IF directive if the substitution variable option is equal to 'A'. The test is not case-sensitive. Only one simple expression is allowed per #IF command. |
|
#ELSE |
#ELSE |
Compiles the commands following the #ELSE directive when the #IF expression is FALSE. |
|
#ENDIF |
#ENDIF |
Ends the #IF directive. #ENDIF can also be typed #END-IF (with a hyphen). |
|
#IFDEF |
#IFDEF option |
Compiles the commands following the #IFDEF directive if the substitution variable option is defined. |
|
#IFNDEF |
#IFNDEF option |
Compiles the command following the #IFNDEF directive if the substitution variable option is not defined. |
Parameters
| Parameter | Description |
|---|---|
|
txt_lit | num_lit |
Any text or numeric literal. |
|
comparison_operator |
Any of the comparison operators as shown here: =Equal !=Not Equal <>Not Equal <Less than >Greater than <=Less than or equal >=Greater than or equal |
Example
The following example illustrates the #IF compiler directive:
begin-setup
ask type 'Use Male, Female or Both (M,F,B)'
end-setup
begin-procedure Main
#if {type} = 'M'
...code for M here
#else
#if {type} = 'F'
...code for F here
#else
#if {type} = 'B'
...code for B here
#else
show 'M, F or B not selected. Report not created.'
stop
#endif ! for B
#endif ! for F
#endif ! for M
#ifdef debug
show 'DEBUG: Cust_num = ' &cust_num edit 099999
#endif
#ifndef debugB ! DebugB turned on with -DEBUGB on
do test_procedure ! SQR command line.
#endif
See The #DEBUG command for
information about the -DEBUG command-line flag