Syntax of Methods in Class Definitions
Introduction
In most cases, a method definition defines the runtime behavior of the method. InterSystems IRIS supports also method generators, which are a special kind of method that generate the code that is used at runtime.
Details
A method definition has the following structure:
/// description
Method name(formal_spec) As returnclass [ keyword_list ]
{ implementation }
Or (for a class method):
/// description
ClassMethod name(formal_spec) As returnclass [ keyword_list ]
{ implementation }
Or (for a client method):
/// description
ClientMethod name(formal_spec) As returnclass [ keyword_list ]
{ implementation }
Where:
-
description (optional) is intended for display in the Class Reference. The description is blank by default. See Creating Class Documentation.
-
name (required) is the name of the method. This must be a valid class member name, and must not conflict with any other class member names.
-
formal_spec (optional) specifies the list of arguments that are passed to or from the method.
The formal specification is a list of a method’s arguments, their types, their call-type (ByRef, Output, or ByVal), and optional default values. The Output call type is used to indicate arguments which are passed by reference, but whose incoming value is nominally not used.
-
returnclass (optional) specifies the type of value returned by this method, if any. If you omit returnclass, also omit the word As
-
keyword_list (optional) is a comma-separated list of keywords that further define the method.
See Method Syntax and Keywords for a complete keyword list.
If this list is omitted, also omit the square brackets.
-
implementation (optional) is zero or more lines of code that define what the method does.
To specify the programming language used, use the class-level Language or method-level Language keyword.
Parameter Values
For formal_spec and returnclass, you can specify optional parameter values after the class names. If the method is used as an SQL stored procedure, then these parameter values are used to provide additional information to an ODBC or JDBC client. These parameters are ignored in all other cases. For example:
ClassMethod MyProc(data As %String(MAXLEN = 85)) As %Integer [ SQLProc ]
{
Quit 22
}
For another example:
ClassMethod GetName() As %String(MAXLEN=222) [ SQLProc ]
{
Quit "Mo"
}