Contents | Index | < Browse | Browse >
CALL
usage: CALL {symbol|string} [expression] [,expression,...]
-used to invoke an internal or external function
-A special variable called RESULT holds the value returned by the function
-If a result is not returned, then RESULT is DROP ed (made uninitialized)

Example code #1:
---------------
[Note: this format puts the arguments into CALL() form which places call parameters as separate, comma-separated arguments: (arg1,arg2, etc.) which have to be retrieved with parsing arg(1), arg(2), etc.]

Var=56.4446
say var
Call Round(var,2) /* ask function to round to two decimal places */
Var=result
say Var
Exit

Round:
procedure
/* parse and round decimal number to specified decimal precision */
parse value arg(1)*1.0 with integer '.' fraction
Precision=arg(2)
Parse numeric NumDigits .
numeric digits 2
fraction=trunc('.'||fraction,precision)
numeric digits NumDigits
RETURN integer+fraction

Example code #2:
---------------
[Note: this format puts the arguments into "CALL var1 var2, etc." form which places call parameters as space delimited arguments, and which then have to be retrieved with parsing format PARSE ARG arg1 arg2 arg3 .]

Var=56.4446
say var
Call Round var 2 /* ask function round to two decimal places */
Var=result
say Var
Exit

Round:
procedure
/* parse and round decimal number to specified decimal precision */
parse arg integer '.' fraction precision
Parse numeric NumDigits . /* discover current setting for precision */
numeric digits precision
fraction=trunc('.'||fraction,precision)
numeric digits NumDigits /* restore precision */
RETURN integer+fraction


TIP:
---
"CALL" works together with ARG() without () in this format...

/* Example 1 */
options results
call checkarg 15,20
say rc result
exit

CheckArg:
call arg() /* get the number of supplied arguments */
return result

Returns: RC 2

...But "CALL" fails in this format...

/* Example 2 */
options results
call checkarg 15,20
say rc result
exit

CheckArg:
arg()
return result

Returns: Command returned 10/37: Invalid template

It will work, though, if you substitute "arg()" with the following:

CheckArg:
x=arg()
return x

Returns: RC 2