Comparison + assignment in Collection iterate expression?

Posted by Brian K. Maher on 26-Dec-2013 14:09

Hi Folks,

 

Is it possible to include both a comparison and assignment in the expression part of iterate or perhaps to do the assignment in the appropriate action column?

 

For example, collection->iterate(somedate < abc.transientdate then abc.transientdate = somedate)

 

Brian

All Replies

Posted by Kendall Sparks on 26-Dec-2013 15:54

Yes, that is possible.

The syntax would look similar to this:

c ->iterate ( integer1 = 7; if decimal5 = 15 then string1 = 'Fifteen' else string1 = 'Not Fifteen' endif )

In this case, integer1 would be set to 7 for all elements in the collection.  The attribute string1 would be set to 'Fifteen' only in the case where the attribute decimal1 = 15 and set to 'Not Fifteen' for any other value of decimal1.

Posted by Brian K. Maher on 26-Dec-2013 16:09

Ksparks,
 
Do you know how to reference a transient field that is at a higher level in the scope?  It is the transient field whose value I want to set based on a condition in the iterate?
 
Brian
 
[collapse]
From: ksparks [mailto:bounce-ksparks@community.progress.com]
Sent: Thursday, December 26, 2013 4:55 PM
To: TU.Corticon@community.progress.com
Subject: RE: [Technical Users - Corticon] Comparison + assignment in Collection iterate expression?
 

Yes, that is possible.

The syntax would look similar to this:

c ->iterate ( integer1 = 7; if decimal5 = 15 then string1 = 'Fifteen' else string1 = 'Not Fifteen' endif )

In this case, integer1 would be set to 7 for all elements in the collection.  The attribute string1 would be set to 'Fifteen' only in the case where the attribute decimal1 = 15 and set to 'Not Fifteen' for any other value of decimal1.

[/collapse]

Posted by mparish on 26-Dec-2013 17:51

I'm not sure its necessary to use the ->iterate operator. I've never found a situation where it was needed.

The natural behavior of a rule sheet is to automatically iterate over all the elements of any collection that is referred to using an alias. So you would simply put the somedate< abc.transientdate in a condition and put the abc.transientdate = somedate in the action and use the rule columns to link the condition to the action.

In fact when there are multiple aliases Corticon will iterate across all of them automatically, effectively generating the cross product.

And writing if then statements inside the iterate is effectively writing procedural code and defeats the purpose of using Corticon to ensure rule integrity.

So even though you can do it I suggest you avoid its use.

If you use the scope section of the rule sheet you can ensure that the correct context is used - this may not be possible if you use iterate.

Is there a particular reason why you want to use iterate rather than the natural form of the rule sheet?

Posted by Brian K. Maher on 26-Dec-2013 18:31

Mparish,
 
That worked.  I was over thinking the problem (and trying to use my “programmer” mind set).
 
Brian

This thread is closed