Chapter Contents

Previous

Next
SAS Component Language: Reference

SCL Data Types

SCL has the following data types:


Declaring Data Types

You can use the DECLARE statement for declaring any type of SCL variable. You can use the LENGTH statement for declaring numeric and character variables.

You can also declare data types when you use the ENTRY and METHOD statements. In these statements, you must specify a colon before a named data type; with an unnamed data type, (for example, $), the colon is optional. For example:

ENTRY: name :$20
       location $20
       zipcode :num
       mybutton :mylib.mycat.button.class
       return=char;
For details, see DECLARE, LENGTH, ENTRY, and METHOD.


Numeric (NUM) Variables

Numeric variables contain numbers and are stored as doubles. They are declared with the keyword NUM.

   /* declare a numeric variable AGE           */
declare num age;

   /* declare the numeric variables AGE and YEARS*/
declare num age, years;

   /* declare numeric variables X and Y.         */
   /* Initialize X to 1 and Y to 20 plus the     */
   /* value of X.                                */
declare num x, y=20+x;


Character (CHAR) Variables

Character variables can contain up to 32,767 characters and are declared with the keyword CHAR. A variable that is declared as CHAR without a specified length is assigned a default length of 200.

   /* declare a character variable NAME and   */
   /* assign the value ABC to it              */
declare char name='abc';

   /* declare a character variable NAME       */
   /* with a length of 20                     */
declare char(20) name;


Lists

SCL lists are ordered collections of data. Lists are dynamic; they grow and shrink to accommodate the number or size of the items that you store in them. Lists can contain items of different data types.

To declare an SCL list, use the keyword LIST. The following example declares the list MYLIST:

declare list mylist;
The function that creates the list (for example, MAKELIST) assigns the identifier for the list to the variable, as shown below.
declare list mylist;
   ...more SCL statements...
mylist=makelist();

Note:    To maintain compatibility with previous releases, the SCL compiler does not generate error messages if a list is not declared or if it is declared as a numeric variable. However, it is recommended that you declare lists so that the compiler can identify errors. A list must be declared as type List when it is passed to a method that requires an argument of type List. See Overloading and List, Object, and Numeric Types.   [cautionend]

For information about using lists, see SCL Lists.


Objects

Objects can be declared in either of two ways:

You can use dot notation for accessing attributes and methods for both specific objects and generic objects.

Note:   If you want to use dot notation to access the attributes or methods of a Version 6 widget, then you need to declare its widget ID of OBJECT type, and you must obtain its widget ID with the _getWidget method. For example, Text is a Version 6 text entry widget. To access its methods or attributes with dot notation, you should use code that looks like this:

dcl object obj;
/* dcl sashelp.fsp.efield.class obj; */
call notify ( `Text', `_getWidget', obj );
obj.backgroundColor = `blue';
See Accessing Object Attributes and Methods With Dot Notation for more information.  [cautionend]

Specific Objects (CLASS and INTERFACE)

The following example declares an object named DataHolder as an instance of the Collection class, which is provided with SAS software:

declare sashelp.fsp.collection.class DataHolder;

When you declare a class, you can also use the IMPORT statement to reference the class and then use an abbreviated form of the class name in the DECLARE statement. For example:

import sashelp.fsp.collection.class;
declare collection DataHolder;

Generic OBJECTs

In the following example, MyObject is recognized by the compiler as an object, but the compiler has no information about the type of class instance that the object will actually be:

declare object MyObject;

Specifying the Object Type at Run Time

The following example declares an object named PgmObj2 and then specifies one condition under which PgmObj2 will be a collection object and another condition under which PgmObj2 will be an object that is created from a class named Foo. The _NEW_ operator creates the object.

declare object PgmObj2,
        num    x;
if x=1 then
   PgmObj2=_new_ sashelp.fsp.collection.class;
else
   PgmObj2=_new_ sashelp.fsp.foo.class;

As described above, you can use the IMPORT statement to reference a class definition and then use an abbreviated class name when you create the class.

import sashelp.fsp.collection.class;
import sashelp.fsp.foo.class;
declare object PgmObj2,
        num    x;
if x=1 then
   PgmObj2=_new_ collection();
   end;
else
   PgmObj2=_new_ foo();
Any errors that result from using incorrect methods or attributes for PgmObj2 and Foo will cause the program to halt.


Chapter Contents

Previous

Next

Top of Page

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