Chapter Contents

Previous

Next
SAS Component Language: Reference

Defining and Using Methods

Methods define operations that you can perform on data. Methods are defined with the METHOD statement. Methods can be implemented in CLASS blocks or in USECLASS blocks. In addition, if you are not designing a strictly object-oriented application, they can be stored in separate SCL entries.

Storing method implementations in SCL entries enables you to write methods that perform operations that are common to or shared by other applications. You can call the methods from any SAS/AF application.

For more information about defining and using methods in CLASS and USECLASS blocks, see SAS Object-Oriented Programming Concepts and Example: Creating An Object-Oriented Application.


Defining Method Blocks

To define a method, use the METHOD statement. For example, the METHOD statement in Example Class Definition defines the public method addNums, which takes two numeric parameters, adds them, and returns the total.

Note:   Do not include window-specific statements or functions (for example, the PROTECT and CURSOR statements and the FIELD and MODIFIED functions) in method blocks that are stored in independent SCL entries. SCL entries that contain window-specific statements or functions will not compile independently. They must be compiled in conjunction with the associated FRAME entry.  [cautionend]

When you want to pass parameters between an SCL program and a method block, you use the same principles as when you are passing parameters between a CALL DISPLAY statement and an ENTRY statement. Unless the REST=, ARGLIST=, or OPTIONAL= option is used in the METHOD statement, the parameter list for the METHOD statement and the argument list for the associated ENTRY statement must agree in the following respects:

The parameters and arguments do not have to agree in name. For more information, see METHOD and ENTRY.


Calling a Method That Is Stored in an SCL Entry

If the method module is stored in a PROGRAM entry or SCREEN entry, then you must use a LINK or GOTO statement to call it. Although parameters cannot be passed with LINK or GOTO statements, you can reference global values in those statements.

If the module is an SCL entry, then call the method module with a CALL METHOD routine. The CALL METHOD routine enables you to pass parameters to the method. For example, a program that needs to validate an amount can call the AMOUNT method, which is stored in METHDLIB.METHODS.VALIDATE.SCL:

call method('methdlib.methods.validate.scl',
             'amount',amount,controlid);
After the method module performs its operations, it can return modified values to the calling routine.

If the method module is stored in the SCL entry that is associated with the FRAME entry, then you must compile the SCL entry as a separate entity from the FRAME entry in addition to compiling the FRAME entry.

For more information about the CALL METHOD routine, see METHOD.


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.