X12 and TCL

  • Creator
    Topic
  • #48470
    Femina Jaffer
    Participant

      Hello again.

      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

    Viewing 2 reply threads
    • Author
      Replies
      • #58709
        Jim Kosloskey
        Participant

          Femina,

          I am just curious – why are you not using Xlate?

          Jim Kosloskey

          email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

        • #58710
          Femina Jaffer
          Participant

            Hi Jim,

            The reason for not using an xlate is because this is a single FTP thread, which grabs a file, makes the changes and then puts the formated file back to a directory for the user.

            FJ

          • #58711
            Anonymous
            Participant

              Femina,

              If you’re willing to alter your technique for pulling segments out of a message this might help.

              There is a regular expressions for lists command that the Cloverleaf developers wrote back at the beginning.  Here’s how you could use it to get the CAS segments out of the message.

              set segmentList [split $msg $segmentSeparator]

              set casSegmentList [lregexp $segmentList ^CAS]

              This code snippet retrieves all the CAS segments in the entire message (get all list elements that begin with CAS).  Then you could use a foreach command to run your code to make your changes to the message and so on.

          Viewing 2 reply threads
          • The forum ‘Cloverleaf’ is closed to new topics and replies.