Consultor Eletrônico



Kbase P114809: How to use the IF and ELSE options of the ASSIGN statement?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   3/31/2006
Status: Unverified

GOAL:

How to use the IF and ELSE options of the ASSIGN statement?

GOAL:

Sample code using the IF and ELSE options when assigning variables.

FIX:

The following code samples demonstrate the use of the IF and ELSE options with the ASSIGN statement:
ASSIGN x = IF <condition> ... requires default ELSE clause. For example, the following snippet is valid 4GL syntax:
DEFINE VARIABLE x AS CHAR.
DEFINE VARIABLE y AS CHAR INIT "abc".
ASSIGN x = IF y = "abc" THEN "it's abc"
ELSE "not abc".
DISPLAY x.
In this example, x will be assigned the value "it's abc".
If the ELSE clause is dropped, an error message will be generated. For example, the following snippet is NOT valid 4GL syntax:
ASSIGN x = IF y = "abc" THEN "it's abc".
This statement results in error 247 "Unable to understand after -- ASSIGN x" because there is no ELSE clause to trap the failed condition test. Similarly, the next statement is also invalid:
ASSIGN x = IF y = "abc" THEN "it's abc" ELSE
IF y = "xyz" THEN "it's xyz".
Again, the possibility exists that the ASSIGN statement will not have a valid value once the conditional expression is evaluated which is not valid syntax.