TCL PROC for X12 transaction

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf TCL PROC for X12 transaction

  • Creator
    Topic
  • #47716
    Alise Blankenship
    Participant

      Hello All,

      I am trying to modify an existing TCL proc that manipulates an X12 transaction. I need the code to look at the CAS segments of the transaction. If there are two CAS segments back-to-back and the first segment has a *CO*42* in the first two fields, and the second CAS segment has an *OA* in the first field, I want to kill the first CAS segment (*CO*42*).  I am attaching the code fragment that deals with the CAS segment. Could someone look at it and see where the problem is? I can’t find it. The code is currently, checking for two CAS segments back-to-back and kills the first one without looking at the fields of either CAS segment.   😕

      Any help would be greatly appreciated. TIA.

      CAS      { if {$preSegInd == “CAS”} {

                            set splitSeg [split $seg *]

                            set Fld1 [string range $splitSeg 0 1]

                                 if {$Fld1 == “OA”} {

                                       set outMsg [lrange $outMsg 0 [expr [llength $outMsg] -2]]

                                       lappend outMsg $seg

                                 } else { lappend outMsg $seg

                           }

                      }

                 }

    Viewing 1 reply thread
    • Author
      Replies
      • #56524
        Anonymous
        Participant

          Hi Alise,

          The error could be in these lines:

          set splitSeg [split $seg *]

          set Fld1 [string range $splitSeg 0 1]

          The split is ok but you’re creating a list of fields where the first field is actually the segment ID or “CAS”.  So when you get the first two characters you get “CA” instead of what you expect.  

          Instead of using ‘string range’ use lindex and get the second element which should be the field that “CO” is in.

          So:

          set Fld1 [lindex $splitSeg 1]

        • #56525
          Alise Blankenship
          Participant

            That worked Greg. Thank you.

            Alise

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