Relates conditions to actions.
IF condition THEN
then block
[ELSEIF condition THEN
elseif block]…
[ELSE
else block]
END IF;
Example
DEFINE R1 TYPE(FB) DATA(
A SMALLINT,
B SMALLINT,
C SMALLINT,
D SMALLINT,
DSNAME 'IBMUSER.Files.R1';
IF R1.C = R1.A THEN;
R1.B = R1.A;
ELSEIF R1.C = 456 THEN;
R1.E = 1234;
ELSEIF R1.C
= 567 THEN;
R1.B
= 123;
ELSE;
R1.D
= R1.A;
END IF;
The keyword
THEN is optional.
The IF statement
is used to relate conditions to actions. Conditions are tested from the top:
the first true condition causes the corresponding block to be executed, and
following conditions and statements to be ignored. Unconditional execution resumes after END IF.
A block can
contain zero or any number of statements.
For example this is perfectly valid, meaning “Do nothing if R1.C = R1.A”
IF R1.C = R1.A THEN;
ELSEIF R1.C = 456 THEN;
R1.E = 1234;
END IF;
A block can
contain further logic-control statements: for example
IF R1.C = R1.A THEN;
IF R1.C = 456 THEN;
R1.E = 1234;
END IF;
ELSEIF
R1.C = 456 THEN;
R1.E
= 1235;
END IF;
By the way,
this particular example could be written without a nested IF as: -
IF R1.C = R1.A & R1.C = 456 THEN;
R1.E = 1234;
ELSEIF R1.C = 456 THEN;
R1.E =
1235;
END IF;
Any inner
logic must be completed with appropriate END IF, END FOR, or END CASE statements before the outer IF statement
is resumed.
Conditions, which are described here, are
essentially the same wherever a condition is written: in IF and ELSEIF
statements, in WHERE and UNTIL options of FOR and I/O
statements (GET, PROCESS, UPDATE,
DELETE).