You are on page 1of 40

PeopleCode and the Component Processor

EIS Developer Forum


February 8, 2007

PeopleCode and the Component Processor


PeopleCode is an object-oriented language

Classes Objects Properties Methods

Classes
A class is the formal definition of an object and acts as a template from which an instance of an object is created at runtime. The class defines the properties of the object and the methods used to control the objects behavior.

Classes
PeopleSoft delivers predefined classes (such as Array, File, Field, Rowset, SQL, and so on). You can create your own classes using the Application class. You can extend the functionality of the existing classes using the Application class.

Classes An example

File class - provides methods and properties for reading from and writing to external files

Objects
An 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.

Object Instantiation

A class is the blueprint for something, like a bicycle, a car, or a data structure. An object is the actual thing that's built using that class (or blueprint.) For example, from the blueprint for a bicycle, you can build a specific mountain bike with 23 gears and tight suspension. From the blueprint of a data structure class, you build a specific instance of that class. For example, an instance of the Record class could be PERSONAL_DATA. Instantiation is the term for building that copy, or an instance, of a class.

Object Instantiation An Example


1.

Define a variable
Local File &fEMPDIRU_OUT;

2.

Instantiate the file object using the defined variable


&fEMPDIRU_OUT = GetFile("/peoplesoft/lsdv/mods/dat/P S_EMPDIRU_OUT.txt", "W", %FilePath_Absolute);

Note: GetFile is a built-in function used to instantiate a new file object from the File class, associate it with an external file, and open the file so you can use File class methods to read from or write to it.

Properties
A property is an attribute of an object (think adjective). Properties define:
Object characteristics, such as name or value. The state of an object, such as deleted or changed.

Properties An Example
IsOpen is a property of the File class which returns a Boolean value indicating whether the file is open.
If &fEMPDIRU_OUT.IsOpen Then

Some of the other properties include CurrentRecord, IsError, Name.

Methods
A method is the code associated with a given object (think verb). A method is a procedure or routine, associated with one or more classes, that acts on an object.

Methods An Example
WriteLine is a method of the File Class that writes
one string of text, string, to the output file associated with the file object executing this method.

&fEMPDIRU_OUT.WriteLine(&sRecOut);

Some of the other methods include Close, Delete, Open, and ReadLine.

Dot Notation

The means through which you access an objects properties or execute its methods.
This enables you to reference fields within a record object, records within a row object, and rows within a rowset object as properties of the parent objects.

Dot Notation An Example


&Rec_Names = &Row_Names.NAMES;

&sMaidenName = &Rec_Names.LAST_NAME.Value;

DERIVED_NAME.UPDATE_NAME_BTN.Enabled = False;

Referencing Data in the Component Buffer


What is the Component Buffer?

The area in memory that stores data for the currently active component. Consists of rows of buffer fields that hold data for the records associated with page controls, including primary scroll records, related display records, derived/work records, and Translate table records.

Ways to reference data

In a contextual reference, PeopleCode refers to a row or buffer field determined by the context in which a PeopleCode program is currently executing (think relative).
A scroll path specifies a scroll level in the currently active page (think absolute).

Contextual Reference

Refers to a row or buffer field determined by the context in which a PeopleCode program is currently executing. The current context includes

All buffer fields in the row of data where the PeopleCode is executing All buffer fields in rows that are hierarchically superior to the row where the PeopleCode is executing

Contextual Reference
Level zero row is always in context

Parent of row where executing takes place is in context

Row where PeopleCode is currently executing All rows on lower scroll area out of context

If GetRowSet().ParentRowset.ParentRow.IsDeleted Then

Scroll Paths

A scroll path specifies a scroll level in the currently active page. If the level you want to reference is level one, you must supply only the RECORD.target_recname parameter. If the target scroll level is greater than level one, you must provide scroll name and row level parameters for all hierarchically superior scroll levels, beginning at level one.

Scroll Paths
Target Level
1

Scroll Path Syntax


RECORD.target_recname

RECORD.level1_recname, level1_row, RECORD.target_recname


RECORD.level1_recname, level1_row, RECORD.level2_recname, level2_row, RECORD.target_recname

Data Buffer Classes

Repeat after me
Rowset

Row
Record Field

Data Buffer Classes


Rowset

A rowset object is a data structure used to describe hierarchical data. It is made up of a collection of rows. Think of a rowset as a scroll on a page that contains all that scrolls data. A level 0 rowset contains all the data for the entire component.

Data Buffer Classes


Row
A

row object represents a single row in a component scroll A row contains one or more records. A row may also contain child rowsets.

Data Buffer Classes


Record
A

record object is a single instance of data within a row and is based on a record definition. A record contains one or more fields.

Data Buffer Classes


Field
A

field object is a single instance of data within a record and is based on a field.

Occurs Level Review


Component Level 0
Every component has at least one level 0 definition. The search key, and other fields from the same record definition, have a level of 0. There can only be one row of data for each level 0 record definition because scrolls begin at occurs level 1.

Occurs Level Review


Component Level 0

Occurs Level Review


Occurs Level 1

Scrolls allow you to insert, delete, and navigate through multiple rows of data. The keys of the occurs level 1 record definition must include the same search keys as level 0, with at least one additional key. PeopleSoft allows only one primary record definition per scroll. Fields from other record definitions may appear on a level for related display or as derived/work fields.

Occurs Level Review


Occurs Level 1

Occurs Level Review


Other Occurs Levels

The maximum possible value of an occurs level for a component is 3. PeopleSoft allows multiple primary record definitions at occurs level 2 and 3, but each primary record definition requires its own scroll. Occurs level 2 primary record definitions must have the same key fields as occurs level 1 plus at least one additional key field. Occurs level 3 primary record definitions must have the same key fields as occurs level 2 plus at least one additional key field.

Occurs Level Review


Other Occurs Levels

Looping through Scroll Levels


Local rowset &RS;
Local row &Row; Local record &Rec; Local field &Field;

&RS = GetLevel0()(1).GetRowset(SCROLL.Owner);
For &i = 1 to &RS.ActiveRowCount &Row = &RS.GetRow(&i); For &j = 1 to &Row.RecordCount

&Rec = &Row.GetRecord(&j);
For &k to &Rec.FieldCount &Field = &Rec.GetField(&k) End-For;

End-For;
End-For;

PeopleCode and the Component Processor


PeopleCode can be performed at different times during a components processing flow (called events) to allow for additional processing.

PeopleCode and the Component Processor


Whenever coding PeopleCode to enforce a business rule governing your data, you will need to know three things:
1. 2. 3.

WHEN you want it to execute WHERE to place your PeopleCode WHAT to program

WHEN you want it to execute


When during the flow of the Component Processor do you need your code to execute?
Before the Search Page is displayed? When the page is activated? When a row is inserted or deleted? When a field is changed? When the user clicks the Save button?

WHERE to place your PeopleCode


Many different events are available:
Record Field Events Component Record Field Events Component Record Events Component Events Page Event Menu Event

- Part 1

PeopleSoft Component Processor Flow - Part 2

WHAT to program

Workshop Tomorrow
For more information on this topic, sign up for one of the workshops to be held tomorrow

9:00 am 12:00 pm

1:00 pm 4:00 pm

You might also like