You are on page 1of 37

IT Wise Solutions

www.itwisesolutions.com

Application Packages
Wrapped Neatly in a Bow
www.itwisesolutions.com
Agenda
What are Application Packages and
Classes?
Why would I want to use App
Packages/Classes?
When would I use App
Packages/Classes?
General Structure of an App Class
Exception Handling (try/catch)
App Packages/Classes and App
Messaging in 8.48
www.itwisesolutions.com
What are Application
Packages/Classes?
Its just PeopleCode
Application Packages contain
Application Classes
You can create your own classes or
extend the functionality of the
existing PeopleCode classes
A subclass can inherit all the
properties and methods of the class
it extends.
www.itwisesolutions.com
Why would I want to use
Application Packages/Classes?
Provide all the advantages of true
object-oriented programming:
easier to debug because all the pieces
are separate
easier to maintain because functionality
is gathered into a single place
extensible by subclass
Provide more structure
Because the Tools team says
its a good idea!
www.itwisesolutions.com
When would I use an
Application Package/Classes?
To structure your existing
PeopleCode functions to make them
easier to debug and maintain.

www.itwisesolutions.com
When would I use an
Application Package/Classes?
For example, consider this FUNCLIB
record

Its full of functions, but where do I


find the one I want?
www.itwisesolutions.com
When would I use an
Application Package/Classes?
compared to this Application Class

The structure of the Application


Package makes it easier to group
similar functions.
www.itwisesolutions.com
When would I use an
Application Package/Classes?
To structure your existing
PeopleCode functions to make them
easier to debug and maintain.
To extend the functionality of an
existing PeopleCode class or a
custom class.

www.itwisesolutions.com
When would I use an
Application Package/Classes?
For example, a custom Person class
could have these properties:
Name
City
State

www.itwisesolutions.com
Person class

class Person
method getBioDemo(&sEMPLID As string) Returns
boolean;
property string Name;
property string City;
property string State;
end-class;

