IF Operator Explained

NOMAD/UltraQuest IF Operator Explained

IF Operator - Allows a user to add logic to their DEFINES or expressions.

The information below is from the NOMAD/UltraQuest Reference Manual page 594.

The IF operator tests a logical expression and returns a value based on the value of the logical expression, that is, based on whether the expression is TRUE or FALSE.

Required Parameters

IF logical-expression THEN expression1
ELSE expression2

logical-expression - An expression that resolves to a TRUE or a FALSE condition.

THEN expression1

Specifies the expression to execute if the logical expression is TRUE. Expression1 can be any valid 4GL expression. The result of the IF-test operator is the value of this expression if the result of the logical expression is TRUE.

ELSE expression2

Specifies the expression to execute if the logical expression is FALSE. Expression2 can be any valid 4GL expression. The result of the IF-test operator is the value of this expression if the result of the logical expression is FALSE. Expression1 and expression2 must both have the same data type.

Problem:

I want to create a new DEFINE (Virtual Field) or expression based on the values of two table columns (fields) ACCOUNT_TYPE that is 3 digits long, 999, and SERVICE_CHARGE that is A1.  Based on the value of these two fields I will determine a NEW_ACCOUNT_TYPE.

Possible Values in the Table Columns:

ACCOUNT_TYPE SERVICE_CHARGE
100 A
200 B
300 C
400 D
500 E
600 F

Desired Result:

ACCOUNT_TYPE SERVICE_CHARGE NEW_ACCOUNT_TYPE
100 B 150
200 D 450
500 C 550

Everything else needs to be set to 750.

Solution:

DEFINE NEW_ACCOUNT_TYPE AS 999 =
IF ACCOUNT_TYPE EQ 100 AND SERVICE_CHARGE EQ ‘B’ THEN 150
ELSE
IF ACCOUNT_TYPE EQ 200 AND SERVICE_CHARGE EQ ‘D’ THEN 450
ELSE
IF ACCOUNT_TYPE EQ 500 AND SERVICE_CHARGE EQ ‘C’ THEN 550
ELSE 750;

Please contact support if you have any additional questions about the IF operator.

Next week’s topic:  ADDATE