Before you can use a class name in a PeopleCode program (either a class definition program or an ordinary PeopleCode program), you must first import it using an import statement at the beginning of your program.
An import statement names either all the classes in a package or one particular application class.
If you're importing all the classes in a package, the syntax for the import statement ends with the following:
This makes all the application classes directly contained in the named package available. Application classes contained in subpackages of the named package are not made available.
If you're importing one particular application class, the syntax of the import statement ends with the short name of the class. Only that class is made available.
For example, the following imports all the classes of the package named Fruit:
The following imports only the application classes Banana and Kiwi. If the package named Fruit contains other classes, those are not made available to the PeopleCode program:
If you had a subpackage in Fruit named Drinks, you could access all the classes in that subpackage like this:
A PeopleCode program (either a separate program or one contained within a class definition) can use only application class names that have been imported. However, a class definition can use its own name without having to import it.
It's possible to import two packages which contain application classes with the same short name. For example, suppose my package Fruit contained classes Apple and Banana. Suppose a second package, Drinks, contained Apple and Cherry.
You could refer to the Banana and Cherry classes using just the short name of the class. However, you couldn't refer to the Apple class by the short name. You must always use the full name reference (that is, the name of the package and the name of the class) when referring to Apple.
Global Banana &MyBanana;
Local Cherry &CherryTree;
Component Fruit:Apple &GreenApple;
The following line produces an error, because the program doesn't know which Apple class you're referring to:
Component Apple &GreenApple;
Note: Single class imports (such as, Import Fruit:Banana) are checked for existence when you save your PeopleCode.