0% found this document useful (0 votes)
17 views7 pages

PeopleCode Developer Handbook

Uploaded by

muhammad.ammad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views7 pages

PeopleCode Developer Handbook

Uploaded by

muhammad.ammad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PeopleCode Developer Handbook

A practical, example-heavy cheat sheet for PHP/JS developers learning PeopleCode.

1) Variables, Types & Scope


Declare with scope keywords: Local, Global, Component, Instance. Primitive types include string, number, boolean,
date, datetime, time; objects include Record, Row, Rowset, SQL, File, arrays and classes.
/* Comments: use REM ... ; for single-line, or /* ... */ for block */
Rem Single line comment;
/* Multi
line comment */

Local string &name;


Local number &count;, &i;
Local boolean &ok;
Local date &today;
Local datetime &ts;
Global string &gCompany; /* visible everywhere in the session */
Component number &compCounter; /* visible within this component */

&name; = "Ammad";
&count; = 3;
&ok; = True;
&today; = %Date;
&ts; = %DateTime;

/* Operators */
∑ = 2 + 3; /* arithmetic: + - * / */
&cat; = "Peoplesoft " | "Rocks"; /* string concat uses | */
&bool; = (&count; > 2) And Not False;

2) Control Flow
Standard branching and loops. For loops support Step; While and Repeat-Until are also available.
/* If / ElseIf / Else */
If &count; = 0 Then
MessageBox(0, "", 0, 0, "Zero");
ElseIf &count; < 5 Then
MessageBox(0, "", 0, 0, "Less than five");
Else
MessageBox(0, "", 0, 0, "Five or more");
End-If;

/* Evaluate (switch) */
Evaluate &status;
When = "NEW"
/* ... */
When = "ACTIVE"
/* ... */
When-Other
/* ... */
End-Evaluate;

/* For */
For &i; = 1 To 10 Step 2
/* do something */
End-For;

/* While */
While &i; < 20
&i; = &i; + 1;
End-While;
/* Repeat-Until */
Repeat
&i; = &i; - 1;
Until &i; = 0;

3) Functions & Procedures


Declare with parameter types and optional return type. Functions must be defined before they are called in the
same program or placed in Include files or Application Packages.
Function AddNumbers(&a; As number, &b; As number) Returns number
Return &a; + &b;
End-Function;

/* Procedure (no return) */


Function LogMsg(&text; As string)
MessageBox(0, "Log", 0, 0, &text;);
End-Function;

Local number ∑ = AddNumbers(10, 20);


LogMsg("Sum is " | String(∑));

4) Error Handling (Try/Catch)


Catch Exception or specific subclasses (e.g., ApplicationException). Use Throw to raise errors.
Try
/* risky code */
Local number &x; = 10 / 0; /* will raise an exception */
Catch Exception &ex;
MessageBox(0, "Error", 0, 0, "Caught: " | &ex.ToString;());
End-Try;

/* Throwing an exception */
class MyError extends Exception end-class;
Try
Throw create MyError("Custom failure");
Catch MyError &e;
MessageBox(0, "MyError", 0, 0, &e.ToString;());
End-Try;

5) Strings & Dates (Common Built-ins)


Frequently used helpers for text and dates/times.
Local string &s; = "PeopleCode";
Local number &pos; = Find("Code", &s;); /* returns 6 (1-based) */
Local string ∂ = SubString(&s;, 1, 6); /* 'People' */
Local string &up; = Upper(&s;); /* 'PEOPLECODE' */
Local string &low; = Lower(&s;); /* 'peoplecode' */
Local number &len; = Len(&s;);

Local date &d; = %Date; /* today's date */


Local number &y; = Year(&d;);
Local number &m; = Month(&d;);
Local number &day; = Day(&d;);
Local date &next; = AddToDate(&d;, 0, 1, 0); /* add 1 month */

6) Arrays
Resizable arrays with CreateArray or CreateArrayRept. Indexing is 1-based.
Local array of string &names; = CreateArray("Ali", "Sara");
&names.Push;("Khan");
For &i; = 1 To &names.Len;
MessageBox(0, "", 0, 0, &names;[&i;]);
End-For;

/* Pre-sized array */
Local array of number &nums; = CreateArrayRept(0, 3);
&nums;[1] = 10; &nums;[2] = 20; &nums;[3] = 30;

7) Component Buffer Navigation


Navigate Level 0/1/2 rowsets to read/write page buffer data.
/* Level 0 rowset */
Local Rowset &L0; = GetLevel0();
Local Row &root; = &L0;(1);

/* Get a child rowset (Scroll) on the page/component */


Local Rowset &jobRs; = &root.GetRowset;(Scroll.JOB);

/* Iterate visible rows */


Local number &r;
For &r; = 1 To &jobRs.ActiveRowCount;
Local Row &row; = &jobRs.GetRow;(&r;);
/* Read/Write field values */
Local string &emplid; = &row.PERSONAL;_DATA.EMPLID.Value;
&row.JOB.EFF;_STATUS.Value = "A";
End-For;

8) Record & Row Objects


Work with Record/Field values and commit changes using Save processing or SQL.
/* Create a standalone record and select by key */
Local Record &rec; = CreateRecord(Record.PERSONAL_DATA);
&rec.EMPLID.Value; = "000123";
If &rec.SelectByKey;() Then
MessageBox(0, "", 0, 0, "Name: " | &rec.NAME.Value;);
End-If;

