Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

What is the scope of implicit loop variables?


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)

Not what you were looking for? View more on this topic or Ask a question