PeopleSoft Application Package Basics


An application package contains one to many application classes and may contain another application package. An application package provides a storage container to place multiple application classes that should be grouped together due to purpose or similar functionality.

Application Class

An application class is a way to create an object in PeopleSoft. For developers that have not utilized object oriented programming in the past, a very rough analogy would be to compare it to a function.

A correct way of describing an application class would be an architect’s blueprint. The blueprint tells how to build a house and provides various drawings for the electrical, plumbing, outside elevations, etc. However, the blueprint is not the house.

§  The house must be built (created/instantiated).
§  The various events (methods) must occur such as pouring a cement foundation, stringing the electric cables, etc.
§  The properties of the house must be set such as the paint color in each room, the type and color of flooring, etc.

The application class possesses everything about the house – everything necessary for its construction and its appearance.

In some respects a simple application class can appear to be similar to a function:

1. You declare a function in PeopleCode to make it ready to be used. With an application class you “import” and then “create” the class to make it ready to be used.

2. You then call that function to do some work by passing parameters to the function. With an application class, you either pass in parameters, or you set object properties.

3. After the function is complete, work has been done, and has possibly returned a value. With an application class, work was performed by returning a value or by changing the value of one of its properties.

You will create a function and an application class to do the same thing in order to highlight the differences.

Add two numbers together and receive the sum.

Create a Function
Local number &c;
Function AddNumbers(&a As number, &b As number) Returns number
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   /* Add numbers &a and &b together                                          */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   &c = &a + &b;
   Messagebox (0, "", 0, 0, "My Result is: " | &c);
   Return &c;
End-Function;

Create an Application Class
§  Create a new application package with the name MY_FIRST_APPPACKAGE.
§  Add a new class in the application package called MyFirstClass.
§  Add the following code to the application class:

class MyFirstClass
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   /* The following line is known as the constructor. The method will         */
   /*    have the same name as the application class name.                    */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   method MyFirstClass();

   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   /* Here is the method that will perform the addition of &a and &b          */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   method AddNumbers(&a As number, &b As number) Returns number;

   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   /* Here is the method that will perform the addition by setting object     */
   /*    properties and read the property MySum to determine the result after */
   /*    the method finishes                                                  */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   method AddNumbers2();

   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   /* Allow a property to be read and write by not setting to readonly        */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   property number FirstNumber;
   property number SecondNumber;

   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   /* Since this is readonly, if you try to set this value you will get a     */
   /*    compile error                                                        */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   property number MySum readonly;

   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   /* All properties and methods that are listed after the key word           */
   /*    protected are only able to be used in this application class or a    */
   /*    derived class. You are not able to call protected methods or         */
   /*    properties outside of the class MyFirstClass since they are     */
   /*    invisible/hidden                                                     */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
protected
   property number MySumProtected;

end-class;

method MyFirstClass
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   /* You do not need to do any initial setup - nothing to do                 */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
end-method;

method AddNumbers
   /+ &a as Number, +/
   /+ &b as Number +/
   /+ Returns Number +/
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   /* Do not alter or create your own lines that start with /+                */
   /* These lines are special lines inserted by the application class         */
   /*    when the application class is saved and the method has parameters    */
   /*    defined in the class section                                         */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   Local number &c;

   &c = &a + &b;

   MessageBox(0, "", 0, 0, "My AddNumbers result is: " | &c);

   Return &c;

end-method;

method AddNumbers2
   &MySum = &FirstNumber + &SecondNumber;
   &MySumProtected = &FirstNumber + &SecondNumber;

   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   /* property &MySumProtected is available with in this app class            */
   /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
   MessageBox(0, "", 0, 0, "My AddNumbers2 result is: " | &MySumProtected);

end-method;

Call the Function
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Declare the function at the beginning of the event                         */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
Declare Function AddNumbers PeopleCode MY_FIRST_APPPACKAGE_WRK.MY_FIELD FieldFormula;
Local number &MyResult;

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Now call the function and provide the two parameters                       */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&MyResult = AddNumbers(2, 1);

Call the Application Class
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* In order to use an application class, you must have an import statement    */
/*    at the top of your code, just like you must Declare a function          */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
import MY_FIRST_APPPACKAGE:MyFirstClass;

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Now you must declare an object variable to hold a reference to the         */
/*    application class. You are giving a variable called &My_Nbr the         */
/*    object type of the application class and then creating (otherwise       */
/*    known as instantiating) the object. This can be done on one line        */
/*    as was done here, or you can declare the variable as local and then     */
/*    set the variable prior to using any of its methods or properties.       */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
Local MY_FIRST_APPPACKAGE:MyFirstClass &My_Nbr = create MY_FIRST_APPPACKAGE:MyFirstClass();
Local number &Result;

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Call the Application Class using the first method that takes parameters    */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&Result = &My_Nbr.AddNumbers(2, 1);

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* You must set the two properties used in the method prior to the calling    */
/*    the method call or the values will be defaulted to zero since they are  */
/*    numeric variables                                                       */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&My_Nbr.FirstNumber = 3;
&My_Nbr.SecondNumber = 2;

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Call the Application Class using the second method that will not use       */
/*    parameters, but will use the two object properties                      */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&My_Nbr.AddNumbers2();

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* This method is also different than the other in that it is not returning   */
/*    a value. Instead, the method is setting another class property that can */
/*    be read into a variable                                                 */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
&Result = &My_Nbr.MySum;

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
/* Attempting to use this property would result in a compile error since it   */
/*    is not accessible outside the application class                         */
/* &Result = &My_Nbr.MySumProtected                                           */
/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */