Definition
Define an internal subroutine.
subroutine SUB_NAME
([ TYPE1:ARG1_NAME [,TYPE2:ARG2_NAME] ...]) is
[LOCAL_VAR] ...
ACTION_STATEMENT
[ACTION_STATEMENT] ...
SUB_NAME
Identifier for the subroutine.
TYPEn
One of the following: integer, string, boolean, float, or structure STRUCTDEF_NAME (STRUCTDEF_NAME is the identifier of a previously defined structure type). For information about defining, declaring, and using structures, see the Programming Guide.
ARGn_NAME
A variable of type TYPEn.
LOCAL_VAR
One or more variable definitions. The variables are local to the subroutine and cannot be referenced outside of it. Local variables are re-initialized whenever the subroutine is called. Note that you cannot declare a structure variable within a subroutine.
ACTION_STATEMENT
An action statement.
Description
Arguments of the same type must be declared separately; for example:
integer:A, integer:B
Arguments and local variables cannot have the same name.
You cannot define another subroutine or action routine within other subroutines. You can, however, call subroutines, action routines, or functions from within other subroutines, as long as they have been defined or declared previously. Array variables may not be passed to ESL subroutines.
An ESL internal or external subroutine can take a maximum of 13 arguments.
Note that if subroutine definitions are placed inside a response, the execution of the response will be interrupted so that no other actions within the response will be executed.
You cannot define a constant within a subroutine.
All blocks defined within a subroutine must be guarded blocks.
You cannot declare a structure variable within a subroutine.
Example
subroutine ReadFile(string:InputFile_SV,
string:DisplayRegionName_SV) is
read file InputFile_SV into DisplayRegionName_SV
response to GetFile
copy "File.dat" to InputFile_SV
copy "DisplayRegion" to DisplayRegionName_SV
call ReadFile(InputFile_SV, DisplayRegionNa_SV)
subroutine Factorial(integer:Number_IV, integer:Result_IV) is
integer I
J is 1
for I= 1 to Number_IV loop
copy (J*I) to J
end loop
copy J to Result_IV
action GetFactorialOf5 is
copy 5 to Number_IV
call Factorial(Number_IV,Result_IV)
send "Result: " Result_IV "\n" to errorlog
structure EmpRec is
string EmpName
integer EmpNum
end structure
subroutine InitEmpRec ( structure EmpRec: Employee ) is
copy "" to Employee.EmpName
copy 0 to Employee.Empnum
See Also
call Action Statement
structure Variable Declaration
structure is Type Definition
subroutine Declaration