/* Insert or Update; these honor PeopleCode events and defaults when used in Component context */
&rec.NAME.Value; = "John Doe";
&rec.Update;(); /* or &rec.Insert;(); or &rec.Delete;(); */

9) SQLExec (single-row)
Quick one-row SELECT/INSERT/UPDATE/DELETE. Binds are :1, :2, ... Output vars must match selected columns.
Local string &name;
Local boolean &ok; = SQLExec("SELECT NAME FROM PS_PERSONAL_DATA WHERE EMPLID = :1", "000123", &name;);
If &ok; Then
MessageBox(0, "", 0, 0, "Found: " | &name;);
End-If;

/* Update example */
SQLExec("UPDATE PS_JOB SET EFF_STATUS = :1 WHERE EMPLID = :2 AND EFFDT = :3",
"A", "000123", %Date);

10) CreateSQL (multi-row cursor)


Use for multi-row results with Fetch in a loop. Always close when finished (auto-closes at scope end).
Local SQL &sql; = CreateSQL("
SELECT EMPLID, NAME
FROM PS_PERSONAL_DATA
WHERE NAME LIKE :1", "A%");

Local string &emplid;, &name;


While &sql.Fetch;(&emplid;, &name;)
MessageBox(0, "", 0, 0, &emplid; | " - " | &name;);
End-While;
&sql.Close;();

11) File I/O


Support for text files. Modes: "R" (read), "W" (write), "A" (append).
Local File &f; = GetFile("/tmp/out.txt", "W", "A", %FilePath_Absolute);
&f.WriteLine;("Hello from PeopleCode");
&f.Close;();

/* Reading */
Local File &rf; = GetFile("/tmp/out.txt", "R", "A", %FilePath_Absolute);
Local string &line;
While &rf.ReadLine;(&line;)
/* process &line; */
End-While;
&rf.Close;();

12) Common Events (Where to put code)


Events run at specific times. Place logic appropriately for correct behavior and performance.
/* FieldChange (RECORD.FIELD) */
Rem Fires when the field value changes;
If %Component = Component.HR_JOB_DATA Then
/* validate or derive values */
End-If;

/* RowInit (RECORD) */
Rem Initialize defaults when a row becomes active;

/* SavePreChange (COMPONENT) */
Rem Final validation before save; set errors with Error or MessageBox;

/* SavePostChange (COMPONENT) */
Rem After successful save; perform follow-up actions;

/* RowInsert / RowDelete */
Rem Logic tied to row-level add/delete;

/* PageActivate (PAGE) */
Rem When page is displayed; avoid heavy SQL loops here;

13) System Variables (Useful Globals)


Handy context variables available anywhere.
/* Examples */
Local string &user; = %UserId; /* current user */
Local string &opr; = %OperatorId; /* operator id */
Local date &d; = %Date; /* current date */
Local datetime &dt; = %DateTime; /* current date/time */
Local string &action; = %Action; /* Add, Update/Display, etc. */
Local number &mode; = %Mode; /* component mode */
14) Application Classes (OO PeopleCode)
Organize logic in Application Packages; supports properties, methods, inheritance.
/* In App Package MY_APP: class Greeter */
class Greeter
property string Name get set;
method Greeter(&n; As string);
method Say();
end-class;

method Greeter
%This.Name = &n;
end-method;

method Say
MessageBox(0, "", 0, 0, "Hello, " | %This.Name | "!");
end-method;

/* Usage */
import MY_APP:*;
Local MY_APP:Greeter &g; = create MY_APP:Greeter("Ammad");
&g.Say;();

15) Component Interface (CI) Basics


Automate component data entry. Set keys, then Get or Create, then Save.
Local ApiObject &ci; = GetCompIntfc(CompIntfc.HR_PERSONAL_DATA);
If &ci; = Null Then
Error ("CI not found");
End-If;

&ci.EMPLID; = "000123";
If &ci.Get;() Then
&ci.NAME; = "John Doe";
&ci.Save;();
End-If;

16) Integration Broker (IB)


Publish asynchronous messages or call synchronous services.
/* Publish example */
Local Message &msg; = CreateMessage(Operation.SEND_EMPLOYEE);
Local Rowset &rs; = &msg.GetRowset;();
&rs;(1).EMPLID.Value = "000123";
%IntBroker.Publish(&msg;);

/* Sync request example */


Local Message &rq; = CreateMessage(Operation.GET_EMPLOYEE);
Local Message &rsMsg; = %IntBroker.SyncRequest(&rq;);

17) Useful Patterns & Tips


Idioms you'll use all the time in real screens and batch code.
/* Safe read of a numeric field (handles Null) */
Local number &n; = Value(&rec.MY;_REC.MY_NUM.Value | "0");

/* Iterate only changed rows to reduce work */


Local Rowset &rs; = GetLevel0()(1).GetRowset(Scroll.MY_SCROLL);
Local number &r;
For &r; = 1 To &rs.ActiveRowCount;
Local Row &row; = &rs.GetRow;(&r;);
If &row.IsChanged; Then
/* process */
End-If;
End-For;

/* Derive display text without saving to DB */


&row.DERIVED;_WRK.DESCR.Value = "Computed: " | String(&n;);
End of Handbook — Happy PeopleCoding!

You might also like