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

  1. Local Array of String &arrayString;

Any type

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

  1. &arrayString = CreateArray("Hello World");

  1. &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.
  1. Local Record &record;
  2. Local Number #
  3. Local Array of Record &records;
  4. Local Array of Number &numbers;
  5. &arrayString = CreateArrayRept("", 0);
  6. &records = CreateArrayRept(&record, 0);
  7. &numbers = CreateArrayRept(&number, 0);

No comments:

Post a Comment