cancel
Showing results for 
Search instead for 
Did you mean: 

BRF+ Scope withing loop

Former Member
0 Kudos

I have a rule that executes a loop expression. The loop parses a table and for each row passes the row structure to a second rule. (The table has been declared to be in scope for the ruleset.)

Within the second rule I see the scope of available objects is restricted to the contents of the row sturcture, which is exactly what I would expect.

Now in the second rule I have written a formual expression. Inside the formula I see I have available table functions that allow me to know how many orws in the table. Can I trust these functions? It seems odd that the formula expression seems to have access to a broader range of data objects than its container rule. I am nervous that the Table_Row_Count() might only ever return a 1 because it can obly see the passed row.

Thanks in advance

Cliff

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Cliff

I can't give you a definitive answer but I can share my own observations and past experience...

I recall creating a rule in the past where the function had two context components - let's call them CC1 and CC2. In my ruleset I had a rule that used a decision table: CC1 was one of the condition columns and the result column was just a builtin type like a numeric (or something). In the result cell of one of the decision table rows I embedded a formula (similar to your scenario) and in that formula I used CC2 to help calculate the result. The Workbench syntax check did not complain that CC2 was not referred to anywhere in the decision table (so should not be available to the formula) and when I tested the function it all worked well. It was then I realised that BRF+ expressions don't really have their own "scope" like an ABAP subroutine does.

My conclusion was that any expression that is used within the ruleset will have access to any of the components in the function context and any variables in the ruleset context... assuming that the expression is able to use that type of object. (ie. a formula can't directly process a table object - that doesn't make sense - but a table function embedded in that formula can)

It probably helps to avoid thinking of data being "passed to" an expression, rather that the expression accesses the data from the context available to it.

So my best (semi-educated) guess is that your embedded table function is working exactly how you want it to. Testing should confirm this for you though...

Hope this helps

Glen

Former Member
0 Kudos

Thanks again. Next time I'm in Sydney I'll buy you a beer.

Former Member
0 Kudos

No worries.

I didn't realise you were a fellow Aussie until I just googled you... 🙂

Answers (1)

Answers (1)

carsten_ziegler
Active Contributor
0 Kudos

Glen is right. Each expression has its execution context. This context consists of Function Context, Function Result and optional Ruleset Variables. Each expression can use any of the context fields. However, not all expressions can make use of all types of context objects. Expressions can be reused when used context is availbale at all places of reuse.

In your specific case consider usage of a table operation expression. This expression type allows you to do checks and manipulations on tabular data.