You are on page 1of 6

Application Class Basics

What is an Application Package?
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.

What is an 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.

Basic Illustration
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.

0. "My Result is: " | &c). Messagebox (0.Create a Function Local number &c. "". &b As number) Returns number. Create an Application Class • • • Create a new application package with the name MY_TEST. Add a new class in the application package called MyFormulaCruncher. /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ */ */ */ */ /* 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 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! . /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ */ */ /* Here is the method that will perform the addition of &a and &b /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! method AddNumbers(&a As number. Return &c. Add the following code to the application class: class MyFormulaCruncher /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* The following line is known as the constructor. &b As number) Returns number /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* Add numbers &a and &b together */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ &c = &a + &b. The method will */ /* have the same name as the application class name. */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ method MyFormulaCruncher(). End-Function. Function AddNumbers(&a As number. 0.

method AddNumbers2(). method MyFormulaCruncher /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* You do not need to do any initial setup . /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ */ */ */ /* Since this is readonly. end-class. You are not able to call protected methods or /* properties outside of the class MyFormulaCruncher since they are /* invisible/hidden */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ protected property number MySumProtected. method AddNumbers /+ &a as Number. if you try to set this value you will get a /* compile error /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! property number MySum readonly. */ */ */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! /* Allow a property to be read and write by not setting to readonly /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! property number FirstNumber. /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ */ */ */ */ /* 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. +/ /+ &b as Number +/ /+ Returns Number +/ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* Do not alter or create your own lines that start with /+ */ . property number SecondNumber.nothing to do */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ end-method.

*/ */ */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! /* property &MySumProtected is available with in this app class /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MessageBox(0. 0. 1). "". &c = &a + &b. end-method. "My AddNumbers result is: " | &c). end-method. "".MY_FIELD FieldFormula. "My AddNumbers2 result is: " | &MySumProtected). /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* Now call the function and provide the two parameters */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ &MyResult = AddNumbers(2. 0. MessageBox(0.*/ */ */ */ /* 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. Local number &MyResult. 0. . method AddNumbers2 &MySum = &FirstNumber + &SecondNumber. Return &c. &MySumProtected = &FirstNumber + &SecondNumber. Call the Function /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* Declare the function at the beginning of the event */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ Declare Function AddNumbers PeopleCode MY_TEST_WRK. 0.

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* Call the Application Class using the first method that takes parameters */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ &Result = &My_Nbr.FirstNumber = 3. */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ Local MY_TEST:MyFormulaCruncher &My_Nbr = create MY_TEST:MyFormulaCruncher().Call the Application Class /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* In order to use an application class. or you can declare the variable as local and then */ /* set the variable prior to using any of its methods or properties. This can be done on one line */ /* as was done here.AddNumbers(2. /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* 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. Local number &Result. &My_Nbr. /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* Now you must declare an object variable to hold a reference to the */ /* application class.SecondNumber = 2. 1). You are giving a variable called &My_Nbr the */ /* object type of the application class and then creating (otherwise */ /* known as instantiating) the object. you must have an import statement */ /* at the top of your code. just like you must Declare a function */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ import MY_TEST:MyFormulaCruncher. /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* Call the Application Class using the second method that will not use */ .

/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* This method is also different than the other in that it is not returning */ /* a value. Instead.AddNumbers2()./* parameters.MySumProtected !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! . the method is setting another class property that can */ /* be read into a variable */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ &Result = &My_Nbr. but will use the two object properties */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ &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.