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.
if CONDITION then
ACTION 1 .
[ACTION 2 .
ACTION N .]
ACTION 1 .
[ACTION 2 .
ACTION N . ]]
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 contain at lease one true action (following the keyword then). When an if statement contains an else command, at least one action must follow the keyword else.
for MEMBERS ;
if highest of RESERVATIONS DATE <01/01/99 then
delete records .
delete records in RESERVATIONS
with ( DATE < 01/01/99) .
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, 1999, delete the MEMBERS record, and (3) if a member's most recent invoice is dated on or after January 1st, 1999, delete all of that member's RESERVATIONS records dated prior to 1999.
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.
Nested if Command:
for RESERVATIONS ;
if TOTAL DUE > 3000 then
modify records in MEMBERS
STATUS := PREFERRED .
if DATE between 01/01/99 to current date then
enter a record in CATALOG MEMBERS
copy all from MEMBERS .
This script tells DataEase to divide the RESERVATIONS records into two groups and process them as follows: (1) The records with a TOTAL DUE greater than $3000 are modified by changing the value in the STATUS field to PREFERRED, and (2) the records with a TOTAL DUE greater than 3000 and a DATE between the start of 1994 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.