Chapter Contents |
Previous |
Next |
SAS Component Language: Reference |
SCL has the following data types:
Declaring Data Types |
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 |
/* 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 |
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.
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.
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;
declare object MyObject;
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.