Explaining the PeopleCode @ operator

By Chris Malek | Tue, Aug 30, 2011

Have you ever seen the PeopleCode @ operator and wondered when and why you would use it? Let’s look into it in more detail. The @ operator is used to tell the PeopleCode interpreter that you are passing in a string name for an object name.

First let’s look at how you normally create records passing an object name. Here we are going to create a record object based on PSOPRDEFN.

local record &recOPR;
&recOPR = createRecord(RECORD.PSOPRDEFN);

In the above example we knew the record name at design time because we hardcoded “RECORD.PSOPRDEFN” in the code. What if we do not know the object name at design time? This could be that we pull the record name out of a setup table. Or you have a generic piece of code that other pieces of code call and pass you the object name. This is where the “@” operator comes in.

Let’s look at the same example above using a dynamic operator.

local string &recName;
local record &recDynamic;
&recName = "RECORD.PSOPRDEFN";

&recDymanic = createRecord(@&recName);

Notice the @ in the createRecord parameter. So imagine that the “&recName” value is maybe pulled from a setup table at run-time and substituted in.

One common mistake that is often made is to forget the object type name at the front. In the code sample above that would be the “RECORD.” piece.

Let’s look at a field example. Here we are going to dynamically get the ACCTLOCK field off the PSOPRDEFN record.

local record &recOPR;
&recOPR = createRecord(RECORD.PSOPRDEFN);

local string &fieldName ;
&fieldName = "FIELD.ACCTLOCK";

local string &locked;
&locked = &recOPR.getfield(@&fieldName).value;
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
Product
PeopleSoft Simple Web Services (SWS)
Do you need a quick way to create web services?

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.

Book
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.