Upload
hardanu
View
217
Download
7
Embed Size (px)
DESCRIPTION
PeopleCode Overview
Citation preview
PeopleCode - Overview
Session 467 - PeopleSoft and AppEngine
IntroductionWhat 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
Session 467 - PeopleSoft and AppEngine
Accessing PeopleCodePrior to PeopleTools 8Record FieldMenu ItemPeopleTools 8Record FieldPageComponentMenu Item (Pop-Up only)Component InterfaceMessage and Message ChannelApplication Engine
Session 467 - PeopleSoft and AppEngine
Editing PeopleCodePeopleCode 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 SyntaxDoes not format anything within the QuotesFieldnames are converted to UppercaseVariable match their First OccurrencePeopleCode is Case-Insensitive, except for quoted literals
Session 467 - PeopleSoft and AppEngine
Referencing Fields
Referring to a field by Assumes that ^The field is on the current record definitionFieldnameThe field is on the current record definitionRecordname.FieldnameThe field is on different record definition
Session 467 - PeopleSoft and AppEngine
PeopleCode StatementsStatement can be aDeclarationAssignmentProgram Construct (Such as a Warning Statement or a conditional loop)Subroutine callsAnd so on
PeopleCode statements should end in a semicolon
Session 467 - PeopleSoft and AppEngine
PeopleCode StatementsComments
Remark Comments;OrREM Comments;Or/* Comments */ Or/* Comments Comments */
Assignments
Addition+PRICE + TAXSubtraction-GROSS - TAXUnary Negation-10Multiplication*PRICE * QUANTITYDivision/ANNUAL_PAYMENTS / 12Exponentiation**DIMENSION ** 3String Concatenation|CITY | ,| STATE
Session 467 - PeopleSoft and AppEngine
PeopleCode StatementsIF statement
If condition then;Else;End-if;
You can have Nested IF statements
Relational Operators
=Equal To!= , Not Equal To> , >=Greater than , Greater than or Equal to< ,
PeopleCode StatementsERROR statementError ();
WARNING statementWarning ();
EVALUATE statementEvaluate When = ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - When-Other;End-EvaluateBREAK statementBreak;
Session 467 - PeopleSoft and AppEngine
PeopleCode StatementsFor LoopFor = to [step ]statement;statement;End-For;
While LoopWhile statement;statement;End-While;
Repeat-Until LoopRepeatstatement;statement;Until ;
Session 467 - PeopleSoft and AppEngine
Component ProcessorControls how PeopleSoft manages applications from Initial data retrieval through updating the databaseThroughout the process, Component Processor applies PeopleCode at different timePeopleCode 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 thingsWHEN you want the PeopleCode to executeWHERE to place the PeopleCodeWHAT PeopleCode syntax to use
Session 467 - PeopleSoft and AppEngine
Component ProcessorGeneral Areas where the Component Processor Performs PeopleCodeDuring the Search ProcessBefore the displaying the PageAfter a field ChangesAfter inserting and deleting a rowAfter page is savedAfter processing pop-menus
Search EventsSearchInit fires before the search dialog box appears to initialize fields or apply defaults to searchAfter 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 enteredBoth 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 EventsBefore 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.
Session 467 - PeopleSoft and AppEngine
Component ProcessorField Action EventsFieldEdit and FieldChange are activated when the value of a field is changedFieldEdit validates the new value. FieldChange does the processing based on the new (and valid) value of the field
Row Action EventsRowInsert 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 EventsOne 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 databaseWorkflow PeopleCode triggers a Business EventSavePostChange 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
Session 467 - PeopleSoft and AppEngine
Component ProcessorPop-Up Menu EventsPrePopup 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 ActionAdd 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 ProcessingIn 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 ImpactNo 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 serverDevelopers are encouraged to put FieldEdit validations in SaveEdit to save trips to serverDevelopers have the option of enabling the deferred processing, which will will automatically defer standard fields edits, FieldEdit and FieldChange events.
Session 467 - PeopleSoft and AppEngine
PeopleCode EventsSearchInit (SrI) PeopleCodePerforms before the search record dialog box displays.Controls processing before a user enters values in the search key and alternate search keysOnly 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) PeopleCodePerforms after the User clicks OK in the search dialog boxProvides a way to edit information entered in the search record dialog boxAlso used to force the user to input atleast one field into the dialog box
If Not RecordChanged(STUDENT_TBL.STUDENT_ID) And%Mode A thenError (You must enter at least one search value);End-If;
RowSelect (RSe) PeopleCodePerforms as the Component Buffer reads data into the componentRowSelect 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;
Session 467 - PeopleSoft and AppEngine
PeopleCode EventsPreBuild PeopleCodeComponent PeopleCode eventFires before the rest of the component build eventsOften used to hide or unhide pagesAlso used to set global or component scope variables that can be used later by PeopleCode located in other events
If %Mode A ThenHide(field.ADD_MODE_IND);End-If;
FieldDefault (FDe) PeopleCodeOnce 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) ThenSTUDENT_TBL.STUDENT_ID = NEW;End-If;
FieldFormula (FFo) PeopleCodeOnce FieldDefault completes successfully, the Component Processor performs FieldFormula PeopleCodeMainly used on the record definitions for PeopleCode function libraries (FUNLIBs). These record definitions store common routines that can be called from other programs
Session 467 - PeopleSoft and AppEngine
PeopleCode EventsRowInit (Rin) PeopleCodePerforms 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) ThenGray(PS_STUDENT_TBL.STUDENT_ID);End-If;
PostBuild PeopleCodeComponent PeopleCode eventUsed to Calculate values and set display characteristics of an object
If AMM_PUBLIST.NRID < 1 ThenGetPage(Page.AMM_RAWNRXML).Visible = False;End-If;
Activate PeopleCodePage PeopleCode eventFires each time a page is activatedPage Processing, such as enabling a field or hiding a scroll
SetGridLables(%Panel, Record.AMM_CHNL_SECVW);
Session 467 - PeopleSoft and AppEngine
PeopleCode EventsFieldEdit (FEd) PeopleCodePerformed after a field has changed and a new value fo the field satisfies the standard system editsUsed to validate the contents of the fieldAssignments statements should not be performed in FieldEdit
If PS_HDR.ORDER_STATUS IN ThenError Msgget(20000,1,Message not found);End-If;
FieldChange (FCh) PeopleCodePerformed after the FieldEdit has performed successfullyUsually 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 PeopleCodePerformed when a new row is addedUsed to Override effective-dated processing, or to auto number new rows of data
Session 467 - PeopleSoft and AppEngine
PeopleCode EventsRowDelete (RDe) PeopleCodePerformed when a new row is deletedUsed to caculate running totals or prevent a row from being deletedAfter the RowDelete finishes, the Component processor performs FieldDefault and FieldFormula peopleCode.
If PS_HDR.ORDER_STATUS IN ThenError Msgget(20000,1,Message not found);End-If;
FieldChange (FCh) PeopleCodePerformed after the FieldEdit has performed successfullyUsually 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 PeopleCodePerformed when a new row is addedUsed to Override effective-dated processing, or to auto number new rows of data
Session 467 - PeopleSoft and AppEngine
PeopleCode EventsSaveEdit (SEd) PeopleCodePerformed when tries to save the componentUsed to validate data before it is updated to the databaseSaveEdit makes sure that all the changes have been made before the validation takes place
SavePreChange (SPr) PeopleCodePerformed after the SaveEdit has performed successfullyProvides 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 thenassign_student_id(PSU_STUDENT_TBL.STUDENT_ID);End-If;
Workflow (Wrk) PeopleCodeSegregates the PeopleCode related to workflow from rest of applications peoplecodeAll Workflow peoplecode programs must include atleast one use of TriggerBusinessEvent() or Virtual_Router() Funclib function, which uses the TriggerBusinessEvent() function internally
SavePostChange (SPo) PeopleCodePerformed after the SavePreChange has successfully completed and CP has update the databaseUsed to update the data outside the component buffer, but still in the same database
Session 467 - PeopleSoft and AppEngine
PeopleCode VariablesUser-defined variables are required for temporarily holding the data in PeopleCodeAll 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
Session 467 - PeopleSoft and AppEngine
PeopleCode Variables
Variable TypeDuration (Scope)PurposeDisadvantageLocalProgramPasses values within a single programCannot display on a pageComponentComponentPasses values between all program within a componentCannot display on a page
GlobalPeopleSoft SessionPasses values between all components for a user sessionToo Numerous to mentionSystemApplication InstallationHold values for reference from any codeDerived/Work FieldsComponentDisplay values on a page and passes values between all programs with a single componentCannot write to database
Session 467 - PeopleSoft and AppEngine
PeopleCode VariablesLOCAL &VarName;
COMPONENT &VarName;
GLOBAL &VarName;
= Number String Boolean Date Time Datetime Object Any Float Integer
System Variables%Date%Time%UserId%Mode%Page
Session 467 - PeopleSoft and AppEngine
Object Oriented ProgrammingPeopleSoft 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.
Session 467 - PeopleSoft and AppEngine
Object Oriented ProgrammingINSTANTIATING OBJECTSUsually Instantiated (created from their class) using built in functions or methods of other objectsSome objects are instantiated by the data already present in the bufferSome objects are instantiated from an already created definition like a Component Interface
Eg: following creates a field object that references an employees nameLocal Field &Field;/* Declare */&Field = GetField(STUDENT_DATA.STUDENT_NAME);/* Instantiate */
Eg: following returns a record object for a record already in the page bufferLocal Record &REC1, &REC2; /* Declare */&REC1 = GetRecord(); /* Instantiate */&REC2 = CreateRecord(RECORD.COURSE_TBL); /* Instantiate */
Session 467 - PeopleSoft and AppEngine
Object Oriented ProgrammingOBJECT PROPERTIESTo 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= Value;Eg:(i) &Field.Visible = False;(ii) &x = &Field.Value; (iii) If &Rowset.ActiveRowCount &ISome of the properties of Field Class are as follows,VisibleValueNameLabelIsYesNoIsKeyEnabledEditError
Session 467 - PeopleSoft and AppEngine
Object Oriented ProgrammingOBJECT METHODSIn 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)
Session 467 - PeopleSoft and AppEngine
Object Oriented ProgrammingPASSING OBJECTSAll PeopleCode objects can be passed as function parameters, thus enabling the application developer to pass complete data structures between peoplecode functions
Local Rowset&ROWSET;LocalRecord&RECORD;
FunctionProcess_Rowset(&ROWSET as Rowset)For &I = 1 to &ROWSET.RowCountFor &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);
Session 467 - PeopleSoft and AppEngine
PeopleCode FunctionsCATEGORIES OF FUNCTIONSInternal-PeopleCode: A PeopleCode routine that is stored in the same program where it is used. Defined by a Function statement.External-PeopleCodeA PeopleCode routine that is stored in a different program from where it is used. Defined by a declare statement with the keyword PeopleCodeExternal-Non-PeopleCodeA common C++ (or other language routine that is loaded from DLL. Defined by a Declare statement with the keyword library.
FUNCTION STATEMENT
Function (,,)statement;statement;End-Function;
Session 467 - PeopleSoft and AppEngine
PeopleCode FunctionsDECLARING A FUNCTION
Declare Function PeopleCode 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 thenassign_student_id(PSU_STUDENT_TBL.STUDENT_ID);end-if;
RETURNS STATEMENT
Function (,) returns Returns ;
Session 467 - PeopleSoft and AppEngine
PeopleCode FunctionsBUILT-IN FUNCTION
Page Buffer Functions:Modify fields, values & variables within the buffersScroll Buffer Functions: Manipulate scroll area records for various purposesLogical Functions: Check if values exist for a fieldDate & Time Funcs: Used to easily calculate & manipulate datesString Functions: With with character stringsDouble-Byte Char Funcs: Supports the languages that utilise double-byte charsNumber functions: Work with numeric valuesDOS functions: Control DOS processesAPI functions: Include WinExec WorkFlow, RemoteCall etc
Session 467 - PeopleSoft and AppEngine
PeopleCode FunctionsMESSAGE CATALOG FUNCTION
MsgGetMsgGet (, ,DefaultMsgTxt[,,])
MsgGetTextMsgGetText(, ,DefaultMsgTxt[,,])
Session 467 - PeopleSoft and AppEngine
PeopleCode FunctionsGray/Ungray and Hide/Unhide FUNCTION
Procedural MethodGray();UnGray();
Object Based Method.Enabled = False;.Enabled = True;
IsChanged, IsNew, IsDeleted FUNCTION
&Field.IsChanged&Record.IsNew&Row.IsDeleted
Session 467 - PeopleSoft and AppEngine
PeopleCode FunctionsOther Important Functions FUNCTION
PriorValueRTrim, Ltrim, SubstringOriginalValueSetCursorPos Method
Local Field &Qty;
&Qty = GetField(PSU_PO_DTL.QTY);If All(&Qty.OriginalValue) then&Orig_Qty = &Qty.OriginalValue;if &Qty.value > &Orig_Qty thenError MsgGet(20000,30,Message Not Found);End-If;End-If;
Session 467 - PeopleSoft and AppEngine
Accessing BufferActiveRowCount.ActiveRowCountTotalRowCount.TotalRowCountValue,FetchValue and UpdateValue..value/* Object Based */FetchValue(,)/* Procedural */UpdateValue(,)/* Procedural */
DATA Buffer ClassesRowsetData structure used to describe a hierarchical dataRowsingle row of data in a component scrollRecordsingle instance of data within a row Fieldsingle instance of data within a recordw
Session 467 - PeopleSoft and AppEngine
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);
Session 467 - PeopleSoft and AppEngine
Traversing BufferTRAVERSING = ROWSET > ROW > RECORD > FIELD
Declare the data buffer objectsLocal Rowset &RS0, &RS1;/* Level0 and level1 rowsets */Local Row &Row0, &Row1;/* single row at level0 and level1 */Local Record &Rec1;/* record */Local Field &Field1;/* field */
&RS0 = GetLevel0();
&Row0 = &RS0.GetRow(1); OR &Row0 = &RS0(1);
&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;
Session 467 - PeopleSoft and AppEngine
Session 467 - PeopleSoft and AppEngine
Session 467 - PeopleSoft and AppEngine
Session 467 - PeopleSoft and AppEngine
Session 467 - PeopleSoft and AppEngine
Session 467 - PeopleSoft and AppEngine
Session 467 - PeopleSoft and AppEngine
Session 467 - PeopleSoft and AppEngine
Session 467 - PeopleSoft and AppEngine
Session 467 - PeopleSoft and AppEngine
Session 467 - PeopleSoft and AppEngine
Session 467 - PeopleSoft and AppEngine
Session 467 - PeopleSoft and AppEngine
PeopleCode Variables
Session 467 - PeopleSoft and AppEngine