Kbase P132341: 4GL/ABL: How to emulate the SQL CEILING and FLOOR functions using 4GL?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  13/06/2008 |
|
Status: Unverified
GOAL:
4GL/ABL: How to emulate the SQL CEILING and FLOOR functions using 4GL?
GOAL:
Sample 4GL/ABL code to define CEILING and FLOOR functions equivalent to their SQL counterparts.
FACT(s) (Environment):
All Supported Operating Systems
Progress 8.x
Progress 9.x
OpenEdge 10.x
FIX:
1. The SQL CEILING function returns the smallest integer more than or equal to its input parameter. The following 4GL Ceiling function has the same functionality as its SQL counterpart:
FUNCTION Ceiling RETURNS INTEGER (INPUT ipdValue AS DECIMAL):
IF (ipdValue LE 0) OR (TRUNCATE(ipdValue,0) = ipdValue) THEN
RETURN INTEGER (TRUNCATE(ipdValue,0)).
ELSE
RETURN integer(TRUNCATE(ipdValue,0) + 1).
END.
2. The SQL FLOOR function returns the largest integer less than or equal to its input parameter. The following 4GL Floor function has the same functionality as its SQL counterpart:
FUNCTION Floor RETURNS INTEGER (INPUT ipdValue AS DECIMAL):
IF (ipdValue GE 0) OR (TRUNCATE(ipdValue,0) = ipdValue) THEN
RETURN INTEGER (TRUNCATE(ipdValue,0)).
ELSE
RETURN integer(TRUNCATE(ipdValue,0) - 1).
END.
3. The following procedure defines the above two 4GL/ABL functions and demonstrates their functionality:
FUNCTION Ceiling RETURNS INTEGER (INPUT ipdValue AS DECIMAL) FORWARD.
FUNCTION Floor RETURNS INTEGER (INPUT ipdValue AS DECIMAL) FORWARD.
MESSAGE
Ceiling(-3.6) Ceiling(-3.3) Ceiling(-3) Ceiling(0) Ceiling(3) Ceiling(3.3) Ceiling(3.6) "~n"
Floor(-3.6) Floor(-3.3) Floor(-3) Floor(0) Floor(3) Floor(3.3) Floor(3.6)
VIEW-AS ALERT-BOX INFO BUTTONS OK.
FUNCTION Ceiling RETURNS INTEGER (INPUT ipdValue AS DECIMAL):
IF (ipdValue LE 0) OR (TRUNCATE(ipdValue,0) = ipdValue) THEN
RETURN INTEGER (TRUNCATE(ipdValue,0)).
ELSE
RETURN integer(TRUNCATE(ipdValue,0) + 1).
END.
FUNCTION Floor RETURNS INTEGER (INPUT ipdValue AS DECIMAL):
IF (ipdValue GE 0) OR (TRUNCATE(ipdValue,0) = ipdValue) THEN
RETURN INTEGER (TRUNCATE(ipdValue,0)).
ELSE
RETURN integer(TRUNCATE(ipdValue,0) - 1).
END.