pTAL Conversion Guide

Statements
pTAL Conversion Guide527302-002
15-21
Returning a Condition Code in pTAL
Example 15-28 on page 15-21 is the syntactically correct version of Example 15-27 on
page 15-21.
pTAL functions that do not specify RETURNSCC return a condition code that is based
on the numeric value returned by the function, regardless of the nature of the
expression in the RETURN statement.
In Example 15-29 on page 15-21, p returns the value -1, 0, or 1 and the condition code
<, =, or >, according to whether I is equal to zero, one, or any other value, respectively.
Functions can return a condition code that is independent of the value returned by the
function if both:
The function declaration specifies the RETURNSCC attribute.
Each RETURN statement in the function specifies the value of the condition code.
Example 15-27. Procedure Without RETURNSCC Attribute (pTAL)
PROC p;
BEGIN
...
END;
PROC q;
BEGIN
CALL p;
IF < THEN ... ! ERROR: p did not return a condition code
END;
Example 15-28. Procedure With RETURNSCC Attribute (pTAL)
PROC p RETURNSCC;
BEGIN
INT i;
...
RETURN ,i;
END;
PROC q;
BEGIN
CALL p;
IF < THEN ... ! OK: P returns a condition code
END;
Example 15-29. Function Without RETURNSCC Attribute (pTAL)
INT PROC p(i); ! Function that does not specify RETURNSCC
INT i;
BEGIN
RETURN IF i = 0 THEN -1 ! Returns a condition code
ELSE IF i = 1 THEN 0 ! based on the value returned
ELSE 1
END;