trying to put the ODS field into a new nte segment

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library trying to put the ODS field into a new nte segment

  • Creator
    Topic
  • #51006
    Steve Lambert
    Participant

    I am trying to put an ods field into a new nte segment and put both segs back in message. Is there anyway other than to concat the segment?

    if [cequal $segtype “ODS”] {

                       set fieldsList [split $segment $field_sep]  

                       set ods_4 [lindex $fieldsList 4]

                         

                   

                    set new_nte  [concat NTE::: $ods_4]

                         

             

                    set segment [concat $segment $new_nte]      

                       

                     msgset $mh $msg

             

                 }                  

                   

                    append outbuf ${segment}r

                       

               } ;# end of ‘foreach’

Viewing 2 reply threads
  • Author
    Replies
    • #68405
      Nate Kruse
      Participant

      I haven’t had to use a concat statement much in my couple of years of Tcl.

    • #68406
      Steve Lambert
      Participant

      Perfect,

      Thanks very much for your help Nate.

      Steve

    • #68407
      Russ Ross
      Participant

      Once you have determine the index of what you want to replace in your list of items then lreplace can be used as an alerternative approach to concatenation.

      I haven’t used lreplace to replace a single segment in my segList with a concatenation of 2 segments but seems like something like this would possibly work as an alternative.

      Code:

      set segList [lreplace $segList $myListIndex $myListIndex “$ODSsegrNTEseg”]

      Here is a tps proc  ( tps_msh_13_seq_num.tcl ) that I found that illustrates using the lreplace to replace the MSH-13 field and then uses a second lpreplace to replace the MSH segment.

      Code:

      # Begin Module Header ==========================================================
      #
      # —–
      # Name:
      # —–
      #
      # tps_msh_13_seq_num
      #
      # ——–
      # Purpose:
      # ——–
      #
      # Set the sequnce number in MSH-13
      #
      # ———–
      # Input Args:
      # ———–
      #
      # Args: tps keyedlist containing:
      #
      #       MODE    run mode (”start” or “run”)
      #       MSGID   message handle
      #       CONTEXT Should be sms_ib_data
      #
      #       ARGS    none
      #
      # ———–
      # Output Args:
      # ———–
      #
      # Returns: tps keyed list containing dispositions
      #
      #     OVER       message handle of ob reply msg
      #     CONTINUE   The received message if valid
      #     KILL       The received message if invalid
      #
      # ——
      # Notes:
      # ——
      #
      # UPoC type = TPS
      #
      # ——–
      # History:
      # ——–
      #
      # 2004.03.02 Russ Ross
      #          – implemented initial version.
      #
      #
      # 2004.03.08 Russ Ross
      #          – added logic to append empty fields if the MSH is shorter than 13 fields
      #
      # End Module Header ============================================================

      proc tps_msh_13_seq_num { args } {
        keylget args MODE mode

        global HciConnName
        set module “tps_msh_13_seq_num”

        switch -exact — $mode {

         # Check for counter file if it exists and value is 999999999 reinit.
         # If it dosen’t exist create counter file
         # This logic prevents the counter file to be reinitialized at thread startup

           start {
              if {[file exist .$module.$HciConnName.ctr]} {
                set ctr_value [CtrCurrentValue .$module.$HciConnName file]
                    if {[cequal $ctr_value 999999999]} {
                       CtrInitCounter .$module.$HciConnName file 1 999999999 1
                    }
              } else {
                 CtrInitCounter .$module.$HciConnName file 1 999999999 1
              }
              return “”
           }
           run {
                keylget args MSGID mh
                keylget args CONTEXT ctx
                set msg [msgget $mh]
               
                #—————————————————–
                # Verify proper context. If not sms_ob_data,do nothing.
                #—————————————————–

                if ![cequal $ctx sms_ob_data] {
                   echo “n($module/$HciConnName) ERROR!! called with Invalid context!”
                   echo “Should be sms_ob_data, is $ctx.”
                   echo “Continuing message, no action taken.nn”
                   return “{CONTINUE $mh}”
                }
             
                set fld_sep [csubstr $msg 3 1]             ;# Field Seperator
           
                #———————————————————-
                # Get the segments in the list. First segment is always MSH
                #———————————————————-

                set segments [split $msg “r”]
                set msh [lindex $segments 0]
                set seq_num [CtrNextValue “.$module.$HciConnName”]

                #——————————————
                # Insert sequence number in field-13 of MSH
                #——————————————

                set mshfld [split $msh $fld_sep]
                set n [llength $mshfld]
                for {set i $n} {$i<13} {incr i} {
                    lappend mshfld ""
                }
                set mshfld [lreplace $mshfld 12 12 $seq_num]
                set msh [join $mshfld $fld_sep]

                #————————–
                # Put message back together
                #————————–

                set segments [lreplace $segments 0 0 $msh]
                set msg [join $segments r]
                msgset $mh $msg
                return "{CONTINUE $mh}"
           }

      shutdown {
         # Doing some clean-up work
      }
           default {
                return ""
           }
        }
      }

      Russ Ross
      RussRoss318@gmail.com

Viewing 2 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