Looping in a DTL

113 views
Skip to first unread message

Jim Dolson

unread,
May 7, 2014, 11:37:18 AM5/7/14
to Ensemble-in...@googlegroups.com

Is there any way to loop a certain number of times in a DTL?

Life would be good if I could execute a section of code ten times but the only looping that I can see is the foreach which only applies to repeating groups, segments, and fields.

I could simply paste that code in ten times in a row but that's embarrassing. Basically I'm looking for the old BASIC For/Next looping structure.

Thanks,

Jim

Andy Picou

unread,
May 7, 2014, 11:46:10 AM5/7/14
to Ensemble-in...@googlegroups.com
You can create a code block:

<code>
<![CDATA[
set tCount = 0
DO {SET tCount = tCount+1 write !,tCount} WHILE tCount <
10
]]>
</code>
--
You received this message because you are subscribed to the Google
Groups "InterSystems: Ensemble in Healthcare Community" group.
To post to this group, send email to
Ensemble-in...@googlegroups.com
To unsubscribe from this group, send email to
Ensemble-in-Healt...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/Ensemble-in-Healthcare?hl=en
---
You received this message because you are subscribed to the Google
Groups "InterSystems: Ensemble in Healthcare" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to Ensemble-in-Healt...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Graham, Ben

unread,
May 7, 2014, 11:51:42 AM5/7/14
to Ensemble-in...@googlegroups.com
Not as obvious, but this will work as well...

<code>
<![CDATA[
//* start of For tCount loop
For tCount=1:1:10 {
]]>
</code>
<assign...
<if...

<code>
<![CDATA[

}
//* end of For tCount loop
________________________________



This electronic transmission and any documents accompanying this electronic transmission may contain information that is confidential and/or legally privileged. The information is intended only for the use of the individual or entity named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on or regarding the contents of this electronically transmitted information is strictly prohibited. If you have received this e-mail in error, please notify the sender and delete this message immediately.

Jim Dolson

unread,
May 7, 2014, 2:16:29 PM5/7/14
to Ensemble-in...@googlegroups.com
Thanks Ben (and Andy). That works great! I'm somewhat astonished that you can break up the loop like that - it shows great foresight on the part of the InterSystrms' programmers.

Thanks again. I owe you a beer.

Jim

Lawrence

unread,
May 7, 2014, 4:43:43 PM5/7/14
to Ensemble-in...@googlegroups.com

Actually I wish they had left the XML out and just used something 'syntax' for accessing the virtual document more cleanly and allowing normal Cache Object Script to be used to write the DTL's  The difficulty in adding comments or even at times seeing what the code is doing irks me.  I would prefer something similar to embeded SQL in Studio, maybe &vdoc<> instead of &sql<>?

    // <assign property='target.{2000A(i2000A).HL!3=20-10:HierarchicalIDNumber}' value='iHL1' action='set'/>
    // Set tSC1=target.SetValueAt(iHL1,"2000A("_(i2000A)_").HL!3=20-10:HierarchicalIDNumber","set","")
    // Set &vdoc<"target.{2000A().i2000AHL!3=20-10:HierarchicalIDNumber}",i2000A,sc>

    Set tValue=&vdoc<"vdoc-reference-S1",sc> If $$$ISERR(sc) ...
    Set tValue=&vdoc<"vdoc-reference-S1",sc> If $$$ISERR(sc) ...
    Set tResult=##class(someclass).somemethod(tValueA,tValueB,.sc) If $$$ISERR(sc) ...
    Set &vdoc<"vdoc-reference-D1",sc>=tResult If $$$ISERR(sc) ...

In any event to stop blue skying, I have resorted at times to something like:

<assign property='tValueA' value='vdoc-reference-S1' action='set'/>
<assign property='tValueB' value='vdoc-reference-S2' action='set'/>
<assign property='tResult' value='##class(someclass).somemethod(tValueA,tValueB)' action='set'/>
<assign property='vdoc-reference-D1' value='tResult' action='set'/>
   :
The XML in the DTL is used to do the VDoc get's and sets' but the meat of the action is in the class.  This allows for good class documentation, good comments in the code and some isolation of functionality from the simple movement of data form the source to destination documents.

VDoc are accessed very much like using $Property and $Method calls in COS but using methods on the source and target objects.  You can use the 'View other code' to see the output of the DTL 'compiler' which is just basic COS. 

For example:

<assign property='target.{2000A(i2000A).PRV-11:RefId}' value='tTaxonomy' action='set'/>

compiles out to

Set tSC1=target.SetValueAt(tTaxonomy,"2000A("_(i2000A)_").PRV-11:RefId","set","")


Lawrence Harris
> To unsubscribe from this group, send email to Ensemble-in-Healthcare-unsub...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/Ensemble-in-Healthcare?hl=en
> ---
> You received this message because you are subscribed to the Google Groups "InterSystems:  Ensemble in Healthcare" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to Ensemble-in-Healthcare+unsub...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups "InterSystems: Ensemble in Healthcare Community" group.
> To post to this group, send email to Ensemble-in...@googlegroups.com
> To unsubscribe from this group, send email to Ensemble-in-Healthcare-unsub...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/Ensemble-in-Healthcare?hl=en
> ---
> You received this message because you are subscribed to the Google Groups "InterSystems:  Ensemble in Healthcare" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to Ensemble-in-Healthcare+unsub...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
> ________________________________
>
>
>
> This electronic transmission and any documents accompanying this electronic transmission may contain information that is confidential and/or legally privileged. The information is intended only for the use of the individual or entity named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on or regarding the contents of this electronically transmitted information is strictly prohibited. If you have received this e-mail in error, please notify the sender and delete this message immediately.
>
> --
> You received this message because you are subscribed to the Google Groups "InterSystems: Ensemble in Healthcare Community" group.
> To post to this group, send email to Ensemble-in...@googlegroups.com
> To unsubscribe from this group, send email to Ensemble-in-Healthcare-unsub...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/Ensemble-in-Healthcare?hl=en
> ---
> You received this message because you are subscribed to the Google Groups "InterSystems:  Ensemble in Healthcare" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to Ensemble-in-Healthcare+unsub...@googlegroups.com.

Adam Lees

unread,
May 8, 2014, 8:05:21 AM5/8/14
to Ensemble-in...@googlegroups.com
You can do pretty much just that: develop transforms entirely in COS, using GetValueAt() and SetValueAt() methods of VDoc enabled message classes, passing in the VDoc path as a parameter.  All this stuff compiles down to COS anyway... then Mumps (sorry, lower-level COS without classes!)... then executable intermediate code... then C... and so on down to machine language!
Reply all
Reply to author
Forward
0 new messages