I am having a difficult time replacing certain occurences of fields in the CAS segment. For example, I need to replace all the occurences of OA*45 with CO*45.
My code will replace the first occurences of OA*45 within a CAS segment but not if there are multiple occurences of the OA field within the CAS segment.
eg. of the code:
CAS { if {$preSegInd == “CAS”} {
set oa_ind [lindex [split $seg *] 1]
set oa_val [lindex [split $seg *] 2]
# if the the first piece and second piece of the segment
# is “OA” and “45”
if {[cequal $oa_ind “OA”] && [cequal $oa_val “45”]} {
set oa_ind “CO”
set nseg [split $seg “*”]
set nseg [lreplace $nseg 1 1 $oa_ind]
set nseg [join $nseg *]
set seg $nseg
set newseg [lappend newseg $seg]
lappend outMsg $seg
} else { lappend outMsg $seg
}
} else { lappend outMsg $seg
}
}
Here is an example of the output data file I am getting with the above code:
~DTM*472*20060307~CAS*CO*45*89.69~AMT*B6*24.
14~LQ*HE*N14~SVC*HC:80061*38.08*0**1~DTM*472*20060307~CAS*CO*45*26.75~AMT*B6*11.
33~LQ*HE*N14~SVC*HC:83036*36.97*0**1~DTM*472*20060307~CAS*OA*45*28.02~CAS*PR*1*8
.95~AMT*B6*8.95~LQ*HE*N14~SVC*HC:84439*36.97*0**1~DTM*472*20060307~CAS*CO*45*28.
65~AMT*B6*8.32~LQ*HE*N14~SVC*HC:86140*28.92*0**1~DTM*472*20060307~CAS*OA*45*25.14~CAS*PR*1*3.78~AMT*B6*3.78
Any help or suggestions would be very much appreciated.
Thanks
FJ