Call
This instruction is used to call a subroutine executed with its own local variables class.
No value is returned by this instruction. Parameters can be transmitted as values or as references; so that the parameters transmitted by reference can be modified by the subroutine.
Call SUBPROGRAMCall SUBPROGRAM From LIBRARYCall SUBPROGRAM(ARGUMENT_LIST)Call SUBPROGRAM(ARGUMENT_LIST) From LIBRARYCall SUBPROGRAM From =EXPRESSION_LIBRARYCall SUBPROGRAM(ARGUMENT_LIST) From =EXPRESSION_LIBRARYCall =EXPRESSION_CALLCall =EXPRESSION_CALL From LIBRARYCall =EXPRESSION_CALL With (ARGUMENT_LIST)Call =EXPRESSION_CALL With (ARGUMENT_LIST) From LIBRARYCall =EXPRESSION_CALL With (ARGUMENT_LIST) From =EXPRESSION_LIBRARYCall =EXPRESSION_CALL With (ARGUMENT_LIST) From =EXPRESSION_LIBRARY
SUBPROGRAM
is the name of the routine declared by the Subprog keyword.LIBRARY
is the name of the script that contains the code of the routine called.ARGUMENT_LIST
is a list of expressions, variables, or subarrays that can be empty. The elements are separated by commas.EXPRESSION_LIBRARY
is an alphanumeric expression whose evaluation returns the script name that contains the code of the routine called.EXPRESSION_CALL
is an alphanumeric expression whose evaluation returns the name of the routine called. # Call of a routine that increments a valueLocal Integer II=314 : Call ADD_ONE(I)I=314 : Call TRY_TO_ADD_ONE(I)I=315 : Call FAIL_TO_ADD_ONE(I)# The value of I found here depends on how the parameter has been declared in the routine# After the first call, I=315# After the second call, I=314# The third call will raise an error...# Case 1 : the argument is declared as a referenceSubprog ADD_ONE(J)Variable Integer JJ+=1 : # J is equal to 315, but J is a reference to I in the calling script, so I is equal to 315I=316 : # I is a local variable that does not refer to the I variable in the calling scriptEnd# Case 2 : the argument is declared as a valueSubprog TRY_TO_ADD_ONE(J)Value Integer JJ+=1 : # J is equal to 315, but J is a local copy of I that is not sent back, so I remains equal to 314End# Case 3 : the argument is declared as a constant referenceSubprog FAIL_TO_ADD_ONE(J)Value Integer JJ+=1 : # Raises an error : J is read-onlyEnd# Call of a subroutine with parameters in another processLocal Integer MATRIX(1..10,1..20,1..30)...# Only a subarray is transmitted (even if it is sent as a reference)Call COMPUTE_SUM(MATRIX(5..6,2..4,1..20),RESULT) FROM MATRIX_LIBRARY...# In the MATRIX_LIBRARY script, the arguments areSubprog COMPUTE_SUM(MATRIX,RESULT)Const Integer MATRIX(,,)Variable Integer RESULTRESULT=sum(MATRIX)End# A subprogram that returns the data type of the argumentSubprog RETURN_TYPE(ARGUMENT,DATA_TYPE)Variable Integer DATA_TYPEDATA_TYPE=type(ARGUMENT)End# Example of sub-program with a variable type of argumentLocal Integer DATA_TYPELocal Char MY_STRING(20),TEXT(10)MY_STRING="abcdefghijklmnopqrst"Call RETURN_TYPE(pi,DATA_TYPE,TEXT): # Will return 7 (decimal) and "3.14159265"Call RETURN_TYPE([1/1/2013],DATA_TYPE,TEXT) : # Will return 3 (date) and "01/01/2013"Call RETURN_TYPE(100,DATA_TYPE,TEXT) : # Will return 4 (integer) and "100"Call RETURN_TYPE("text sent",DATA_TYPE,TEXT) : # Will return 523 (clob) and "text sent"Call RETURN_TYPE(MY_STRING,DATA_TYPE,TEXT) : # Will return 20 (string 10) and "abcdefghij"End# ARGUMENT has not be declared because it has a variable typeSubprog RETURN_TYPE(ARGUMENT,DATA_TYPE,TEXT)Variable Integer DATA_TYPEVariable Char TEXT()DATA_TYPE=type(ARGUMENT) : # returns the data type of the argumentTEXT=num$(ARGUMENT) : # returns a string representation of the argument regardless of its typeEnd
Call
executes a subroutine with possible parameters. The calling code will end its execution when an End instruction is encountered. The calling process will then resume the execution with the instruction located after the call
instruction.
The local variables and all the resources opened with Local keyword in the subroutine are lost after the execution of the call.
A call
performed without specifying a script is done on the same script.
The number of parameters transmitted in the "call" must correspond to the number of parameters declared in the Subprog instruction.
The parameters of the Subprog can be declared by using a data type prefixed by Variable, Value, or Const. They must be declared just after prefixing the data type that must be the same as the one sent in the Call.
The parameter can be transmitted as:
The declaration of the parameters is not mandatory, and allows you to send parameters of variable types. Make sure that they are transmitted as references on read-only values (exactly as if they would have been declared with Const).
The parameters may be variables or expressions. If a parameter is an expression, it can only be transferred by value; the Subprog parameter cannot be defined with dimensions.
A variable passed in parameters can be declared with dimensions. The number of dimensions must be the same. A subarray can be transmitted as shown in one of the previous examples.
During a "call", the following information is saved:
The following information is lost:
When executing a "call", a class of local variables is created with the subroutine, abbreviated [L]. This local class becomes the default class since the local class with the calling process is no longer accessible. When you return to the process, you will find the default local class which existed before the call.
A "call" can be called recursively and the number of embedded "calls" is not limited. Nevertheless, pay close attention to the available memory as the number of opened table in Local mode for each call nested is viewed independently.
Error code | Description |
---|---|
10 | The expression giving the script name does not return a string value. |
20 | The process does not exist. |
39 | The label does not exist. |
55 | Number of dimensions invalid. |
69 | Number of parameters does not correspond. |
70 | Transmission mode incompatible. |