To use a SOM class in your program, you must first import it. There are two ways to import a SOM class. You can use a ::CLASS directive, or you can send IMPORT message to the SOM class.
To import a SOM class named Animal using a directive, specify the keyword EXTERNAL as follows:
::class beasts external 'SOM Animal'
The literal string following EXTERNAL indicates where we are to import the class from and the name of that class. In this case we are importing the Animal class from SOM. The name Beasts is given to the REXX class. You can use the same name (Animal) if you wish.
The second way to import a class is by sending a message to a REXX object in the global environment named SOM. The SOM object has an IMPORT method for importing classes:
beastclass = .som~import('animal')
The argument 'animal' tells the SOM object the name of the class to import from SOM. An object representing this SOM class is returned and assigned to Beastclass. The class name in REXX will be the same as the name of the SOM class.
In addition to importing regular SOM classes, you can also import DSOM classes. Importing DSOM classes is very similar to importing a SOM class. To import using directives, you use the ::CLASS directive and must specify DSOM instead of SOM after the EXTERNAL keyword. For example, suppose the Animal class described earlier is a DSOM class. In this case you would code:
::CLASS beasts EXTERNAL 'DSOM Animal'
For dynamic loading you must first initialize the DSOM environment in REXX. You do this by using:
.som~SOMD_INIT
This installs a new object into the local environment. This object is .DSOM. It functions the same as .SOM, but for DSOM rather than SOM classes. You can now import dynamically, using:
beastclass = .DSOM~import('Animal')