pTAL Conversion Guide

Statements
pTAL Conversion Guide527302-002
15-22
Returning a Condition Code in pTAL
A function or procedure that specifies RETURNSCC must include cc-expression
on every RETURN statement. Conversely, specify cc-expression in RETURN
statements only in functions and procedures that specify RETURNSCC.
You can test the condition code returned by a function, even if you call the function in a
CALL statement.
Example 15-30.
INT PROC p(i) RETURNSCC;
INT i;
BEGIN
INT cc_result;
...
cc_result :=
IF i < max_val THEN -1
ELSE
IF i = max_val THEN 0
ELSE 1;
RETURN i, cc_result; ! Return function value and
END; ! condition code that indicates
! whether the function value is
! less than, equal to, or
! greater than some maximum
Example 15-31. Testing the Condition Code Returned by a Function (pTAL)
INT PROC p1(i);
INT i;
BEGIN
RETURN i;
END;
INT PROC p2(i) RETURNSCC;
INT i;
BEGIN
INT j := i + 1;
RETURN i, j;
END;
CALL p1(1);
IF < THEN ...
CALL p2(1);
IF < THEN ...