Previous Page | Next Page

SAS Component Language Dictionary

METHOD



Executes a method block that is defined in an SCL entry
Category: Modular Programming and Object Oriented

Syntax
Details
Example
See Also

Syntax

CALL METHOD(entry,label<,parameters>);
return-value=METHOD(entry,label<,parameters>);

entry

is a catalog entry of type SCL. To specify an entry in the current catalog, use entry or entry.type. To specify an entry in a different catalog, use libref.catalog.entry.type. If type is not specified, it defaults to SCL.

Type: Character

label

is the name of the method block in the SCL entry.

Type: Character

parameters

are parameters to pass to the method block. The SCL entry that receives these parameters must declare each of them in a METHOD statement.

Note:   These parameters are update parameters. See Input, Output, and Update Parameters for more information.  [cautionend]

Type: Character

return-value

contains the value that is returned by the method block.

Type: Numeric, Character, List, Object, Class, or Interface


Details

METHOD can pass parameter values to the called method, and it can receive a value when it is used as a function. In order to return a value, the associated METHOD statement must contain the RETURN= option, and the RETURN statement must specify the variable or literal value to return.

Parameters that are passed must agree with the number of arguments, relative positions, and data types in the corresponding method block unless the REST= or ARGLIST= options are used in the method block. The parameter names in METHOD do not have to match the argument names in the method block.

A method block, which contains a sequence of SCL statements, can be defined either in the current SCL entry or in another, external SCL entry. If the method block is defined in the current entry, it is more efficient to use a LINK statement instead of a METHOD routine.

Parameters are passed in the following ways:

call-by-reference

passes variables and enables values to be returned to CALL METHOD. This approach enables the called method block to modify values and then to return them.

An example of a call-by-reference is

call method('b.scl','abc',var1,name,field2);

If you do not want to return the values, use the NOCHANGE() routine in the method block. Or, you can assign the INPUT, OUTPUT, and UPDATE options to the variables listed in the METHOD statement to determine which variables can receive and return values. For example:

abc: method var1 :input :num
            name :update :char
            field1 :output :num;
call-by-value

is used for all numeric constants, character constants, and expressions. It does not return values to the calling METHOD routine. An example of a call-by-value is

call method('b.scl','abc',100,'hello',x+y);

Example

Call the method block that is labeled ABC in the SCL entry CODE. The following three parameters are passed: the contents of the variable A, the literal value 3, and the contents of the variable C.

call method('code.scl','abc',a,3,c);

The method block can return modified values to the variables A and C unless the NOCHANGE routine is specified in the method block or unless A and C are not specified in the METHOD statement as input parameters.


See Also

DISPLAY

NOCHANGE

METHOD

Previous Page | Next Page | Top of Page