0% found this document useful (0 votes)
7 views12 pages

PeopleCode Syntax and Functions Guide

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)
7 views12 pages

PeopleCode Syntax and Functions Guide

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 Full Reference Guide

1. Basic Syntax
-- Single line comment
/* Multi-line comment */
Local string &name;
Local number &count;
&name; = "John";
&count; = 5;
2. Control Structures
If &count; > 0 Then
MessageBox(0, "", 0, 0, "Positive");
Else
MessageBox(0, "", 0, 0, "Not Positive");
End-If;
For &i; = 1 To 5
MessageBox(0, "", 0, 0, String(&i;));
End-For;
While &i; < 10
&i; = &i; + 1;
End-While;
Evaluate &grade;
When = "A"
MessageBox(0, "", 0, 0, "Excellent");
When-Other
MessageBox(0, "", 0, 0, "Other Grade");
End-Evaluate;
3. Functions
Function AddNumbers(&a; As number, &b; As number) Returns number
Return &a; + &b;
End-Function;
Local number ∑ = AddNumbers(10, 20);
4. Try-Catch (Error Handling)
Try
/* risky code */
Local number &x; = 10 / 0;
Catch Exception &ex;
MessageBox(0, "Error", 0, 0, &[Link];());
End-Try;
5. Arrays & Objects
Local array of string &arr;
&arr; = CreateArrayRept("", 3);
&arr;[1] = "One";
&arr;[2] = "Two";
MessageBox(0, "", 0, 0, &arr;[2]);
6. Records & Rowsets
Local Record &rec; = CreateRecord(Record.PERSONAL_DATA);
&[Link]; = "123";
&[Link];();
MessageBox(0, "", 0, 0, &[Link];);
Local Rowset &rs; = GetLevel0()(1).GetRowset(Scroll.EMPL_DATA);
Local Row &row; = &rs;(1);
&[Link];_DATA.[Link] = "John Doe";
7. SQL in PeopleCode
SQLExec("SELECT COUNT(*) FROM PS_PERSONAL_DATA", &count;);
Local SQL &sql; = CreateSQL(
"SELECT NAME FROM PS_PERSONAL_DATA WHERE EMPLID = :1", &emplid;);
While &[Link];(&name;)
MessageBox(0, "", 0, 0, &name;);
End-While;
8. File Handling
Local File &file; = GetFile("/tmp/[Link]", "W", "A", %FilePath_Absolute);
&[Link];("Hello World");
&[Link];();
9. Events
/* Common Component Events */
FieldChange – runs when field changes.
RowInit – runs when row is initialized.
SavePreChange – before saving data.
SavePostChange – after saving data.
PageActivate – when page is activated.
10. Application Classes (OO PeopleCode)
class HelloWorld
method SayHello();
end-class;
method HelloWorld
end-method;
method SayHello
MessageBox(0, "", 0, 0, "Hello from Class!");
end-method;
Local HelloWorld &obj; = create HelloWorld();
&[Link];();
11. Component Interfaces
Local ApiObject &ci; = GetCompIntfc(CompIntfc.HR_PERSONAL_DATA);
&[Link]; = "123";
&[Link];();
MessageBox(0, "", 0, 0, &[Link];);
12. Integration Broker (IB)
Local Message &msg; = CreateMessage(Operation.SEND_EMPLOYEE);
Local Rowset &rsData; = &[Link];();
&rsData;(1).[Link] = "123";
%[Link](&msg;);

Common questions

Powered by AI

In PeopleCode, single line comments are denoted by the double forward slash (//), allowing for comments to be added on a single line or after code. Multi-line comments are enclosed within /* and */, enabling comments to span multiple lines. The choice between these impacts readability by allowing for conciseness with single line comments or detailed explanations with multi-line comments .

SQLExec is a PeopleCode function for executing SQL statements from within PeopleCode scripts. It is used to interact directly with the database to perform queries, updates, or insertions. SQLExec can execute select statements to retrieve data or modify the database directly. For instance, SQLExec("SELECT COUNT(*) FROM PS_PERSONAL_DATA", &count;) retrieves the number of rows in the PS_PERSONAL_DATA table and assigns it to &count .

PeopleCode events are triggers that execute PeopleCode programs at specific times in the component processing lifecycle, enhancing interactivity and responsiveness. The FieldChange event runs when a field's value changes on a page, allowing for validation, computations, or updates to execute immediately based on user actions, thus improving user experience and data integrity within components .

Key components of a PeopleCode function include the function name, input parameters, return type, and the code block that performs computations. For example, the function 'AddNumbers' takes two numerical parameters and returns their sum. Functions contribute to code reusability by encapsulating operations that can be easily called with different arguments, reducing code duplication and enhancing maintainability .

Component Interfaces in PeopleCode provide a programmatic way to interact with the PeopleSoft application server, allowing external systems to execute business logic and access component data securely. They encapsulate component structure and business rules, promoting integration. A practical example involves setting an employee ID and retrieving details: GetCompIntfc(CompIntfc.HR_PERSONAL_DATA).EMPLID = "123"; .

Control structures in PeopleCode, such as 'If', 'For', 'While', and 'Evaluate', allow for decision-making, looping, and branching, which enhance the program flow by enabling the execution of different code blocks based on conditions. An example of an 'If' statement checks whether a numerical variable &count is greater than zero to display a message accordingly: If &count > 0 Then MessageBox(0, "", 0, 0, "Positive"); Else MessageBox(0, "", 0, 0, "Not Positive"); End-If; .

The Integration Broker in PeopleCode enhances system interoperability by enabling asynchronous and synchronous integrations between PeopleSoft applications and external systems via web services. It employs messages to transport data, defining message structure and format. For example, a message created for the 'SEND_EMPLOYEE' operation includes a rowset with employee data, published to the broker for processing, thus facilitating streamlined communication and data exchange .

The Try-Catch block in PeopleCode allows for graceful error handling by attempting to execute code that might fail within a 'Try' block and catching exceptions with a 'Catch' block. If a runtime error occurs, control is passed to the Catch block where the error can be managed, logged, or displayed. This mechanism is critical for building robust applications that can manage and recover from unexpected issues without crashing .

Arrays in PeopleCode are used to store collections of elements of the same type, allowing for easy data access, manipulation, and management. Using arrays, a large set of data can be processed efficiently through looping constructs. For instance, the CreateArrayRept function creates an array, and data is accessed by indexing, providing benefits like efficient data handling and reduced memory overhead for common operations .

PeopleCode supports Object-Oriented Programming (OOP) through application classes, which encapsulate behavior (methods) and state (properties) within a defined blueprint. Classes enable modular, reusable code by defining methods and properties accessed through instantiated objects. For example, the HelloWorld class contains a method SayHello, encapsulating functionality to display a message, demonstrating encapsulation and reusability .

You might also like