An IF statement is executed based on the occurrence of a certain condition. IF statements must begin with the keyword IF and terminate with the keyword END.
Components within IF statements can be connected with the keywords AND or OR. IF statements can have three forms: a simple IF statement, an IF statement with an ELSE condition, or an IF statement with an ELSEIF condition.
A simple IF Statement contains a single statement block. The calculation is performed only if the logical expression is true. If the logical expression is false, control passes to the next statement after the END keyword. Here is an example:
IF (@("FirstAmount") < 1000.00) THEN
$FinalAmount = @("FirstAmount") * .05;
END;
RETURN ($FinalAmount)
CALCULATION: If the value of the section variable field FirstAmount is less than 1000.00 then the value is multiplied by .05 and entered in the target variable $FinalAmount. The value of the $FinalAmount target variable is then returned to the section variable field.
The use of the keyword connector THEN is optional.
An IF Statement with an ELSE condition contains an alternative calculation. If the logical expression is false, control passes to the statement after the ELSE keyword.
Here is an example:
IF (@("FirstAmount") < 1000.00) THEN
$FinalAmount = @("FirstAmount") * .05;
ELSE
$FinalAmount = @("FirstAmount") + 10.00;
END;
RETURN ($FinalAmount)
CALCULATION: If the value of the section variable field FirstAmount is less than 1000.00 then the amount is multiplied by .05 and entered in the target variable $FinalAmount.
If the value of the section variable field FirstAmount is greater than or equal to 1000.00 then 10.00 is added to the amount and entered in the target variable $FinalAmount.
The value of the $FinalAmount field is then returned to the caller or section variable field.
The use of the keyword connector THEN is optional.
An IF statement with an ELSEIF condition is the most complicated type of IF statement. If the first logical expression is true, the statement block after IF is executed until the first ELSEIF statement is reached. If the first logical expression is false, the first ELSEIF logical expression is evaluated. If the ELSEIF logical expression is true, the statement block from the ELSEIF to the next ELSEIF (or ELSE) is executed. If the ELSEIF statement is false, the next ELSEIF is evaluated. If all logical expressions are false, control passes to the ELSE block. If there is no ELSE block, control passes to the statement following the END keyword.
An ELSEIF statement is considered part of the same IF statement. Only one END keyword is needed to end an IF, ELSEIF, or ELSE statement. IF statements can be nested inside other IF statements. A nested IF statement requires its own END keyword. A missing or mismatched keyword results in a runtime syntax error. Here is a sample IF statement with ELSEIF condition:
IF (@("FirstAmount") < 1000.00)
$FinalAmount = @("FirstAmount") * .05;
ELSEIF @("FirstAmount") < 5000.00
$FinalAmount = @("FirstAmount") * .03;
ELSEIF @("FirstAmount") < 10000.00
$FinalAmount = @("FirstAmount") * .02;
ELSE
$FinalAmount = @("FirstAmount") + 10.00;
END;
RETURN ($FinalAmount)
CALCULATION: If the value of the section variable field FirstAmount is less than 1000.00 then the amount is multiplied by .05 and entered in the target variable $FinalAmount.
If the value of the section variable field FirstAmount is greater than or equal to 1000.00 but less than 5000.00 then the amount is multiplied by .03 and entered in the target variable $FinalAmount.
If the value of the section variable field FirstAmount is greater than or equal to 5000.00 but less than 10000.00 then the amount is multiplied by .02 and entered in the target variable $FinalAmount.
If the value of the section variable field FirstAmount is greater than or equal to 10000.00 then 10.00 is added to the amount and entered in the target variable $FinalAmount.
The value of the $FinalAmount field is then returned to the caller or section variable field.
© Copyright 2017, Oracle and/or its affiliates. All rights reserved. Legal Notices