1

I want to iterate over a list of objects in my rule and check some conditions on each object using if statement in the loop, is it possible?

Have tried the for loop, but it is not allowing to have if statement within it.

aryanRaj_kary
  • 503
  • 2
  • 7
  • 28

2 Answers2

1

Not only is it possible, it is very common. Just use a DEFINITIONS clause to bind a variable to each element in the list. The iteration is implied.

definitions
set <variable> to <definition> in <list> ;

Using a second SET statement and another list yields a nested loop. You can check conditions on the object either in an IF statement or by adding a WHERE clause to the SET statement.

Here is a link to one of the Knowledge Center pages: https://www.ibm.com/support/knowledgecenter/en/SSQP76_8.9.2/com.ibm.odm.itoa.ref/topics/ref_bal_set_var_to_def.html

By contrast, the FOR EACH loop is used in the action of the rule -- after all the conditions have been satisfied. There is nothing wrong with using it when appropriate, but its use is not that common.

1

define:

make 'varialbe' be any in collection ;

if

"condition"

then

something

else:

other

Sorry for the syntacs. I'm not using the english version of ODM, but i think you got the idea. It works both in tables and rules.

Alexander
  • 51
  • 8