Consultor Eletrônico



Kbase P52686: Can the IF THEN ELSE function be used in a FOR EACH state
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   07/11/2003
Status: Unverified

GOAL:

Can the IF <condition> THEN <if-expression> ELSE <else-expression> function be used in a FOR EACH statement WHERE clause with an 'empty' <else-expression>?

FIX:

Strictly speaking, the syntax of IF...THEN...ELSE Function does not allow dropping the ELSE part.

However setting the <else-expression> to TRUE or FALSE may achieve the desired business logic.

The following code snippets illustrate the use of the IF...THEN...ELSE Function in a FOR EACH WHERE clause by translating each code snippet to its equivalent without the IF...THEN...ELSE Function.

/* 1. Code with the an <if-expression> and an <else-expression> */
FOR EACH customer NO-LOCK WHERE
IF Country = 'USA' THEN City = 'Boston' ELSE Customer.Country = 'FRANCE'.
DISPLAY Country balance city.
END.

/* 1. Equivalent code without the IF...THEN...ELSE Function */
FOR EACH customer NO-LOCK WHERE
(Customer.Country = 'USA' AND Customer.City = 'Boston')
OR (Customer.Country = 'FRANCE').
DISPLAY Country balance city.
END.

/* 2. Code with the <else-expression> set to FALSE */
FOR EACH customer NO-LOCK WHERE
IF Country = 'USA' THEN City = 'Boston' ELSE FALSE.
DISPLAY Country balance city.
END.

/* 2. Equivalent code without the IF...THEN...ELSE Function */
FOR EACH customer NO-LOCK WHERE
(Customer.Country = 'USA' AND Customer.City = 'Boston'):
DISPLAY Country balance city.
END.

/* 3. Code with the <else-expression> set to TRUE */
FOR EACH customer NO-LOCK WHERE
IF Country = 'USA' THEN City = 'Boston' ELSE TRUE.
DISPLAY Country balance city.
END.

/* 3. Equivalent code without the IF...THEN...ELSE Function */
FOR EACH customer NO-LOCK WHERE
(Customer.Country = 'USA' AND Customer.City = 'Boston') OR
Customer.Country <> 'USA':
DISPLAY Country balance city.
END.