Referencing a variable as a repetition counter in an Xlate

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Referencing a variable as a repetition counter in an Xlate

  • Creator
    Topic
  • #55302
    Patricia L McCarl
    Participant

      Hi,

      Working with some MFN^M16s that include repeating IVT segments.  The request is for me to add  an additional IVT segment to the end of the repeats (and there can be anywhere from 0 to dozens of repeats).  I’m able to create a counter in my iterate just fine, but I’m not sure how to tell the Xlate to use the counter number as the repeat number — is there any way to pass a variable value?  like 1(0).3(0).IVT(@next).#1(0)?

      Trish McCarl

      Piedmont Healthcare Corp

      Atlanta, GA

      Trish McCarl | Interface Developer | Piedmont Healthcare Corp
      2727 Paces Ferry Rd, Suite 1-1000 | Atlanta, GA 30339
      O: 470.271.4108 | M: 404.805.4103 | E: trish.mccarl@piedmont.org

    Viewing 5 reply threads
    • Author
      Replies
      • #84885
        Peter Heggie
        Participant

          The only way I know is to use the dollar sign method, where an iterate variable like %s1 can be updated by referring to it as $%s1.

          So if you are using %s1 for your iterate index, and then you create your own iterate variable %s2, you can use a COPY action with code, or a MATH action with an Add, and specify $%s2.

          Is that what you are looking for? I don’t know what Cloverleaf does to its variables when it is done iterating – does it zero out the value right away, and then you don’t get a chance to grab the highest value?

          I’d probably create a %s2 iterate variable and set it equal to 0, right before the iterate loop. At the end of the iterate loop (inside the iterate loop, maybe the last statement of the loop)  I would use a COPY action to copy $%s1 to $%s2.

          After the iterate is all done, the %s2 should be equal to the maximum number of segments, and then I would ADD $%s2 and =1 and set the output side to $%s2.

          Then I could use %s2 in COPY statements to put data in the new segment.

          1(0).3(0).IVT(%s2).#1(0)

          Peter Heggie
          PeterHeggie@crouse.org

        • #84886
          Patricia L McCarl
          Participant

            It does zero out the iterate values outside of the loop.  But maybe just some creativity on nesting iterates will get me what I want.

            Trish McCarl | Interface Developer | Piedmont Healthcare Corp
            2727 Paces Ferry Rd, Suite 1-1000 | Atlanta, GA 30339
            O: 470.271.4108 | M: 404.805.4103 | E: trish.mccarl@piedmont.org

          • #84887
            Peter Heggie
            Participant

              Its Monday, not sure how much creativity I have left.

              You could do all the usual COPY actions in the iterate loop from %s1 to %s1, and then before ending the loop, you would MATH ADD $%s1 and =1 into $%s2. And then use %s2 to add a few more COPY actions to build your new segment occurrence using the next index number in %s2. Then you hit the end of the loop.

              You would loop through all iterate occurrences. Each loop execution would copy the existing segment from the source to the target, and also build an additional new segment with %s1, but then the next loop would just overlay that %s2 segment you just created with the next original source segment. And over and over. Until you go to the last original segment, which gets copied to the target side, and again you create the new segment fields using %s2. But this time it does not get overlaid.

              It is very inefficient but you get it all done within the iterate loop.

              Or were you thinking of some other approach with nested loops?

              Peter Heggie
              PeterHeggie@crouse.org

            • #84888
              Bob Schmid
              Participant

                Loop mgmnt:

                …always a little clunky…for example….what if you want to leave the loop before the input list is exhausted ?…  “breaking out of loop”

                ….variable syntax and mgmnt a little tuff before it becomes intuitive

              • #84889
                Patricia L McCarl
                Participant

                  I got it figured out.  I did not know that I could just use a variable like I usually use in an iterate on the fly when I needed it, and just add $ in front if I needed to use the value to indicate a repetition in either the Source or Destination.  Works like a champ even on messages that had 0 IVT segs.  Thank you everyone for your help.

                  Trish McCarl | Interface Developer | Piedmont Healthcare Corp
                  2727 Paces Ferry Rd, Suite 1-1000 | Atlanta, GA 30339
                  O: 470.271.4108 | M: 404.805.4103 | E: trish.mccarl@piedmont.org

                • #84890
                  Peter Heggie
                  Participant

                    glad to help

                    Peter Heggie
                    PeterHeggie@crouse.org

                Viewing 5 reply threads
                • The forum ‘Cloverleaf’ is closed to new topics and replies.