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.
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.
# 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