Within a loop, how can i count number of rows in each iteration and have a cumulative total?

Hi all,

I have a workflow that checks user access in SAP. To do this I have a loop that loops around a list of users roles and collects whether each roles provides access to a list of predefined tables.

Currently, I am downloading table access for all roles within a loop and then filtering on those which provide table access. However, I want to improve performance by exiting a loop once all of the required tables have been granted by a combination of the roles. (i.e. if the first 2 roles grant access to all 4 tables, there is no need to check whether the remaining 5 roles also provide access).

What I am trying to achieve is the following:

To run a workflow, a user requires access to 4 different tables.

Iteration 1 - Role 1 provides access to 3 of the required tables.

Cumulative total = 3

Iteration 2 - Role 2 provides no access to the required tables.

Cumulative total = 3

Iteration 3 - Role 4 provides access to 1 of the required tables.

Cumulative total = 4.

At this point, I want the loop to end because the required number of tables equals the cumulative total rows within the loop.

Please can anyone advise whether this is possible?

Thanks.

tp