Showing results for 
Search instead for 
Did you mean: 

What is the scope of implicit loop variables?

Former Member
0 Kudos


I'm facing some strange error from the ABSL editor (syntax checker).

In ABSL the loop variables are implicit and don't have to be declared in the head section of the script.

My question now is simple: How is the scope/visibility of such loop variables specified ?

There's a complete code snippet below.

In line no.9, there's the first time use of implicit loop variable 'task_inst'.

Because of type inference, it will be typed as MasterDataWanneBe/Tasks (which is my own BO type).

In line no.20, I want to use the same variable name in a different loop, outside the parenthesis/scope of the first first use.

Now the ABSL syntax checker complains about incompatible types (see code snippet)

Thus the type inference should result in the, (lets say 'local') type Project/Task, which is the one I was querying for.

To me it looks like, that loop variables implicitly get a global scope (hopefully bound to this ABSL file only).

I would like to see the scope/visibility of loop variables restricted to the parenthesis.

In other words only inside the loop.


I heard (from little sparrows), that local variable scoping is not possible because of underlying

generated ABAP code. If so, than it would be helpful to print warnings, in case of types are compatible

but used in different scopes. Think about the unintended side effects.


import ABSL;
import AP.ProjectManagement.Global;

var query_tasks;
var query_tasks_param;
var query_tasks_result;

foreach (empl_inst in this.Employees) {
	foreach (task_inst in empl_inst.Tasks) {
	    //   ^^^^^^^^^  first time use
// ===========================================================================

query_tasks = Project.Task.QueryByResponsibleEmployee;
query_tasks_param = query_tasks.CreateSelectionParams();
query_tasks_result = query_tasks.Execute(query_tasks_param);

foreach (task_inst in query_tasks_result) {
      // ^^^^^^^^^ Error: 4
      // The foreach loop variable is already inferred to an incompatible type:
      // Node(MasterDataWanneBe/Tasks). Expected Node(Project/Task)

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos


Former Member
0 Kudos

One little side note: I didn't found any documentation, clarifying variable scopes/visibility.

0 Kudos

Yes, variable declarations in ByD Scripting Language indeed have (snippet) global visibility. In the FP 3.0 release the variables can be declared anywhere in the snippet (not only in the beginning, as with FP 2.6), however still not within code blocks, i.e. within curly braces ({}). Therefore variable name shadowing is still not supported and because of the global visibility of variables they cannot be reused for a different type, later in the same snippet. This is because of the statically typed nature of ByD Script, despite the type inference convenience.

Kind regards,

Andreas Mueller