removing a segment

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf removing a segment

  • Creator
    Topic
  • #50459
    Kevin Crist
    Participant

      is there a quick way to remove a segment with a tcl. i have seen a few of the posts here, but not sure that is exactly what i am looking for. just a basic: if the message has this segment, then remove it and continue.

    Viewing 9 reply threads
    • Author
      Replies
      • #66172
        Nate Kruse
        Participant

          I typed this out quickly, so not sure if the syntax is correct.  Basically, get the incoming message.  Go through each segment.  If the segment is one that you want, append that segment to a variable.  If the segment is one that you don’t want, don’t append that segment (skipping it).  Then set your outgoing message to that variable.

          keylget args MSGID mh               ;# Get message handle

          set msg [msgget $mh]                ;# Get message

          set segments [split $msg r]       ;# Get segments

          set OutBoundMsg “”

          foreach seg $segments {

              if [cequal $seg “”] { continue }    ;# Just in case

                   set segtype [csubstr $seg 0 3]      ;# segment name

                   

           if {[cequal $segtype MSH]} {

            #Use this segment

            append OutBoundMsg $seg

           }

           if {[cequal $segtype PID]} {

            #Use this segment

            append OutBoundMsg $seg

           }  

           if {[cequal $segtype NTE]} {

            #do not send this segment, so do not append to OutBoundMsg

           }

              } ;#end if

          }

          msgset $mh $OutBoundMsg

                       

          return “{CONTINUE $mh}”

        • #66173
          Tom Rioux
          Participant

            Here is one quick way:

            Split the message:

          • #66174
            Tom Rioux
            Participant

              One little addition….if the segment you want is a repeating segment and you want to remove all of the repeating segments, try this instead:

              Find the index of the segment you want to delete (in this case the variable $rseg).

            • #66175
              Michael Hertel
              Participant

                Look at one of my posts at:

                https://usspvlclovertch2.infor.com/viewtopic.php?p=7420#7420

                There is a tcl proc file that can help you.

              • #66176
                Kevin Crist
                Participant

                  thank you all for your quick help. my tcl is limited and things seem to crop up that needs to be done last minute.

                • #66177
                  Matt Estrella
                  Participant

                    Quick question – Would it be possible to create a condition to only remove the segment if the contents of the segment are empty?

                  • #66178

                    Definitely. Lots of ways to do it. What does your empty segment look like? Maybe something like “PV1||”? You could check to see if a particular field is null, like the first field, or you can compare strings, etc.

                    -- Max Drown (Infor)

                  • #66179
                    Matt Estrella
                    Participant

                      Here is an example:

                      NTE|4||

                      The ‘4’ could be any number, which may get tricky. I want to be able to only removed the blank NTE’s as shown above and allow the NTE’s with data to continue.

                    • #66180

                      Matt Estrella wrote:

                      Here is an example:

                      NTE|4||

                      The ‘4’ could be any number, which may get tricky. I want to be able to only removed the blank NTE’s as shown above and allow the NTE’s with data to continue.

                      Here is one way it could be done.

                      if {[regsub {^NTE|d*?||} $seg]} {

                      -- Max Drown (Infor)

                    • #66181
                      Matt Estrella
                      Participant

                        I tried this with removing blank NTE’s and it seems to work:

                        regsub -all — {NTE|d*?||r+} $msg {} msg

                        Thanks for the input !

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