Вы находитесь на странице: 1из 50

PeopleCode - Overview

Introduction
What is PeopleCode?
PeopleSofts own Proprietary language
Used to incorporate sophisticated business rules into PeopleSoft applications Gives the capability to enhance applications beyond the capability of the PeopleTools

Allows to create more complex validations and programs

Accessing PeopleCode
Prior to PeopleTools 8
Record Field Menu Item

PeopleTools 8
Record Field Page Component Menu Item (Pop-Up only) Component Interface Message and Message Channel Application Engine
3

Editing PeopleCode
PeopleCode supports the standard text editing features and functions such as Save, Undo, Cut, Paste, Find and Replace. No Need to Format PeopleCode Just be concerned about the correct Syntax Does not format anything within the Quotes Fieldnames are converted to Uppercase Variable match their First Occurrence PeopleCode is Case-Insensitive, except for quoted literals

Referencing Fields
Referring to a field by Assumes that ^
Fieldname Recordname. Fieldname

The field is on the current record definition


The field is on the current record definition The field is on different record definition

PeopleCode Statements
Statement can be a Declaration Assignment Program Construct (Such as a Warning Statement or a conditional loop) Subroutine calls And so on PeopleCode statements should end in a semicolon

PeopleCode Statements
Comments
Remark Comments; Or REM Comments; Or /* Comments */ Or /* Comments <* Inside nest *> Comments */

Assignments
Addition Subtraction Unary Negation Multiplication Division Exponentiation String Concatenation + * / ** | PRICE + TAX GROSS - TAX -10 PRICE * QUANTITY ANNUAL_PAYMENTS / 12 DIMENSION ** 3 CITY | ,| STATE

PeopleCode Statements
IF statement
If condition then <PeopleCode Statements>; Else <PeopleCode Statements>; End-if; You can have Nested IF statements Relational Operators
= != , <> > , >= < , <= Equal To Not Equal To Greater than , Greater than or Equal to Less than , Less Than or Equal to

Relational Operators
NOT AND OR

PeopleCode Statements
ERROR statement
Error (<message>);

WARNING statement
Warning (<message>);

EVALUATE statement
Evaluate <field or &variable> When = <Value1> <PeopleCode statements>; -------------------------------When-Other <PeopleCode statements>; End-Evaluate

BREAK statement
Break;

PeopleCode Statements
For Loop
For <&variable> = <Start-Value> to <End-Value> [step <stepvalue>] statement; statement; End-For;

While Loop
While <condition> statement; statement; End-While;

Repeat-Until Loop
Repeat statement; statement; Until <condition>;

10

Component Processor
Controls how PeopleSoft manages applications from Initial data retrieval through updating the database Throughout the process, Component Processor applies PeopleCode at different time PeopleCode events fire at particular times and in particular sequence during flow of execution Whenever you code PeopleCode to enforce a business rule, you will need to know three things
WHEN you want the PeopleCode to execute WHERE to place the PeopleCode WHAT PeopleCode syntax to use
11

Component Processor
General Areas where the Component Processor Performs PeopleCode
During the Search Process Before the displaying the Page After a field Changes After inserting and deleting a row After page is saved After processing pop-menus

Search Events
SearchInit fires before the search dialog box appears to initialize fields or apply defaults to search After entering appropriate search values and Search push button is clicked, SearchSave PeopleCode will perform. It is used to either force a user to enter a value into the dialog, restrict the ranges of codes that can be added, or edit the valued entered Both the Search PeopleCode event will perform if the PeopleCode is attached to the search records to fields that appear in the dialog (Search Keys and Alternate Search Keys)

Page Startup Events

Before displaying the Component to a User, seven PeopleCode events are invoked RowSelect, PreBuild, FieldDefault, FieldFormula, RowInit, PostBuild and Activate. If User changes an action, The component processor displays the page again, the Component Processor performs FieldDefault, FieldFormula, and RowInit PeopleCode, if appropriate. PreBuild and PostBuild are executed only once when Component is built. Activate fires only when the user selects the page.

12

Component Processor
Field Action Events
FieldEdit and FieldChange are activated when the value of a field is changed FieldEdit validates the new value. FieldChange does the processing based on the new (and valid) value of the field

Row Action Events


RowInsert is performed after inserting a new row of data. When a row insert is performed, the component processor will also perform RowInit on just the one new row as part of displaying the page. RowDelete PeopleCode is performed after deleting a row of data.

Save Action Events


One the User presses the Save button, it tells the Component processor to take the information that has changed in its buffers and update it to the database. Before it updates the database, it goes through three PeopleCode events: SaveEdit, SavePreChange and Workflow. SaveEdit performs consistency, or relational, edits among multiple fields on a record definition and can also edit multiple rows of data in the buffer. SavePreChange does last minute processing just before the Component processor updates the database Workflow PeopleCode triggers a Business Event SavePostChange happens after the Component Processor isses the appropriate SQL command to update the database. SavePostChange mainly updates other tables. After SavePostChange successfully executes, an SQL Commit command will be performed on the database

13

Component Processor
Pop-Up Menu Events
PrePopup event fires before the pop-up menu is displayed. This allows a PeopleCode program to conditionally alter the appearance of one or more menu items. For instance, a menu can be disabled (grayed out) or hidden temporarily. If the user selects a menu item from the Pop-up list that has a PeopleCode program attached to it, then the ItemSelected event will fire.

Add Action
Add Processing is handled quite a bit differently by the Component Processor. For rows added with a new search (high-level) key, a flow of RowInit, SearchInit, FieldEdit, FieldChange, SaveEdit, and then finally SearchSave is processed prior to User receiving the GUI.

Deferred Processing
In PIA architecture all the component buffers are on the Application Server and all the PeopleCode is executed on the Application Server. This can result in a performance impact when there is a lot of field action processing that is FieldEdit and FieldChange peoplecode, along with standard system field edits. Mitigating the Performance Impact No automatic trip back to server. In other words, if a field is changed and there is no FieldEdit or FieldChange PeopleCode on the field, record defaults and FieldDefault PeopleCode will not be run until some other action causes the trip to the server Developers are encouraged to put FieldEdit validations in SaveEdit to save trips to server Developers have the option of enabling the deferred processing, which will will automatically defer standard fields edits, FieldEdit and FieldChange events.

14

PeopleCode Events
SearchInit (SrI) PeopleCode
Performs before the search record dialog box displays. Controls processing before a user enters values in the search key and alternate search keys Only performs only if the search record with search keys and alternate search key is associated with the peoplecode
PSUSERSELF_SRCH.OPRID = %OperatorId; SetSearchDialogBehaviour(0);

SearchSave (SrS) PeopleCode


Performs after the User clicks OK in the search dialog box Provides a way to edit information entered in the search record dialog box Also used to force the user to input atleast one field into the dialog box
If Not RecordChanged(STUDENT_TBL.STUDENT_ID) And %Mode <> A then Error (You must enter at least one search value); End-If;

RowSelect (RSe) PeopleCode


Performs as the Component Buffer reads data into the component RowSelect can prevent the component processor from loading specific rows of data into the component
If COUNRSE_TBL.COURSE_TYPE = DISC then /* Discontinued */ DiscardRow(); End-If;

15

PeopleCode Events
PreBuild PeopleCode
Component PeopleCode event Fires before the rest of the component build events Often used to hide or unhide pages Also used to set global or component scope variables that can be used later by PeopleCode located in other events
If %Mode <> A Then
Hide(field.ADD_MODE_IND);

End-If;

FieldDefault (FDe) PeopleCode


Once the Component Processor fills the component, it attempts to set defaults for fields without a value. If a record default is specified for the blank field, the default value is applied. FieldDefault is applied only when field to which it is attached has not value. Once the field has a value, the Component processor ignores the program.
If None(STUDENT_TBL.STUDENT_ID) Then STUDENT_TBL.STUDENT_ID = NEW; End-If;

FieldFormula (FFo) PeopleCode


Once FieldDefault completes successfully, the Component Processor performs FieldFormula PeopleCode Mainly used on the record definitions for PeopleCode function libraries (FUNLIBs). These record definitions store common routines that can be called from other programs

16

PeopleCode Events
RowInit (Rin) PeopleCode
Performs the first time the component processor encounters a row of data. This occurs for every new row of data brought into the component after the buffer allocation process. It also occurs when a users performs a RowInsert, but just on the one new row of data.
If None(PS_STUDENT_TBL.STUDENT_ID) Then
Gray(PS_STUDENT_TBL.STUDENT_ID);

End-If;

PostBuild PeopleCode
Component PeopleCode event Used to Calculate values and set display characteristics of an object
If AMM_PUBLIST.NRID < 1 Then
GetPage(Page.AMM_RAWNRXML).Visible = False;

End-If;

Activate PeopleCode
Page PeopleCode event Fires each time a page is activated Page Processing, such as enabling a field or hiding a scroll
SetGridLables(%Panel, Record.AMM_CHNL_SECVW);

17

PeopleCode Events
FieldEdit (FEd) PeopleCode
Performed after a field has changed and a new value fo the field satisfies the standard system edits Used to validate the contents of the field Assignments statements should not be performed in FieldEdit
If PS_HDR.ORDER_STATUS <> IN Then Error Msgget(20000,1,Message not found); End-If;

FieldChange (FCh) PeopleCode


Performed after the FieldEdit has performed successfully Usually when a field has changed, other fields may need to be calculated again or change the display characteristics
If PS_HDR.ORDER_STATUS <> IN Then &PO_HDR.ORDER_STATUS.Enabled = False; End-If;

RowInsert PeopleCode
Performed when a new row is added Used to Override effective-dated processing, or to auto number new rows of data

18

PeopleCode Events
RowDelete (RDe) PeopleCode
Performed when a new row is deleted Used to caculate running totals or prevent a row from being deleted After the RowDelete finishes, the Component processor performs FieldDefault and FieldFormula peopleCode.
If PS_HDR.ORDER_STATUS <> IN Then Error Msgget(20000,1,Message not found); End-If;

FieldChange (FCh) PeopleCode


Performed after the FieldEdit has performed successfully Usually when a field has changed, other fields may need to be calculated again or change the display characteristics
If PS_HDR.ORDER_STATUS <> IN Then &PO_HDR.ORDER_STATUS.Enabled = False; End-If;

RowInsert PeopleCode
Performed when a new row is added Used to Override effective-dated processing, or to auto number new rows of data

19

PeopleCode Events
SaveEdit (SEd) PeopleCode
Performed when tries to save the component Used to validate data before it is updated to the database SaveEdit makes sure that all the changes have been made before the validation takes place

SavePreChange (SPr) PeopleCode


Performed after the SaveEdit has performed successfully Provides last chance to manipulate data before the database is updated
Declare Function assign_student_id PeopleCode FUNCLIB_PSU.STUDENT_ID FieldFormula; If PSU_STUDENT_TBL.STUDENT_ID = NeW then assign_student_id(PSU_STUDENT_TBL.STUDENT_ID); End-If;

Workflow (Wrk) PeopleCode


Segregates the PeopleCode related to workflow from rest of applications peoplecode All Workflow peoplecode programs must include atleast one use of TriggerBusinessEvent() or Virtual_Router() Funclib function, which uses the TriggerBusinessEvent() function internally

SavePostChange (SPo) PeopleCode


Performed after the SavePreChange has successfully completed and CP has update the database Used to update the data outside the component buffer, but still in the same database

20

PeopleCode Variables
User-defined variables are required for temporarily holding the data in PeopleCode All variable names must begin with & and can be maximum in 18 characters in length, including the ampersand. Fields from Derived/Work Records add more flexibility to the system as they can be placed on the pages

21

PeopleCode Variables
Variable Type
Local

Duration (Scope)
Program

Purpose
Passes values within a single program Passes values between all program within a component Passes values between all components for a user session Hold values for reference from any code Display values on a page and passes values between all programs with a single component

Disadvantage
Cannot display on a page

Component

Component

