Professional Documents
Culture Documents
com
Arrays
Arrays are variables that hold multiple values.
Each array value has an index number.
You write values, to or read values from, the array by referencing the
index number.
Loops
Loops can reduce the size of your script. For example, instead of creating 20
lines of script to calculate 20 account values, you can create a loop that
repeats a single line of script 20 times, specifying a different account for each
iteration. Loops are sections of code that repeat execution for a specified
number of times or until a condition is met.
We have learned that the HS.Exp function can write data to either a single
member of a subcube dimension or to all valid members of the dimension:
If we specify a dimension member on the destination (left) side of
HS.Exp, it writes data only to that member of the dimension.
If we omit the dimension from the destination (left) and source (right)
sides of HS.Exp or include it only on the source (right) side, it writes to
all valid members of the dimension.
But frequently you need a rule to act on a subset of dimension members. For
example, we might need a rule that writes values to all accounts that are
descendants of the Total Expenses account, but to no others. If there were 50
descendants of Total Expenses, you would need 50 HS.Exp statements.
Similarly, we must frequently limit the members of the Entity, Scenario, Year,
or Period dimension for which a rule executes. Using an If...Then or
Select...Case statement is convenient if there are a small number of members,
but it becomes problematic with many members. For example, we might need
a rule that executes only for entities that have Eur as their default currency. If
there were 25 entities with Eur as their default currency, you would need an
If...Then statement or a Select...Case statement with 25 conditions, which
would be difficult to write and maintain.
We can use loops and arrays to work with large subsets of members. We first
load the members into an array. We then use a loop to repeat the execution of
a rule for each member in the array.
Frequently you need to write rules that execute for a subset of members
in a dimension.
In the example on the slide, the Overhead members of the Custom2 dimension
are stored in an array variable named aOver. A loop is used to perform a
calculation for each member in the array.
aEntity(8)=Europe
This example retrieves the tenth item from aEntity and stores it in the
vCurrEntity variable:
vCurrEntity=aEntity(9)
Filling Arrays Using Member ListsYou can use the HS.List function to fill an
array variable with the members from a member list.
Syntax
HS.Dimension.List("Parent","Listname")
Parameter Description
Dimension A Dimension name
Parent Optional. The name of the top parent member for a system-defined
list.
Listname The name of a valid system list or a user-defined member list
Examples of HS.List:
Creating Loops
You can create several types of loops in VBScript.
For...Next
Repeats the execution of a block of statements a specific number of times. For
loops use a counter variable whose value is automatically increased or
decreased with each repetition of the loop. You specify the initial value for the
counter variable and the maximum value the counter can reach for the block
of code to be executed.
Syntax
For Counter = StartVal To EndVal
...
...
Next
Creating Loops
You can use these statements to create loops:
For...Next: Using a counter to run statements a specified number of
times.
For Each...Next: Repeating a group of statements for each object in a
collection.
Do...Loop: Looping while or until a condition is true.
Parameter Description
Counter A name for the counter variable
StartVal The initial value for counter variable.
For Each...Next
Repeats a block of statements for each element in an array. All statements
execute for each element in the array until there are no more elements. You
specify a variable that returns the index for the current element in the array.
Syntax
For Each Item in ArrayVariable
...
...
Next
Parameter
Item
A variable name for the counter variable.
ArrayVariable
The name of an array variable
Example
In the following script, Item is the counter variable and BeepCount is an array
variable.The computer beeps for as many items as there are in the BeepCount
array variable.
Do...Loop
Runs a block of statements an indefinite number of times. The statements are
repeated either while a condition is true or until a condition becomes true.
Repeating Statements While a Condition is True
You use the While keyword with a Do loop to run a block of statements while
a condition is true.
Syntax
Do While Condition
...
...
Loop
Parameters
Condition
An expression that evaluates to true or false
Example
In the following script, the statements inside the loop run while the value of
myNum is 10 or less.
Syntax
Do Until Condition
...
...
Loop
Parameters
Condition
An expression that evaluates to true or false
Example
In the following script, the statements inside the loop execute until the value
of myNum reaches 11.
With For...Next loops, you must specify a start number and an end number for
the counter variable. But often you do not know the number of items in the
array. You can use the Lbound function to retrieve the index number of the
first item in the array and the Ubound function to retrieve the index number
of the last item.
For Each...Next loops automatically repeat for each member in the array, so
the Lbound and Ubound functions are not needed.
The counter variable increments the index number of the array variable
to retrieve a different member from the array at each iteration of the
loop.
Use the Lbound and Ubound functions to retrieve the number of items
in the array.
Attributes in Loops
There may not be a system or user-defined member list that defines the
precise subset of members that you need to include in a loop. You can use
member attributes as additional criteria for selecting members for which
rules are executed
So far, you have used the Exp function to read and write account values.
Financial Management rules provide other functions for reading and writing
data to data intersections.
The Exp function retrieves data from a source account or accounts and writes
it to a destination account or accounts. However, sometimes you need to store
data to a variable instead of an account. For example, you might want to
retrieve the value for TotalHeadcount and store it in a variable, which you
then use for a series of calculations. The GetCell function enables you to
retrieve data from a specified data intersection or cell and store it in a
variable.
GetCell Function
Syntax
HS.GetCell("POVExpression")
Parameter
POVExpression
A valid Point of View. You can include any dimension in the POV expression. If
you omit the Entity, Scenario, Year, or Period dimensions, the current Point of
View is used.
SetDataWithPOV Function
You may need to add to the existing values for an account rather than
overwrite them.
You can use the SetDataWithPOV option to write data to a specified data
intersection or cell. You can choose to overwrite the data for the cell or add to
the existing data. Writes data to a specified data intersection or cell.
Syntax
HS.SetDataWithPOV(POV,Data,Add)
Parameter
Parameter Description
POV A valid expression. You must include members for the
Account, custom, and ICP dimensions. No other dimensions
are valid.
Data The data value to set.
Add True to accumulate the data or False to replace the data.
Syntax
HS.GetCell("POVExpression,Var")
Parameter
POVExpression
A valid Point of View. You can include any dimension in the POV expression.
Var
A variable that returns True if there is no data and False if there is real data
or derived data.
GetCellRealData Function
Gets the data contained in a cell and indicates if the cell contains real data.
Syntax
HS.GetCellRealData("POVExpression,Var")
Parameters
POVExpression
A valid Point of View. You can include any dimension in the POV expression.
Var
A variable that returns True if there is real data and False if there is no data or
derived data.
Example
The Prior and Next keywords can cross years but cannot distinguish
between interim years and first and last year.
In rules, you use the First, Last, Prior, and Next keywords to dynamically
select earlier and later periods and years. Year and Period are separate
dimensions. However, if the current period is the first period in a year, the
Prior function, used with the Period dimension, crosses to the last member of
the previous year. For example, if the current period is January, 1996, the
syntax P#Prior retrieves the value for December, 1995. Similarly, if the
current period is the last period in a year, the P#Next crosses to the next year.
The Prior and Next keywords, however, do not distinguish between interim
years and first and last years. Therefore, if a rule tries to retrieve data from a
year prior to the first year or after the last year, an error is returned. For
example, if the current year is the first year, the syntax Y#Prior returns an
error. Similarly, if the current year is the first year and the current period is
the first period, the syntax P#Prior returns an error.