help with argument driven table lookup

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library help with argument driven table lookup

  • Creator
    Topic
  • #51235
    Kevin Crist
    Participant

    I am trying to write a simple proc that we can use for table lookups by using arguments. I know that i can do this in an xlate but we have some feeds that dont require xlates and i dont want to make one just for  a table lookup. I was thinking of making the args, just an example{SEGMENT OBR} {FIELD 15} {TABLE specimanSource} , but i am getting a little lost on where to go. any help or ideas are appreciated.

    thanks.

    proc tpsSetTableValue { args } {

    #########################################################################################

    # Get the Connection/Proc Name for Error/Debug Messages

    #########################################################################################

    global HciConnName

    set myname “$HciConnName/[lindex [info level 1] 0]”

    set nowis [clock format [clock scan now] -format “%D – %T”]

    #########################################################################################

    # Initialize Variables Used

    #########################################################################################

    set dispList

  • ;# Disposition List Returned to Engine

    set fldSep “” ;# Field Seperator – get from MSH

    set subSep “” ;# SubField Seperator – get from MSH

    set repSep “” ;# Repeating Field Seperator – get from MSH

    set SegName “” ;# User Supplied Segment to Change

    set FieldNum 0 ;# User Supplied Field Num to Change

    set FieldVal “” ;# User Supplied Value to set in Field Num

     set TableName “” ;# User Supplied Table to use

    set segList

  • ;# Message Segments in List Form

    set SegPos

  • ;# List of Seg Pos in segList that match

    ;#  the User Supplied Segment Name

    #########################################################################################

    # Load in the arguments we need that were passed from the caller

    #########################################################################################

    keylget args MODE mode             ;# The mode the engine called from

    keylget args ARGS.SEGMENT SegName ;# Segment Name

    set SegName [string toupper $SegName] ;# Force to uppercase

    keylget args ARGS.FIELDNUM FieldNum ;# Field Number to Change

    # keylget args ARGS.FIELDVAL FieldVal ;# Value to Set Field To

    keylget args ARGS.TABLE TableName ;# Table to use

    #########################################################################################

    # Switch based on what mode the engine was in when it called the procedure

    #########################################################################################

     switch -exact — $mode {

       run {

        set mh [keylget args MSGID] ;# Get message handle from args

       set dispList

      ;# Initialize to good message

           set msg [msgget $mh] ;# Get a copy of the message

           set fldSep [string index $msg 3] ;# Field Seperator

           set subSep [string index $msg 4] ;# Sub-Field Seperator

           set repSep [string index $msg 5] ;# Repeating Field Seperator

      set segList [split $msg r] ;# Split message into segList

      #########################################################################################

      # Validate the user supplied values

      #########################################################################################

      if { $SegName == “” } {

       echo n n

       echo “==========================================================”

        echo “:WARN – No Segement Name Was Supplied !”

       echo “:WARN – Message Continued As Is.”

       echo “:WARN – Here Is: $myname”

       echo “:WARN – Now Is: $nowis”

       echo $msg

       echo “==========================================================”  

       echo n n

             return $dispList

      }

      if { $FieldNum == “” || $FieldNum == 0 } {

       echo n n

       echo “==========================================================”

        echo “:WARN – Invalid or No Field Number Was Supplied !”

        echo “:WARN – Field Number is: “$FieldNum””

       echo “:WARN – Message Continued As Is.”

       echo “:WARN – Here Is: $myname”

       echo “:WARN – Now Is: $nowis”

       echo $msg

       echo “==========================================================”  

       echo n n

             return $dispList

      }

      #########################################################################################

      # Find Position of Segement(s) – If missing -> Continue Message and Return

      #########################################################################################

      set SegPos [lsearch -all -regexp $segList “^$SegName”]

      if { [lindex $SegPos 0] < 0 } {  echo n n  echo “==========================================================”   echo “:WARN – Segment “$SegName” Is Missing !”  echo “:WARN – Message Continued As Is.”  echo “:WARN – Here Is: $myname”  echo “:WARN – Now Is: $nowis”  echo $msg  echo “==========================================================”    echo n n        return $dispList } ######################################################################################### # Take the value of the field and change it according to the table. ######################################################################################### foreach Seg $SegPos { set fldList [split [lindex $segList $Seg] $fldSep] set fldCnt [llength $fldList]    for { set flds $fldCnt } { $flds < [expr $FieldNum + 1] } { incr flds } { lappend fldList {}   }      set value [tbllookup $TableName $FieldVal]     lset fldList $FieldNum $FieldVal     lset segList $Seg [join $fldList $fldSep]     } ######################################################################################### # Recreate the message and store back at msg handle #########################################################################################  set msg [join $segList r]        msgset $mh $msg } start { }    time { }    shutdown { }    default {     echo “:WARN”     echo “:WARN ======================================”  echo “:WARN – tps called with invalid mode !” echo “:WARN – Mode Is: $mode” echo “:WARN – Here Is: $myname” echo “:WARN – Now Is: $nowis” echo “:WARN ======================================” echo “:WARN”    } } ;# End Switch return $dispList } ;# End Proc

Viewing 2 reply threads
  • Author
    Replies
    • #69306
      David Barr
      Participant

      Does it not work?  What errors are you seeing?

    • #69307
      Kevin Crist
      Participant

      My bad, if i would have proof read it i probably would have realized that. I am not getting any error. Its pulling the value out of the field but it’s not doing anythign with it. In the screen shot i added i circled where the new value should be. There was a number there but i am trying to replace it with a description. i have echoed the value and it comes back with nothing.

      Thanks.

    • #69308
      David Barr
      Participant

      Code:

       for { set flds $fldCnt } { $flds < [expr $FieldNum + 1] } { incr flds } {
      lappend fldList {}
       }

      I think the “expr” command is redundant.  Expr is implicitly called to evaluate the condition of a for loop.

      Code:


          set value [tbllookup $TableName $FieldVal]

       lset fldList $FieldNum $FieldVal

      Before this code, FieldVal should probably be set to [lindex $fldList $Fieldnum].  It appears to be uninitialized.

      Also, it looks like you’re putting the result of the lookup in a variable called “value”, but you aren’t doing anything with the result.  On the second line you should probably replace $FieldVal with $value.

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

Forums

Forum Statistics

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