As an alternative to creating a
class interactively with the Class Editor, you can create a
SAS/AF class entirely in
SCL with the CLASS/ENDCLASS statement block. You can define all
property information through SCL. When you have finished defining a class with SCL, you must
save it as a CLASS entry so that it can be used as a class.
Creating a class with
SCL has several advantages:
-
Lengthy or repetitive changes to class information (such as adding or deleting the
signatures for several methods) are easier
with a text editor than with the interactive, graphical approach of the Class Editor.
-
Classes that are defined in an SCL entry can define and implement methods in one location.
-
The CLASS block provides improved
error detection at compile time, as well as improved run-time performance.
Metadata information, such as
description, is added to the class or property by including a forward slash (/) delimiter and
the appropriate
metadata items enclosed in parentheses before the semicolon (;) that ends the statement. Use
a comma to separate multiple metadata items (see
description,
SCL,
and
Label in the definition of the
add method below).
Consider the following example, which defines the Combination class in SCL:
CLASS sasuser.myclasses.Combination.class
extends sashelp.fsp.Object.class
/ (description='My Combination Class');
/* define attributes */
Public num total
/ (description='total attribute');
Public char catstr
/ (description='catstr attribute');
/* define methods */
add: public method
n1: num
n2: num
return=num
/(description='Adds two numbers',
SCL='sasuser.myclasses.Combination.scl',
Label='add');
concat: public method
c1: char
c2: char
return=char
/(description='Concatenates two strings',
SCL='sasuser.myclasses.Combination.scl',
Label='concat');
ENDCLASS;
To compile the SCL
program and save it as a CLASS entry:
-
Save the SCL entry. You must save an SCL entry before using Save as Class or
the SAVECLASS command.
-
From the
Source window,
select
File
Save As
Class.
Alternatively, you can
enter the SAVECLASS command.
Saving an SCL program as a class is equivalent to saving a class that you created
interactively with the Class Editor.
You can implement the methods directly in the same SCL as the class definition. The
following code defines the Combination class and implements its methods:
CLASS
sasuser.myclasses.Combination.class
extends sashelp.fsp.Object.class
/ (description='My Combination Class');
/* define attributes */
Public num total
/ (description='total attribute');
Public char catstr
/ (description='catstr attribute');
/* define methods */
add: public method
n1:num
n2:num
return=num
/(description='Adds two numbers');
total=n1+n2;
return (total);
concat: public method
c1:char
c2:char
return=char
/(description='Concatenates two strings');
catstr=c1 || c2;
return(catstr);
ENDCLASS;
Additionally, you can create an abstract class by adding the optional reserved word
ABSTRACT before the CLASS statement. For example:
ABSTRACT CLASS myClass
EXTENDS sashelp.fsp.Object.class;
/* ...insert additional SCL here... */
ENDCLASS;
For complete information about the CLASS statement, including all valid metadata that
you can include with the class and properties definitions, see the SAS
Component Language: Reference.