Forum Replies Created
-
AuthorReplies
-
I was able to finally resolve this with a little tinkering, thanks!
Couple of take-aways from the above post:
-lines 9-11 : cleaned up the RXA segment locator. much better, I appreciate that.
lines 17-20 : cleaned up RXA-11.1 delimiter by nesting commands to split and index RXA. much better, also appreciated.
-lines 36-40 : this is where the switch comes in. Unfortunately, as I see it, the switch is required. Ultimately, the file that is written to will be decided by the value of RXA-11.1, but the filename will not always match that value. essentially, there’s 8 possible files. 7 of them are associated with 14 potential values (2x potential values to each file). The 8th file is a catch all, which should be written to if the value of RXA-11.1 is not one of the 14 aforementioned values. Because there’s so many potential values that could be received in that field, a switch statement seems most efficient for handling it.
So, I updated my code, and it now points to the right file path based on the value of RXA-11.1, but I’m having trouble with opening, writing to file, and then closing. I’m sure its a one-off that I’ve been missing, but I can’t seem to get the expected behavior *note, I haven’t made some of the cosmetic/clean-up changes to the code yet, I want to get the file write commands working before I go back to clean up:
run {
Thanks Charlie, apologies for the sparse details on the original post. So, I went with a switch statement to cover the logic since there were a handful of potential options. At this point I’m trying to create or append a newline terminated file, which is created if it doesn’t already exist. I’m thinking that the code for each scenario in the switch statement would first check to see if the file exists. If not, create it (newline, append). After the check/creation, open, write the message to the to file, and close. I’m just not sure how to actually code this. If you have any pointers, it’s much appreciated. Thanks!
###########################################
keylget args MSGID mh
set msg [msgget $mh]
set fieldSep [string index $msg 3]
set subSep [string index $msg 4]
set segList [split $msg r]
set segment [lsearch -inline -regexp $segList ^RXA]
set fieldList [split $segment $fieldSep]
set fieldList [lreplace $fieldList 6 6 1]
set segment [join $fieldList $fieldSep]
set position [lsearch -regexp $segList ^RXA]
set segList [lreplace $segList $position $position $segment]
set rxa_11 [lindex $fieldList 11]
set subFieldList [split $rxa_11 $subSep]
set rxa_11_1 [lindex $subFieldList 0]
set dest_Dir $HciSiteDir/dir/subdir/out
set msg [join $segList r]
msgset $mh $msg
switch -exact — $rxa_11_1 {
facility1 {
set fileId [open $dest_Dir/facility1 RDWR 0666]
}
facility1 {
set fileId [open $dest_Dir/facility1 RDWR 0666]
}
facility2 {
set fileId [open $dest_Dir/facility2 RDWR -0666]
}
facility2 {
set fileId [open $dest_Dir/facility2 RDWR 0666]
}
facility3 {
set fileId [open $dest_Dir/facility3 RDWR 0666]
}
facility3 {
set fileId [open $dest_Dir/facility3 RDWR 0666]
}
facility4 {
set fileId [open $dest_Dir/facility4 RDWR 0666]
}
facility4 {
set fileId [open $dest_Dir/facility4 RDWR 0666]
}
facility5 {
set fileId [open $dest_Dir/facility5 RDWR 0666]
}
facility5 {
set fileId [open $dest_Dir/facility5 RDWR 0666]
}
facility6 {
set fileId [open $dest_Dir/facility6 RDWR 0666]
}
facility6 {
set fileId [open $dest_Dir/facility6 RDWR 0666]
}
facility7 {
set fileId [open $dest_Dir/facility7 RDWR 0666]
}
facility7 {
set fileId [open $dest_Dir/facility7 RDWR 0666]
}
default {
set fileId [open $dest_Dir/DefaultFacility RDWR 0666]
}
}
echo $fileId
lappend dispList “CONTINUE $mh”
}
-
AuthorReplies