Anda di halaman 1dari 41

PeopleCode

PeopleCode - Proprietary scripting language used in the development of PeopleSoft applications. Closely integrated with objects that we create and modify in Application Designer.

4/14/2012

Areas Covered
People Code Language People Code Events

4/14/2012

PeopleCode Language
Data Types Comments and Statements Functions Expressions Operators

4/14/2012

Data Types

4/14/2012

ANY NUMBER STRING BOOLEAN DATE DATETIME TIME OBJECT (Ex: Field, Record, Page etc)

Comments
REM This is an example of commenting single line
PeopleCode; /* ----- Logic for Compensation Change ----- */ /* Recalculate compensation change for next row. Next row is based on prior value of EFFDT. */

4/14/2012

4/14/2012

Statements
Separators Assignment Statements Language Constructs Functions

4/14/2012

Separators
Statements are terminated with a semicolon(;). Extra spaces and line breaks are ignored (Removed by PeopleCode Editor while saving code)

4/14/2012

Variable Declaration stmts.


Variable declaration statements: Global, Component, Local
Ex: Global Number &Curr_Num; Component Record &Dept_Rec; Local String &First_Name_Str;

4/14/2012

Variables and Assignment Statements


field_or_var = expression; (= can be used both for assignment and comparison)
Variable names are preceded by an "&" character System variables are preceded by a percent (%) Eg. %DateTime, %DbName, %OperatorId, %PanelGroup
4/14/2012

Language Constructs
PeopleCode language constructs include: Branching structures: If and Evaluate. Loops and conditional loops: For, Repeat, and While. Break and Exit statements for escaping loops and terminating program execution. (Contd..)

4/14/2012

Language Constructs II
If condition Then [statement_list_1] [Else [statement_list_2]] End-if;

4/14/2012

Language Constructs III


Evaluate left_term When [relop_1] right_term_1 [statement_list] . . When [relop_n] right_term_n [statement_list] [When-other [statement_list]] End-evaluate;
To end the Evaluate after the execution of a When clause, you can add a Break statement at the end of the clause:
4/14/2012

Language Constructs III


evaluate &USE_FREQUENCY when = "never" PROD_USE_FREQ = 0; Break; when = "sometimes" PROD_USE_FREQ = 1; Break; when = "frequently" PROD_USE_FREQ = 2; Break; when-other Error "Unexpected value assigned." end-evaluate;
4/14/2012

Language Constructs IV
For count = expression1 to expression2 [Step i]; statement_list End-for;
Eg :&MAX = 10; for &COUNT = 1 to &MAX; WinMessage("Executing list, count = " | &COUNT); end-for;
4/14/2012

Language Constructs V
Repeat statement_list Until logical_expression;
Ex: Repeat x = y; y = y + 1; Until y > 10; The Repeat statement executes the statements in statement_list once, then evaluates logical_expression. If logical_expression is False the sequence of statements is repeated until logical_expression is True.
4/14/2012

Language Constructs VI
While logical_expression statement_list End-while;
Ex: While y < 10 x = y; y = y + 1; End-While; The While statement evaluates logical_expression before executing the statements in statement_list. It continues to repeat the sequence of statements until logical_expression evaluates to False.
4/14/2012

Functions
PeopleCode supports the following types of functions:

Built-in
Supplied along with PeopleSoft

Internal
Declared in PeopleCode with keyword Function

External PeopleCode
PeopleCode functions defined outside the calling program in record definitions.

External Non-PeopleCode
Functions stored in external (C-callable) libraries.
4/14/2012

Functions
Defining the function Function run_status_upd(&PROCESS_INSTANCE, &RUN_STATUS) returns boolean; &UPDATEOK = SQLExec("update PS_PRCS_RQST set run_status = :1 where process_instance = :2", &RUN_STATUS, &PROCESS_INSTANCE); If &UPDATEOK Then Return True; Else Return False; End-if; End-function; . Function Declaration declare function run_status_upd peoplecode FUNCLIB_MYUTILS.ZIP_EDITS FieldFormula;
4/14/2012

Functions
PeopleCode Function Syntax Declare Function function_name PeopleCode record_name.field_name event_type declare function verifyzip PeopleCode FUNCLIB_MYUTILS.ZIP_EDITS FieldFormula; External Function Syntax Declare Function function_name Library lib_name [ALIAS module_name ] [param_list] [RETURNS ext_return_type [As pc_type]] declare function pctest library "psuser.dll" (integer value as number) returns integer as number;
4/14/2012

PeopleCode Events and Objects


Every PeopleCode program is associated with an object and with an event. When an event fires on an object, it triggers any PeopleCode program associated with that object and that event. Each class of objects in Application Designer can have an event set. An object can have zero or one PeopleCode programs for each event in its event set.

4/14/2012

PeopleCode Events and Objects


PeopleCode is associated with many types of definitions, such:
Records Pages Components Messages

Menus

