Accessing PeopleCode Objects
The existing PeopleCode classes (like Array, Rowset, and so on) have properties and methods you can access.
-
PeopleCode classes have the same names, so Record becomes Record, SQL becomes SQL, and so on.
-
Methods are accessed by the method name.
-
The name of a property is prepended with either get or set, depending on whether you're reading or writing to the property.
For example, to get the IsChanged property would be getIsChanged. To set the value for a field would be &MyField.setValue.
Here is an example of a Java program that uses PeopleCode objects to access the database:
/*
* Class Test
*
* This code is used to test the Java/PeopleCode interface.
*
*/
import PeopleSoft.PeopleCode.*;
public class Test {
/*
* Test
*
* Add up and return the length of all the
* item labels on the UTILITIES menu,
* found two different ways.
*
*/
public static int Test() {
/* Get a Rowset to hold all the menu item records. */
Rowset rs = Func.CreateRowset(new Name("RECORD", "PSMENUITEM"), new Object[]{});
String menuName = "UTILITIES";
int nRecs = rs.Fill(new Object[]{"WHERE FILL.MENUNAME = :1", menuName});
int i;
int nFillChars = 0;
for (i = 1; i <= rs.getActiveRowCount(); i++) {
String itemLabel = (String)rs.GetRow(i)
.GetRecord(new Name("RECORD", "PSMENUITEM"))
.GetField(new Name("FIELD", "ITEMLABEL"))
.getValue();
nFillChars += itemLabel.length();
}
/* Do this a different way - use the SQL object to read each menu
item record. */
int nSQLChars = 0;
Record menuRec = Func.CreateRecord(new Name("RECORD", "PSMENUITEM"));
SQL menuSQL = Func.CreateSQL("%SelectAll(:1) WHERE MENUNAME = :2",
new Object[]{menuRec, menuName});
while (menuSQL.Fetch(new Object[]{menuRec})) {
String itemLabel = (String)menuRec
.GetField(new Name("FIELD", "ITEMLABEL"))
.getValue();
nSQLChars += itemLabel.length();
}
return nFillChars + 100000 * nSQLChars;
}
}
This can be run from PeopleCode like this:
Local JavaObject &Test;
Local number &chars;
&Test = GetJavaClass("Test");
&chars = &Test.Test();
&Test = Null;
WinMessage("The character counts found are: " | &chars, 0);