Iterating a subfield

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library Iterating a subfield

  • Creator
    Topic
  • #51226
    Randall Constant
    Participant

    Hey guys,

    I’m a Tcl amateur and I’m not real sure about how to iterate a subfield within a proc. I’m adding some leading zeros to a field but just today realized that one of our facilities is sending multiple consulting docs. However, only the first instance is getting the leading zeros.

                 # Consulting Doc

                       set pv1_9 [lindex $fields 9]

                       set pv1_9_list [split [lindex $fields 9] $sub_sep]

                       set DocNumber_9_0 [lindex $pv1_9_list 0]

                       if {$DocNumber_9_0 != “”} {

                          set nDocNum [x_prepenZeros 5 $DocNumber_9_0]

                          set replaceDocNum “”

                          append replaceDocNum $hmsId $nDocNum

                          set pv1_9 [join [lreplace $pv1_9_list 0 0 $replaceDocNum] $sub_sep]

                          set fields [lreplace $fields 9 9 $pv1_9]

                       }

Viewing 1 reply thread
  • Author
    Replies
    • #69274
      David Barr
      Participant

      Code:

      # Consulting Doc
      set pv1_9 [lindex $fields 9]
      set pv1_9_list [split [lindex $fields 9] $sub_sep]
      for { set i 0 } { $i < [llength $pv1_9_list] } { incr i } {
       set DocNumber_9_0 [lindex $pv1_9_list $i]
       if {$DocNumber_9_0 ne ""} {
         set nDocNum [x_prepenZeros 5 $DocNumber_9_0]
         set replaceDocNum ""
         append replaceDocNum $hmsId $nDocNum
         set pv1_9_list [lreplace $pv1_9_list $i $i $replaceDocNum]
       }
      }
      set pv1_9 [join $pv1_9_list $sub_sep]
      set fields [lreplace $fields 9 9 $pv1_9]

    • #69275
      Jim Kosloskey
      Participant

      If you are using an Xlate, this can be done inside the Xlate without Tcl I think.

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

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

Forum Statistics

Registered Users
5,126
Forums
28
Topics
9,296
Replies
34,439
Topic Tags
287
Empty Topic Tags
10