Using Record Objects as Parameters and Returns

By Chris Malek | Wed, Oct 13, 2010

There are often times where I would like to create a PeopleCode function with optional parameters. PeopleCode does not support optional parameters like more advanced languages (i.e. Ruby as one of many examples). One work around for this is to use a record object as the function parameters.

The function declaration might look something like this rough sketch:

Function MyFunction(&inRec as record)

   &Param3 = "defaultValue";
   &Param3 = "defaultValue";
/* do some important work with &inRec field values and &param3 */

Then to call the function it might look like this:

Local Record &rec = CreateRecord(record.MY_FUNC_PARAM)
&rec.FIELD1.VALUE = "123";
&rec.FIELD2.VALUE = "ABC";

In this case we did not set a value of FIELD3. The function implementation looks for the optional value and defaults it to something if not provided.

Another benefit of using record objects as parameters, is that you can later add fields to the record object which represent new parameters and any calling client code in your production database will not have to be updated. Of course, the functional implementation will need to have some “smarts” to default the value to something if it was not passed until all the clients of the function have been changed.

You can also use record objects as a return to return more than one value from a function since Peoplecode does not support multiple return values like Ruby does.

The function implementation might look something roughly like this:

Function MyFunction2() returns record

  local record &rec = createrecord(record.MY_RETURN_REC);
   /* Do some important stuff */
   &rec.FIELD1.VALUE = "123";
   &rec.FIELD2.VALUE = "ABC";
   &rec.FIELD3.VALUE = "XYZ";
   return &rec;


Of course, if you start using application Packages you can get around many of these limitations using Class Instance variables. However, I will save that for another discussion.

Article Categories
Author Info
Chris Malek

Chris Malek is a PeopleTools® Technical Consultant with two decades of experience working on PeopleSoft enterprise software projects. He is available for consulting engagements.

About Chris Work with Chris
Looking for pain-free PeopleSoft web services? 😀
PeopleSoft Simple Web Services (SWS)

Introducing a small but powerful PeopleSoft bolt-on that makes web services very easy. If you have a SQL statement, you can turn that into a web service in PeopleSoft in a few minutes.

Integration Broker - The Missing Manual

I am in the process of writing a book called "Integration Broker - The Missing Manual" that you can read online.