Tue 26 Oct 2004
PeopleCode: Comparing a variable to a list of values
Posted by ChiliJoe under PeopleSoft • Tips & Techniques • PeopleCodeI sometimes come across a chunk of PeopleCode that requires a variable be compared to a list of values — like the IN operator in SQL:
If &code = "ABCD" Or &code = "HIJK" Or &code = "OPQR" Then
...
If the condition needs to be checked multiple times within the code and the list changes, there will be some effort required to update the code.
A better coding approach is to use an array and its Find method:
Local array of string &list;
&list = CreateArray("ABCD", "HIJK", "OPQR");
...
If &list.Find(&code) > 0 Then
...
If the list of values changes, only the array will need to be updated.
April 19th, 2008 at 10:12 am
There is no find method for an array. You have to loop thru the array to find a value,
An alternative is to concatenate the values into a string and use the string find method.
April 20th, 2008 at 10:08 am
No, it has a Find method.