www.itwisesolutions.com
Person class getBioDemo method
method getBioDemo
/+ &sEMPLID as String +/ Created automatically dont mess
/+ Returns Boolean +/ with these statements!
Local boolean &bReturn;
Local string &sName, &sCity, &sState;
SQLExec("SELECT NAME_DISPLAY, CITY, STATE FROM PS_PERSONAL_DATA where
EMPLID = :1", &sEMPLID, &sName, &sCity, &sState);
&Name = &sName;
&City = &sCity;
&State = &sState;
If All(&sName) Or All(&sCity) Or All(&sState) Then
&bReturn = True;
Else
&bReturn = False;
End-If;
Return &bReturn;
end-method; www.itwisesolutions.com
PeopleCode using Person class
import GBUT_PEOPLE:Person;

Local GBUT_PEOPLE:Person &personBioDemo;

&sEMPLID = GBUT_TEST_WRK.EMPLID.Value;
&personBioDemo = create GBUT_PEOPLE:Person();

If &personBioDemo.getBioDemo(&sEMPLID) Then
MessageBox(0, "", 0, 0, &personBioDemo.Name | " lives in " |
&personBioDemo.City | ", " | &personBioDemo.State);
Else
MessageBox(0, "", 0, 0, "No Bio Demo Data Found");
End-If;

www.itwisesolutions.com
Employee subclass extends
Person class
An Employee would have the same
properties as a Person along with
additional attributes like Job Title.
By making Employee a subclass of
Person, the Employee class has
access to the properties/methods of
Person as well as any additional
properties/methods defined for
Employee.
www.itwisesolutions.com
Employee subclass

class Employee extends GBUT_PEOPLE:Person


method getJobData(&sEMPLID As string) Returns
boolean;
property string JobTitle;
end-class;

www.itwisesolutions.com
Employee subclass getJobData
method
method getJobData
/+ &sEMPLID as String +/ Created automatically dont mess
/+ Returns Boolean +/ with these statements!
Local boolean &bReturn;
If %This.getBioDemo(&sEMPLID) Then This method is in class Person
SQLExec("Select b.DESCR from PS_JOB a, PS_JOBCODE_TBL b where a.EMPLID = :1 and a.effdt =
(select max(a_ed.effdt) from ps_job a_ed where a.emplid = a_ed.emplid and a.empl_rcd = a_ed.
empl_rcd) and b.jobcode = a.jobcode", &sEMPLID, &sJobTitle);
If All(&sJobTitle) Then
&JobTitle = &sJobTitle;
&bReturn = True;
Else
&bReturn = False;
End-If;
Else
&bReturn = False;
End-If;
Return &bReturn;
www.itwisesolutions.com
end-method;
PeopleCode using Employee
subclass
import GBUT_PEOPLE:Employee;

Local GBUT_PEOPLE:Employee &employeeData;

&sEMPLID = GBUT_TEST_WRK.EMPLID.Value;
&employeeData = create GBUT_PEOPLE:Employee();

If &employeeData.getJobData(&sEMPLID) Then
MessageBox(0, "", 0, 0, &employeeData.Name | ", " | &employeeData.
JobTitle | ", lives in " | &employeeData.City | ", " | &employeeData.
State);
Else
MessageBox(0, "", 0, 0, "Either no BioDemo data or no job title
found");
End-If;
www.itwisesolutions.com
General Structure of an
Application Class
Class name
Class extensions
Declaration of public external interface
Declaration of private instance variables
and methods
Declaration of protected instance variables
and methods
Definition of methods
Constructors
External function declarations

www.itwisesolutions.com
Class name
A fully qualified name that is formed
hierarchically by the name of the top-
level package that contains them, the
package that contains that package
and so on.
Must be unique within the App
package.

class Employee extends GBUT_PEOPLE:Person


method getJobData(&sEMPLID As string) Returns boolean;
property string JobTitle;
www.itwisesolutions.com
end-class;
Class name Example
Application Packages

Application Classes

Class names
CRM:Address
CRM:Customer
CRM:Utilities:Address
CRM:Utilities:Incident
www.itwisesolutions.com
Class extension
Represents the is a relationship.
Inherits all the public methods and
properties of the class it extends.
Before you can extend a class, you
must import it.

import GBUT_PEOPLE:Person;

class Employee extends GBUT_PEOPLE:Person


method getJobData(&sEMPLID As string) Returns boolean;
property string JobTitle;
end-class; www.itwisesolutions.com
Declaration of public external
interface
Specifies the methods and properties
that the class provides to other
PeopleCode programs.
class Employee extends GBUT_PEOPLE:Person
method getJobData(&sEMPLID As string) Returns boolean;
property string JobTitle;
end-class;

www.itwisesolutions.com
Declaration of private instance
variables and methods
The private part of a class
declaration gives the declaration of
any private methods, instance
variable, and private class constants.
Private methods or instance variables
cannot be overridden by subclasses
because they are completely private
to the declaring class.

www.itwisesolutions.com
Declaration of private instance
variables and methods
class Emailer
method Emailer(&bDebug As boolean);
method addAttachment(&sFile As string, &sTitle As string);
method send() Returns boolean;
Public
property string TU;
property string CC;
property string BC;
property string Subject;
property string Body; P
r
private i
method getUserEMail(&sOPRID As string) Returns string; v
method getRoleEMail(&sROLENAME As string) Returns string; a
method errorThrower(&nMsgSetNum As number, &nMsgNum As number, t
&aSubstitution As array of string); These methods are not e
method isValid() Returns boolean; available to programs
outside class Emailer.
www.itwisesolutions.com
instance boolean &bInError;
instance string &currentMethod;
Declaration of protected
instance variables and methods
Fall between public and private.
Can be accessed only by objects of
this application class and those
derived from this application class.
Use protected methods and
properties when you want to hide
them from outside use, but allow the
flexibility of using them in derived
classes.
www.itwisesolutions.com
Declaration of private instance
variables and methods
class A;
method A(); Public P
r
property string Q; o
protected t
e
method MP() Returns string; c
t
property string P; e
end-class; d

method MP() is available only


to class A and its subclasses
Class b extends A; (like Class b).
method B(); www.itwisesolutions.com
property string X;
Definition of methods
Come after the definition of any
global or component variables and
external functions needed by the
method

Passing parameters
By value
method increment (&val as number, &text as string);
By reference
method increment (&val as number out, &text as string);

www.itwisesolutions.com
Constructors
A constructor is a public method with the
same name as the class.
A class that does not extend some other
class does not need any constructor.
Instantiate new objects of an app class by
using the Create function. The function
takes the name of the class and any
parameters needed for the constructor
method.
&employeeData = create GBUT_PEOPLE:Employee();

www.itwisesolutions.com
External function declarations
Declare Function xyz PeopleCode FUNCLIB_MISC.
MISC_FUNCTIONS FieldFormula;

Allowed in application classes


In the global and component variable
declarations
After the class declaration (after the
end-class statement)
Before the method definitions

www.itwisesolutions.com
Other AppClass Concepts
that we arent going into today
Abstract Methods and Properties
Interfaces
Using Methods and Properties for
Collections
Downcasting

Please refer to PeopleBooks 8.48 >


PeopleCode API reference > Application
Classes for more information.
www.itwisesolutions.com
Exception Handling
An exception can be defined as any unusual
event that requires special handling in your
PeopleCode program.
For example, dividing by zero, referencing a
method or property that doesn't exist, or trying to
use a method or property on a null object are all
exceptions that should be handled.
Exception handling is the processing you initiate
when an exception occurs. You can handle errors
in PeopleCode using the catch statement. The
places in your code where you want exceptions
handled must be enclosed by the try and end-try
statements.
www.itwisesolutions.com
Exception Handling
The process of exception handling
can be broken down as follows:
An error occurs (either a hardware or
software error).
The error is detected and an exception
is thrown (either by the system or by
your program).
Your exception handler provides the
response.

www.itwisesolutions.com
Exception Handling
try
SQLExec(&sCurrentDDL);
catch Exception &cl
%This.Result = "Error";
%This.errorThrower(20101, 13, Split(%This.Name | "." |
%This.currentMethod, ";" | %This.TableName | ";"));
If &bInDebug Then
&fLogFile = GetFile(&sLogFileName, "A",
%FilePath_Absolute);
&fLogFile.WriteLine(%Datetime | " | " | %This.Name |
"." | %This.currentMethod | " Error during
doAlter");
&fLogFile.Close();
End-If; www.itwisesolutions.com
Return False;
Exception Handling
An exception to exception handling:
Using functions that transfer the end
user to a new component, such as
the DoModal, DoModalComponent, or
Transfer functions (in some cases)
inside a try block do not catch
PeopleCode exceptions thrown in the
new component.
Catches are only caught for
exceptions thrown
www.itwisesolutions.com
within the current
component.
AppClasses and the
LS 8.9 Upgrade
Application Messaging changes in the
8.48 version of PeopleTools
A Node is still a Node and a Message is
still a Message, but
Message channels become Queues
New objects: Services and Service
Operations
Node Transactions (Routing tab in
8.21) become Routings
Message Subscriptions become
Application Classes and Service
Operation Handlers
www.itwisesolutions.com
AppClasses and the
LS 8.9 Upgrade

www.itwisesolutions.com
AppClasses and the
LS 8.9 Upgrade

www.itwisesolutions.com
The End

www.itwisesolutions.com

You might also like