removing segments — question

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library removing segments — question

  • Creator
    Topic
  • #51243
    Josh Fishel
    Participant

    Hi again,

    I need to loop through all of the AL1 segments and grab the AL1-3 field, then concat them into one AL1-3 field in a new AL1 segment (which i have done).

    The part that i cannot seem to figure out is how to remove the other AL1 segments.  I only need the one AL1 segment that I created, and need to remove the others.  Is this possible?  If so, how?

    Thank you,

    Josh

Viewing 7 reply threads
  • Author
    Replies
    • #69324
      Troy Morton
      Participant

      Hi Joel,

      There are two ways that I have done this.

      1) Write a Tcl Procedure that runs post-Xlate which will remove the unwanted segments from the messages.

      2) In your Xlate, do not BULKCOPY, PATHCOPY or COPY any data to the iterations of the AL1 segment that you do not want to appear in the outbound message.

      When Cloverleaf creates the outbound message in Xlate, it starts out completely empty.  Only things that you COPY from the input to the output will appear in the outbound message.

      Make sense?

    • #69325
      Josh Fishel
      Participant

      I would like to use Tcl because I have to do this for several ADT messages of different types, so the XLATE would be out (from what i can tell).  

      So i guess what i’m really asking is, what would be the syntax to do something like this?

    • #69326
      Tom Rioux
      Participant

      Joel,

      Here is one way to do it in Tcl.  I’m sure there are cleaner and more slick ways to do it though:

      Set your new AL1 segment to some variable:  newAL1

      Create an index of your old AL1 segments that you want to remove and set it to a variable:

        set oldAL1 [lsearch -regexp -all $msg ^AL1]

      Now remove those segments from the msg variable:

       set msg [lreplace $msg [lindex $oldAL1 0] [lindex $oldAL1 end] ]

      Then just add your new AL1 segment in its place:

        set msg [linsert $msg [lindex $oldAL1 0] $newAL1]

      Hope this helps…Tom

    • #69327
      Troy Morton
      Participant

      This procedure parses the message and puts it back together only including the 1st AL1 segment, discarding all the other AL1 segments.


      proc rm_al1 { msg } {

      [code]
      proc rm_al1 { msg } {

    • #69328
      Charlie Bursell
      Participant

      You know how I hate to loop  ðŸ˜†

      # Get a list of *ALL* AL1 locations

      set LOCS [lsearch -all -regexp $SEGMENTS {^AL1}]

      # Pop off the first one so you keep it

      lvarpop LOCS

      # Traverse the list backward to maintain location in list

      foreach loc [lsprt -decreasing -integer $LOCS] {lvarpop SEGMENTS $loc}

      There you have it.  Just join the segments back together and do the msgset.  Three lines  of code  ðŸ˜‰

    • #69329
      Troy Morton
      Participant

      I admittedly am not good with regexp and so I end up coding things in loops.

      Thanks for this code snipit, Charlie.  I’m gonna file this in my Tcl bible.   😆

    • #69330
      Charlie Bursell
      Participant

      I hope you noticed that lsprt  should be lsort

      Fingers are fasterthan the brain  ðŸ˜‰

    • #69331
      Josh Fishel
      Participant

      Got it!  Thanks for all your help!!

      and yes i did notice the lsort 🙂

Viewing 7 reply threads
  • The forum ‘Tcl Library’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,129
Forums
28
Topics
9,301
Replies
34,447
Topic Tags
288
Empty Topic Tags
10