How to write CASE-Statement in Progress-4GL?

abd050707

New Member
Hi,

how can you write this IF-Statement as a CASE-Statement?

Code:
DEF VAR i AS INT.

IF i < 0 THEN
    MESSAGE "i < 0".
ELSE IF i = 0 THEN
    MESSAGE "i = 0".
ELSE
    MESSAGE "i > 0".

/*like following?? It doesn't work!!*/

CASE i:
    WHEN < 0 THEN
        MESSAGE "i < 0".
    WHEN = 0 THEN
        MESSAGE "i = 0".
    WHEN > 0 THEN
        MESSAGE "i > 0".
END CASE.

DISP i.
Thanks
Tom
 
case

Can't really put less-than or greater-than logic in it. If the values are specific you can with the OR

case i:

when 0 then do...end.
when 1 or
when 2 or
when 3 or
when 4 then do...end.
when -1 or
when -2 or
when -3 or
when -4 then do...end.
otherwise do...end.
end case.
 
Syntax

As previousley iterated. The CASE command can not be variable. Therefor your criteria HAS to be constant.
CASE iVarName:
WHEN 1 AND <= 50 THEN
DO:
/* iVarName< 50 */
END.

WHEN 51 AND <= 99 THEN
DO:
/* iVarName< 100 */
END.

END CASE.
 
Another approach to solve this problem

DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE lxGT AS LOGICAL NO-UNDO.
DEFINE VARIABLE lxEQ AS LOGICAL NO-UNDO.
i = 0.
lxGT = i GT 0.
CASE lxGT:
WHEN TRUE THEN
DO:
MESSAGE "i is greater than 0"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
WHEN FALSE THEN
DO:
lxEQ = i EQ 0.
CASE lxEQ:
WHEN TRUE THEN
DO:
MESSAGE "i is equal to 0."
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
WHEN FALSE THEN
DO:
MESSAGE "i is less than 0"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
END CASE.
END.
END CASE.

/* Note: Please change the value to test all possible messages */
 

praneesh

New Member
Try dis out!!!

DEFINE VARIABLE i AS INTEGER NO-UNDO INIT -1.
CASE i < 0:
WHEN TRUE THEN
MESSAGE "<1".
OTHERWISE
CASE i = 0:
WHEN TRUE THEN
MESSAGE "0".
OTHERWISE
MESSAGE ">1".
END CASE.
END CASE.
 
Top