4/14/2012

PeopleCode Events
Record Field Component Record Field Component Record Component Page Menu

FieldChange FieldDefault FieldEdit FieldFormula PrePopup RowDelete RowInit RowInsert RowSelect SaveEdit SavePostChg SavePreChg SearchInit SearchSave Workflow
4/14/2012

FieldChange FieldDefault FieldEdit PrePopup

RowDelete RowInit RowInsert RowSelect SaveEdit SavePostChg SavePreChg SearchInit SearchSave

PostBuild PreBuild SavePostChg SavePreChg Workflow

Activate

ItemSelected

FieldDefault Event
Allows to programmatically set default values Fired on all page fields as part of many different processes; but triggers only when the following conditions are all true:
The page field is still blank after applying any default specified in the record field properties. (This will be true if there is no default specified, if a null value is specified, or if a 0 is specified for a numeric field.) The panel field has a FieldDefault PeopleCode program.

In practice, FieldDefault PeopleCode normally defaults fields when new data is being added to the page group; that is, in Add mode and when a new row is inserted into a scroll. Must attach FieldDefault PeopleCode to the specific field that is being defaulted.
4/14/2012

FieldEdit Event
Used to validate the contents of a field, - supplements standard system edits. Error, Warning and Message can be used If validation needs to check the contents of more than one fieldthat is, if the validation is checking for consistency across page fieldsthen SaveEdit PeopleCode need to be used instead of FieldEdit. The FieldEdit event fires on the specific field and row that just changed.

4/14/2012

FieldChange Event
Used to recalculate page field values. Fires on the specific field and row that just changed. Do not use Error or Warning statements in FieldChange PeopleCode Often paired with RowInit PeopleCode.

4/14/2012

FieldFormula Event
A vestige of early versions of PeopleTools Not used in recent applications Triggers PeopleCode on every field on every row in the page buffer De-grades Application performance Replaced by RowInit and FieldChange
4/14/2012

RowInit Event
Fires the first time the Application Processor encounters a row of data. Happens during page group build processing and row insert processing. RowInit is not field-specific: it triggers PeopleCode on all fields and on all rows in the panel buffer. Do not use Error or Warning statements

4/14/2012

RowSelect Event
Fires at the beginning of the Page Group Build process in any of the Update action modes

4/14/2012

RowInsert Event
Application Processor generates a RowInsert event, whenever a row of data is added RowInit event always fires after the RowInsert event Do not repeat code both in RowInit and RowInsert Do not use a Warning or Error in RowInsert Row insertion can not be prevented conditionally can be prevented unconditionally by checking the no row insert check box in scroll bars panel field properties

4/14/2012

RowDelete Event
Fires whenever a row is deleted Can be used to prevent deletion of a row Can be used for other contingent processing

4/14/2012

PrePopup Event
Fires just before the display of a popup menu defined by a developer attached to a page field. Does not fire for System popup Menu or popup menu attached to panel background Used to control the appearance of the Popup menu.
4/14/2012

SaveEdit Event
Fires whenever the user attempts to save the component. Used to validate the consistency of data in component triggers associated PeopleCode on every row of data in the component buffers. SetCursorPos can be used to position cursor in the page field that needs to be corrected. Assignment statement cannot be used.

4/14/2012

SavePreChg Event
Fires after SaveEdit completes without errors One last chance to manipulate data before the system updates the database
Eg. Sequential numbers

Not field-specific: it triggers PeopleCode on all fields and on all rows of data in the panel buffer
4/14/2012

Workflow Event
Executes immediately after SavePreChg and before the database update Purpose is to segregate PeopleCode related to Workflow from the rest of application's PeopleCode. Not field-specific: it triggers PeopleCode on all fields and on all rows of data in the panel buffer
4/14/2012

SavePostChg Event
Fired after database update Used to update tables not defined in components using SQLExec
Eg. Log tables

Do not use Error or Warning Fails if Workflow fails Never use commit or rollback
4/14/2012

SearchInit Event
Generated just before a search dialog, add dialog, or data entry dialog is displayed Triggers associated PeopleCode in the search key fields of the search record Used to control the behavior of search dialog box Used to initialize or default search key or alt search key
4/14/2012

SearchSave Event
Executed for all search key fields on a search dialog, add dialog, or data entry dialog after the user OKs the dialog Allows to control processing after search key values are entered, but before the search based on these keys is executed Error and Warning can be used to send back search dialog if validations fail
Eg. Address validations - Flat No. and Door No.
4/14/2012

Menu PeopleCode
Menus are of two types
popup and standard, both are standalone objects in the project hierarchy.

Menu PeopleCode programs are associated with menu items,


4/14/2012

ItemSelected Event
Menu event set consists of a single event, ItemSelected Event Fires whenever an operator chooses a menu item from a popup menu; Is only associated with pop-up menus.

4/14/2012

Thank you

4/14/2012

Anda mungkin juga menyukai