Explaining the PeopleCode @ operator

Explaining the PeopleCode @ operator

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 intepreter 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;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值