- This topic has 7 replies, 2 voices, and was last updated 15 years, 2 months ago by .
-
Topic
-
Hi All, I have written tcl code to read an x12 file, which breaks each raw file read into separate files and adds the ISA header to each file it breaks. I now need to add the Trailer to each file. I am having a very difficult time to get this to work. However, I am able to extract the IEA hdr and store it in a variable.
The code is listed below…please advise.
keylget args MODE mode ;# Fetch mode
set dispList {} ;# Nothing to return
switch -exact — $mode {
start {
# Perform special init functions
# N.B.: there may or may not be a MSGID key in args
}
run {
# ‘run’ mode always has a MSGID; fetch and process it
keylget args MSGID mh
set msg [msgget $mh]
# set dir /hci/quovadx/qdx5.5/integrator/trlprod/FTP/EOB/STRIP/IN
set dir /hci/quovadx/qdx5.5/integrator/testdev_res/
set count 0
set segCount 0
set segID “”
set elSep [string index $msg 104]
set ISAHdr [string range $msg 0 [string first “${elSep}” $msg]]
set splitMsg [split $msg ~]
set IEAFtr [lregexp $splitMsg {^IEA}]
foreach seg $splitMsg {
if {$segCount > 0} {
set preSegInd $segID
}
set segID [string range $seg 0 2]
incr segCount +1
switch -exact $segID {
ISA {
lappend outMsg $seg }
GS* { if {$count > 0} {
set outFile [open $dir/PHP$outFileName.dat w]
set outMsg “[join $outMsg ~]~”
puts $outFile $outMsg
flush $outFile
set outMsg “”
lappend outMsg $ISAHdr
lappend outMsg $seg
incr count +1
} else {
lappend outMsg $seg
incr count +1
}
}
CAS { if {$segID == “CAS”} {
set oa_ind [lindex [split $seg *] 1]
set oa_val [lindex [split $seg *] 2]
if {[cequal $oa_ind “OA”] && [cequal $oa_val “45”]} {
regsub -all “OA” $seg “CO” nseg
set seg $nseg
lappend outMsg $seg
} else { lappend outMsg $seg
}
} else { lappend outMsg $seg
}
}
TRN { set outFileName [lindex [split $seg *] 2]
lappend outMsg $seg
}
default { lappend outMsg $seg
}
}
}
if {$count != -1} {
set outFile [open $dir/PHP$outFileName.dat w]
set outMsg [join $outMsg ~]
puts $outFile $outMsg
flush $outFile
}
lappend dispList “KILL $mh”
}
Thanks for any advise or feedback.
- The forum ‘Cloverleaf’ is closed to new topics and replies.