Friday, January 31, 2014

Array Oddities Creating the empty array

I've found that the arrays in peoplecode have a few oddities that you really need to pay attention to when you creating them.

Defining Array

Specific type

Local Array of String &arrayString;

Any type

Local Array of Any &arrayAny;

Instantiate your Array

If you use the CreateArray(); method you must pass in at least one value of the array type you defined UNLESS you are instantiating and Any array you can call it without a value to create an empty array.

&arrayString = CreateArray("Hello World");

&arrayAny = CreateArray();

Empty Array of a specific Type

If you want to create an empty array of a specific data type you need to use a different method CreateArrayRept(); This method has two parameters the type of object and the number of times you want that object repeated into the array.
Local Record &record;
Local Number #
Local Array of Record &records;
Local Array of Number &numbers;
&arrayString = CreateArrayRept("", 0);
&records = CreateArrayRept(&record, 0);
&numbers = CreateArrayRept(&number, 0);

No comments:

Post a Comment