Cannot display on a page

Global

PeopleSoft Session

Too Numerous to mention

System

Application Installation

Derived/Work Fields

Component

Cannot write to database

22

PeopleCode Variables
LOCAL COMPONENT GLOBAL <type> &VarName; <type> &VarName; <type> &VarName;

<type> = Number String Boolean Date Time Datetime Object Any Float Integer

System Variables
%Date %Time %UserId %Mode %Page
23

Object Oriented Programming


PeopleSoft delivers classes of objects that one can manipulate with PeopleCode CLASS is an formal definition of an object and acts as a template from which an instance of an object is created at runtime. This class defines the properties of the object and the methods used the control the objects behaviour. Eg, Array, File, Field, SQL and so on OBJECT represents a unique instance of a data structure defined by the template provided by its class. Each object has its own values for the variables belonging to its class and responds to methods defined by that class. METHOD is a procedure or routine, associated with one or more classes, that acts on an object.

24

Object Oriented Programming


INSTANTIATING OBJECTS
Usually Instantiated (created from their class) using built in functions or methods of other objects Some objects are instantiated by the data already present in the buffer Some objects are instantiated from an already created definition like a Component Interface

Eg: following creates a field object that references an employees name Local Field &Field; /* Declare */ &Field = GetField(STUDENT_DATA.STUDENT_NAME); /* Instantiate */ Eg: following returns a record object for a record already in the page buffer Local Record &REC1, &REC2; /* Declare */ &REC1 = GetRecord(); /* Instantiate */ &REC2 = CreateRecord(RECORD.COURSE_TBL); /* Instantiate */

25

Object Oriented Programming


OBJECT PROPERTIES
To set or get characteristics of an object, or to determine the state of an object, the properties of the object need to be accessed using the DOT NOTATION syntax Object.Property Eg: = Value; (i) &Field.Visible = False; (ii) &x = &Field.Value; (iii) If &Rowset.ActiveRowCount <> &I Some of the properties of Field Class are as follows, Visible Value Name Label IsYesNo IsKey Enabled EditError
26

Object Oriented Programming


OBJECT METHODS
In order to execute a method, the reference to an object is followed by the DOT NOTATION (period) and then the method name. Methods are easily identified by parentheses appearing after the method name. Object.Method(); Eg: (i) If &REC1.GetField(&R).Name = NEW then (ii) If &REC1.CompareFields(&REC2) then (iii) If &ROW = &ROWSET.GetCurrRow(); Some of the methods of Field Class are as follows, GetShortLabel(LabelId) GetLongLabel(LabelId) SetCursorPos(PAGE.Pagename) SetDefault(RECNAME.Fieldname)

27

Object Oriented Programming


PASSING OBJECTS
All PeopleCode objects can be passed as function parameters, thus enabling the application developer to pass complete data structures between peoplecode functions
Rowset Record &ROWSET; &RECORD; Local Local

Function Process_Rowset(&ROWSET as Rowset) For &I = 1 to &ROWSET.RowCount For &J = 1 to &ROWSET.RecordCount &RECORD = &ROWSET.GetRow(&I).GetRecord(&J); [do stuff to the data here] &RECORD.Update(); End-For; End-For; End-Function;

&ROWSET = GetLevel0(); Process_Rowset(&ROWSET);

28

