![](/static/images/style_img/searchBtn.png)
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 . ]]
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.
Example 1
if highest of RESERVATIONS DATE <01/01/99 then
delete records in RESERVATIONS
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, 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.
Example 2
Nested if Command:
modify records in MEMBERS
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.