PeopleSoft Application Class Basics
What is a PeopleSoft Application Package?
The top most level of an Application in PeopleSoft is the Application Package. An Application Package is a container for one or more Application Classes. Application Packages should only contain Application Classes that are related to each other based on purpose or similar functionality.
What is a PeopleSoft Application Class?
An Application Class is equivalent to an object in Object Oriented Design. If you have never done OO programming think about this analogy. An object tries to represent a possible real world object in an abstract way. You wouldn’t build a house without first creating a blueprint of where everything would go. An architect might in fact have several blue prints detailing where electrical will be placed and wires run. Conversely another blue print might show where piping will run. Keep in mind the blue print is NOT the house it is only a representation of the house an Application Class is similar. There are a few things that need to happen before we have a house:
- A house must be constructed(created/instantiated)
- The various systems and processes must happen in a particular order(i.e. you can’t have walls without a basement or foundation)
- The attributes of the house must be agreed upon (i.e. the color of walls, the type/color of flooring etc.).
An Application Class has everything necessary to build the object it represents.
In some respect a simple application class can appear on the surface to be similar to a function.
- A function declared in PeopleCode to prepare it to be used. An application class can “import” and then “create” a class to prepare it to be used.
- Then you run a function by calling it to do some work and passing some parameters. Application Classes you either pass parameters in a constructor or you set properties/attributes.
- Functions can return values once complete. Application classes can return values or change values of their properties.
Basic Example of PeopleCode Application Classes
Create a Function
1 2 3 4 5 6 7 8 9 | 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | class MyFormulaCruncher /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* The following line is known as the constructor. The method will */ /* have the same name as the application class name. */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ method MyFormulaCruncher(); /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* 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 MyFormulaCruncher since they are */ /* invisible/hidden */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ protected property number MySumProtected; end-class; method MyFormulaCruncher /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* 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
1 2 3 4 5 6 7 8 9 10 | /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* Declare the function at the beginning of the event */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ Declare Function AddNumbers PeopleCode MY_TEST_WRK.MY_FIELD FieldFormula; Local number &MyResult; /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* Now call the function and provide the two parameters */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ &MyResult = AddNumbers(2, 1); |
Call the Application Class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* 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_TEST:MyFormulaCruncher; /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* 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_TEST:MyFormulaCruncher &My_Nbr = create MY_TEST:MyFormulaCruncher(); 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 */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ |