- This topic has 5 replies, 3 voices, and was last updated 17 years, 9 months ago by .
-
Topic
-
😯 I have order messages that have repeating ORC segment groups. Some of the groups are not valid and must be deleted because of the order code in OBR.4. I need to iterate through the message segments and create the groups . I am using the following tcl code to create them:set pat “OBR.*?OBR”
set OBRlist [regexp -all -inline — $pat $msg].
As I create the groups I will evaluate and create a goodgroup list which I will use to put the message back together. I have been to iterate through the segements (foreach segment $msgseglist {) and create the first group but cannot create any additional groups. For example:
OBR1 bad
NTE1
NTE1
ORC2
OBR2 good
NTE2
NTE2
ORC3 bad
OBR3
NTE3
I need to eliminate the bad segment and the other segments in its group and keep the good group and then put the message back together. Here is the code I have right now (its pretty crude):
foreach segment $msgseglist {
echo “segment = $segment”
if {([crange $segment 0 2] == “OBR”)} {
set pat “OBR.*?OBR”
set OBRlist [regexp -all -inline — $pat $msg]
echo “OBRlist=$OBRlist”
set OBRfieldlist [split $OBRlist |]
set codefld [lindex $OBRfieldlist 4]
set codelist [split $codefld ^]
set code [lindex $codelist 0]
echo “code = $code”
set 1stNum [string range $code 0 0]
echo “1stNum = $1stNum”
if {$1stNum == 7} {
set killgroup [lappend killgroup $OBRlist]
echo “killgroup = $killgroup”
} else {
set goodgroup [lappend goodgroup $OBRlist]
echo “goodgroup = $goodgroup”
}
set pat “OBR.*?OBR”
set OBRlist [regexp -all -inline — $pat $msg]
echo “OBRlist=$OBRlist”
set goodgroup [lappend goodgroup $OBRlist]
echo “goodgroup = $goodgroup”
}
set segcounter1 [incr segcounter1]
}
Any ideas how I can make this work?
Thank you
- The forum ‘Tcl Library’ is closed to new topics and replies.