I have noticed a very odd behaviour with an IF-statement in Progress 4gl.
I define an integer with the format “999” which tells it to have 3 digits and then I assign a value lower than 100 (eg. 12) then when I display it it shows as “012” as it should.
But when I add an IF-statement inside the DISPLAY statement that really shouldn’t do anything, the variable is displayed as “12”.
This is a test code to clearify the differences. The LABEL doesn’t affect the output of the variable.
DEF VAR tmp AS INTEGER FORMAT "999".
ASSIGN tmp = 12.
DISPLAY
tmp LABEL "disp1".
DISPLAY
IF TRUE THEN tmp ELSE tmp LABEL "disp2".
The same behaviour could also be acheived by changing the format to “>99”.
My question is: Why does an IF-statement change the way a variable is displayed?
Best regards
//MrBucket
Your second example is similar to:
The compiler sees the IF function returns an integer and applies the default formatting for an integer. The compiler does not try to second guess you and notice that (in your example) both results are the same variable.
(In this case IF is a function embedded within the DISPLAY — not a stand-alone statement of it’s own.)
To get the result you are looking for:
Whenever I embed an IF function I make a point of wrapping it in parenthesis — it helps make it clear that it is embedded and clearly shows where things like a FORMAT phrase apply.