x12 – search for segment

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf x12 – search for segment

  • Creator
    Topic
  • #48842
    Femina Jaffer
    Participant

      Hi All,

      I have an X12 file broken into segment format, and I need to find all CLP segments (e.g see below) and then identify the 1st field of each CLP segment (eg. 0-147L81771-4).  Can someone advise me on the best was to do this.

      E.g. of file format:

      ISA*00*          *00*          *27*00882          *ZZ*ER1559         *060929*141

      7*U*00401*627100040*0*P*>~

      GS*HP*00882*ER1559*20060929*141710*1509293*X*004010X091A1~

      ST*835*000000001~

      BPR*H*0*C*NON************20060928~

      TRN*1*304418615*1571062326~

      CAS*CO*18*11.55~

      REF*LU*81~

      CLP*0-147L81771-4*4*11.55*0**MB*2206270301940~

      NM1*QC*1*PACHECO*DICK*F***HN*A525589743~

      MOA***MA01~

      DTM*050*20060927~

      SVC*HC>36415*11.55*0****1~

      DTM*472*20050311~

      CAS*CO*18*11.55~

      REF*LU*81~

      CLP*Z147L81771-4*4*57.03*0**MB*2206270301950~

      Thank you.

      fj

    Viewing 3 reply threads
    • Author
      Replies
      • #59869
        garry r fisher
        Participant

          Hi,

          I can think of a number of ways – of the top of my head:

          Read the file into memory

          Split on ~ ( I assume this is the segment delimiter)

          Loop through the list checking the chars before the *

          If chars = CLP then split on *

          read list item 1

          Another method might to use the string first function and search for CLP and use variable to store the position of the CLP and process the CLP to extract the 1st field – then increment the counter and do another search first through the file incrementing the counter after each find.

          How’s that?

          I’m sure someone will post some simpler suggestion:-)

          Garry

        • #59870
          Charlie Bursell
          Participant

            No need to loop through the list.  Assuming your segments are in a list:

            If Tcl 8.3:

            foreach clp [lregexp $segments {^CLP}] {

                  set fld1 [lindex [split $clp *] 1]

            }

            If on Tcl 8.4 use the lsearch command to do the same

          • #59871
            Femina Jaffer
            Participant

              Thank you Garry and Charlie.  That did it!

              fj

            • #59872
              garry r fisher
              Participant

                Hi,

                I did say somebody would make a simpler suggestion:-)

                Thanks Charlie.

                Garry

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