CALL (Statement)


Call a program and execute it.


CALL <programname> [(<argument>[,<argument>...])]


This statement calls the program specified by <programname> and transfers control to that program.
An END statement in a called program is functionally equivalent to a RETURN statement in a subroutine so that execution of the END statement returns control to the caller program.
<argument> is passed to the program specified by <programname> either by "call by value" or "call by reference." The former uses a constant or expression; the latter passes a variable. For details, refer to 8.16 "Calling with a Value and with Reference".
Call by value
In calling by value, a constant, arithmetic expression or string expression is passed as a value.
Even a variable, if enclosed in parentheses ( ), is regarded as an expression and can be passed as a value. In the case of numbered variables, integer, floating-point, double-precision, and string variables can be passed if enclosed in parentheses ( ).
Example: Calling PROGRAM SUB1(AA#)
- To pass a variable as a value
CALL SUB1((D1))
- To pass a constant
CALL SUB1(10#)
- To pass an arithmetic expression
CALL SUB1(D1+D2)

In passing an arithmetic expression, the type of operation result should match that of an argument in the called program.
Call by reference
In calling by reference, a variable can be passed as an argument.
To specify a whole array as <argument>, enclose the array name with parentheses ( ).
A global variable or a single element of a local array cannot be passed by reference. To pass such an element by reference, assign a value to the local variable once and then call the program by reference via the local variable.
If the called program changes the data passed as a variable by calling by reference, the content of the variable in the caller program is changed.
Example 1: Calling PROGRAM SUB1(AA#)
- To pass a local variable (1)
CALL SUB1(DD#)
- To pass a local variable (2)
CALL SUB1(DA)

(where DA has been declared with DEFDBL.)
A local variable should be assigned a value beforehand.
Example 2: Calling PROGRAM SUB2(BB%(10))
- To pass a whole array
CALL SUB2(AB%())

(where AB%(10) has been declared with DIM.)
If no value has been assigned to a variable, an error occurs in execution.
In programs having the name PROnumeral, an argument cannot be passed.
The number of arguments in a caller program must match the one in the called program.



DEFDBL ld1, ld2
CALL SUB1((ld1))
'Pass a variable as a value
CALL SUB1(10#)
'Pass a constant
CALL SUB1(ld1 + ld2)
'Pass an arithmetic expression


Top