Type
Procedural Command

Purpose
The if command executes one of two different actions (or series of actions) based on whether a specified condition is true or false.
When processing reaches an if command, DataEase evaluates the condition that follows the keyword if.
If the specified condition is true, DataEase executes all the actions which follow the keyword then until processing reaches the corresponding end or else command.
If the specified condition is false, DataEase executes all the actions that follow the keyword else (if present) until processing reaches the corresponding end command.

Syntax
if CONDITION then
ACTION 1 .
[ACTION 2 .
.
.
ACTION N .]
[else
ACTION 1 .
[ACTION 2 .
.
.
ACTION N . ]]
end

Usage
A script may contain multiple if commands nested within one another (see Example 2). An additional if command can appear after either then or else.
Each if command must be matched with a corresponding end command. When if commands are nested, the first end corresponds to the last preceding if. This rule applies to all nested Procedural commands (case, for, if, and while). See nested actions and the for command entry for more information on nesting one command inside another.

Example 1
for MEMBERS ;
if highest of RESERVATIONS DATE <01/01/90 then
delete records .
else
delete records in RESERVATIONS
with (<MS>DATE < 01/01/90) .
end
end

This script tells DataEase: 1) For each MEMBERS record, find the most recently dated record in the related RESERVATIONS table. 2) If the most recent invoice is dated before January 1st, 1980, delete the MEMBERS record. 3) If a member's most recent invoice is dated on or after January 1st, 1990, delete all of that member's RESERVATIONS records dated prior to 1990.
The first end marks the end of the if command that selects the records to delete. The second end marks the end of the for command that selects the records from the Primary table.

Example 2
Nested if Command:
for RESERVATIONS ;
if RESERVATIONS TOTAL DUE > 3000 then
modify records in MEMBERS
STATUS := PREFERRED .
if DATE between 01/01/92 to current date then
enter a record in CATALOG MEMBERS
copy all from MEMBERS .
end
end
end


This script tells DataEase to divide the RESERVATIONS records into two groups and process them as follows: 1) The records with an TOTAL DUE greater than $3000 are modified by changing the value in the STATUS field to PREFERRED. 2) The records with an TOTAL DUE greater than 3000 and a DATE between the start of 1992 and today's date are modified and also copied into the CATALOG MEMBERS table.
In this example, the second if command, which selects a subgroup of the records selected by the first if command, is nested within the first if command.