Before you can use any object you must instantiate it first. This means that you must create the memory for object. See the Wikipedia for more information.
The instantiation applies to both regular PeopleTools objects and custom Application Packages. Here is an exploration or documentation of how you would do it.
Regular PeopleTools Objects
While you can create your own objects with Application Packages, let’s focus on the API objects from PeopleSoft first.
- “Get” Built-in function
- “Create” Built-in function
- “Get” method to get an object from another object
The Get function is unique for each type of object, but the concept is basically the same. Bascially, the object already exists somewhere in memory, you just want your variable to point to that object. For example, when you page loads, it creates rowsets, rows, records, and fields. If you want a record object that was loaded by the component processor, you would use the GetRecord function.
Here are some other functions that fall in the same category:
The Create function, like the Get function, is unique for each type of object as well. It is designed to instantiate standalone objects that do not already exist.
For example, if you want a record that is in the component buffer (it is on a page), you would use the GetRecord() method. But, if you want to create a standalone record that you might use to update the database (with the update() or insert() methods), you would use the CreateRecord() method.
Here are some functions that fall in this category:
Get Method of other objects
Like the first Get functions we talked about, the get methods access objects that already exist in memory somewhere. More specifically, they exist “inside” another object that we already have access to. The Get method retrieves that object.
For example, a RowSet contains a group of rows. Assuming an &rs variable is a RowSet, we can use the &rs.GetRow() method to access one of the rows in that RowSet.
Here are some other examples:
- RowSet — GetRow() method
- Row — GetRecord() method
- Record — GetField() method
Applications Classes are custom objects defined in PeopleCode. They are defined as part of the Application Packages definition, which means that you can view or create them with the File, Open or File, New operations. Let’s leave them at that for this article.
Before you can use or instantiate an Application Class, you must “import” it. This simply means that you have to tell PeopleTools where the actual class is defined. This includes the Application Package and the structure inside the package. The different levels of the structure are separated with colons (:). For example, an import might look like this:
This import gives our program access to the “Employee” class. PeopleTools would find the class in the “MY_CLASSES” Application Package definition, and once open, the class is under the WorkforceAdmin level.
Custom classes do not exist anywhere like built-in classes do. They are not used in the buffer or any other place where you could use a “Get” method to access it. So, at some point all Application Classes must be instantiated with the “Create” keyword. For example, our previous example would look like this:
&employee = Create MY_CLASSES:WorkforceAdmin:Employee();
The PeopleCode editor will allow you to type only the class name assuming you have imported the class. When you save the program, the editor will supply the complete path to the class. So, you could type this:
&employee = Create Employee();
Some classes have a constructor method, which is just a method that PeopleCode automatically calls when it creates the class. This method is defined in the class with the same name as the class and no return value.
Sometimes the constructors have parameters. If it does, you will have to supply the parameter in your create statement. Say, for example, that our Employee class requires an employee id. The code might look like this:
&employee = Create Employee(“111000″);
When ever you use an object variable always remember to instantiate it before you begin to use the methods and properties of that object. Make it a mental habit to decide first where and how you will instantiate your objects.
Hopefully, this helps someone. Please let me know if this is helpful, and if more information on object-oriented programming would help any other PeopleSoft developers.