Previous Page | Next Page

SAS Component Language Dictionary

IMPORT



Defines a search path for references to CLASS entries
Category: Catalog, Object Oriented

Syntax
Details
Examples
Example 1: Defining a Search Path
Example 2: Importing a Class from Another Catalog
See Also

Syntax

IMPORT class-specification;

class-specification

is the two- to four-level name of a CLASS entry. If it is a four-level name, then that CLASS entry is imported. If it is a two-level name, then it is used as the libref.catalog prefix for any one- or two- level CLASS entry names in the program. This prefix is concatenated to the one- or two-level CLASS entry name, and that is the CLASS entry that is searched for. The first CLASS entry that is found is the one that is imported. Any subsequent entries that are found are flagged as warnings.


Details

The IMPORT statement defines a search path for CLASS entry references in an SCL program so that you can refer to CLASS entries with one- or two-level names instead of having to use a four-level name in each reference. The current catalog is always the first catalog to be searched for a one- or two-level class name, regardless of whether there are any imported catalogs. References to CLASS entries are resolved by the SCL compiler at compile time. The SEARCH function can be used to define a search path that will resolve at run time.


Examples


Example 1: Defining a Search Path

Define a MYLIB.MYCAT as a search path for the program.

   /* All the program's classes  */
   /* are defined in MYLIB.MYCAT *
IMPORT mylib.mycat;
   /* collobj1 is defined in       */
   /* mylib.mycat.collection.class */
DECLARE Collection c1=_new_ Collection();
   /* collobj2 is defined in              */
   /* mylib.mycat.OrderedCollection.class */
DECLARE OrderedCollection c2=_new_ OrderedCollection();


Example 2: Importing a Class from Another Catalog

This example imports class X from another catalog. Class Y is in the current catalog.

X.SCL
class work.cat.x;
  public num n;
endclass;

Y.SCL
import work.cat2;
class y;
  m: method o: x;
    o.n=99;
  endmethod;
endclass;

Z.SCL
init:
  import work.cat2;
  dcl y yobj=_new_ y();
  dcl x xobj=_new_ x();
  yobj.m(xobj);
  put xobj.n=;
return;

This example should produce the following output:

xobj.n=99


See Also

DECLARE

SEARCH

Previous Page | Next Page | Top of Page