PeopleCode Functions
CATEGORIES OF FUNCTIONS
Internal-PeopleCode: A PeopleCode routine that is stored in the same program where it is used. Defined by a Function statement. External-PeopleCode A PeopleCode routine that is stored in a different program from where it is used. Defined by a declare statement with the keyword PeopleCode External-Non-PeopleCode A common C++ (or other language routine that is loaded from DLL. Defined by a Declare statement with the keyword library.

FUNCTION STATEMENT
Function <function-name> (<parm1>,<parm2>,) statement; statement; End-Function;

29

PeopleCode Functions
DECLARING A FUNCTION
Declare Function <Function-Name> PeopleCode <RecordName.FieldName> FieldEvent;

CALLING A FUNCTION
PeopleCode Functions are called using the name of the function and passing the correct number of parameters in paratheses. The number of parameters need to match the parameters used by the function
Declare Function assign_student_id PeopleCode FUNCLIB.STUDENT_ID FieldFormula; if PSU_STUDENT_TBL.STUDENT_ID = NEW then assign_student_id(PSU_STUDENT_TBL.STUDENT_ID); end-if;

RETURNS STATEMENT
Function <Function-name> (<parm1>,) returns <type> Returns <Expression>;
30

PeopleCode Functions
BUILT-IN FUNCTION Page Buffer Functions: Modify fields, values & variables within the buffers Scroll Buffer Functions: Manipulate scroll area records for various purposes Logical Functions: Check if values exist for a field Date & Time Funcs: Used to easily calculate & manipulate dates String Functions: With with character strings Double-Byte Char Funcs: Supports the languages that utilise double-byte chars Number functions: Work with numeric values DOS functions: Control DOS processes API functions: Include WinExec WorkFlow, RemoteCall etc

31

PeopleCode Functions
MESSAGE CATALOG FUNCTION MsgGet MsgGet (<MessageSet>, <MessageNum>,DefaultMsgTxt[,<Bind1>,]) MsgGetText MsgGetText(<MessageSet>, <MessageNum>,DefaultMsgTxt[,<Bind1>,])

32

PeopleCode Functions
Gray/Ungray and Hide/Unhide FUNCTION Procedural Method Gray(<recordname.fieldname>); UnGray(<recordname.fieldname>); Object Based Method <Recordname.fieldname>.Enabled = False; <Recordname.fieldname>.Enabled = True; IsChanged, IsNew, IsDeleted FUNCTION

&Field.IsChanged &Record.IsNew &Row.IsDeleted


33

PeopleCode Functions
Other Important Functions FUNCTION PriorValue RTrim, Ltrim, Substring OriginalValue SetCursorPos Method

Local Field &Qty; &Qty = GetField(PSU_PO_DTL.QTY); If All(&Qty.OriginalValue) then &Orig_Qty = &Qty.OriginalValue; if &Qty.value > &Orig_Qty then Error MsgGet(20000,30,Message Not Found); End-If; End-If;
34

Accessing Buffer
ActiveRowCount <RowSetName>.ActiveRowCount TotalRowCount <RowSetName>.TotalRowCount Value,FetchValue and UpdateValue <RowNumber>.<RecordName.Fieldname>.value /* Object Based */ FetchValue(<RecordName.Fieldname>,<RowNumber>) /* Procedural */ UpdateValue(<RecordName.Fieldname>,<RowNumber>) /* Procedural */

DATA Buffer Classes Rowset Data structure used to describe a hierarchical data Row single row of data in a component scroll Record single instance of data within a row Field single instance of data within a recordw
35

Accessing Buffer
&RowSet = GetLevel0(); &RowSet = GetRowSet(Scroll.RecordName); &RowSet = &Row.GetRowSet(Scroll.RecordName); &Row = &RowSet.GetRow(n); &Record = &Row.GetRecord(RECORD.RecordName); &Field = &Record.GetField(FIELD.Fieldname);

36

Traversing Buffer
TRAVERSING = ROWSET > ROW > RECORD > FIELD
Declare the data buffer objects Local Rowset &RS0, &RS1; Local Row &Row0, &Row1; Local Record &Rec1; Local Field &Field1; &RS0 = GetLevel0(); &Row0 = &RS0.GetRow(1); OR &Row0 = &RS0(1); /* Level0 and level1 rowsets */ /* single row at level0 and level1 */ /* record */ /* field */

&RS1 = &Row0.GetRowSet(Scroll.Level1-Record); &Row1 = &RS1.GetRow(1) OR &Row1 = &RS1(1);

&Rec1 = &Row1.GetRecord(Record.Recordname); OR &Rec1 = &Row1.Recordname; &Field1 = &Rec1.FieldName; Then you can use sa &Field1.Enabled = False;

37

38

39

40

41

42

43

44

45

46

47

48

49

PeopleCode Variables

50

Вам также может понравиться