Help with writing UPOC using TCL

Clovertech Forums Cloverleaf Help with writing UPOC using TCL

Tagged: 

  • Creator
    Topic
  • #121616
    Rin
    Participant

      Hi,

      I am not good with tcl and need help to write a simple UPOC to do the following please:

      I receive various file names from a source once daily and I need to update the database only if the file type is SMS Daily , TCHEADER  or CVENDOR . The rest can be killed.

      The problem is, the contents of the file is received in a separate message that has no file names. The file names are in the message above but can be identified using certain format.

       

      We receive files in Cloverleaf with the following (This is what I see in SMART DB):

      This is what I see in the first line:

      (1) Anything that has “Interface is Complete” needs to be killed and move onto the next message in the SMART DB

      “2024-08-06 1640 Records Have been extracted as TCTERMS. Interface is Complete”

      *************************************************************************

      Then  I need to look for any of the 3 file types which has the following format in the first line of the incoming file:

      (2) SMS Daily – (tcl code to uniquely identify the files
      file where the unique identifier is a combination of 4 elements, SQDMFGVENDORNBR which is first 6 digits, followed by SQDDISTVENDORNBR next 6 digits withoutany spaces and SQDCONTRACTNBR next 6 gigits and SQD-ITEM-REF-NBR last 7 digits)

      SMS Daily Format -9383479383471176278274720AR-4205

      ******************************************************************************

      (3) TCHEADER – The first 6 digits is the vendor #

      KILL: First ” 2024-08-06 2042 Records Have been extracted as TCHEADER . Interface is Complete”

      9577491175222025-09-302018-10-022018-10-02NNot

      ******************************************************************

      (4) CVENDOR – The first 6 digits is the vendor #

      KILL: First ” 2024-08-06 2042 Records Have been extracted as CVENDOR. Interface is Complete”

      Format: 003938347000001UNIT 1, TESTTTT PARK SHEPCOTE LANE SHEFFIELD GB11 1 D11

      **********************************************************************

      This is what I started doing

      proc trxID_Cat360Files_US { mh } {

      set file_handle [open $filename r] ;# Get message

      echo “hello, these are files from 360Catalogue”

      # Read the first line
      set first_line [gets $file_handle]

      # Close the file
      close $file_handle

      # Extract the data elements using regular expressions
      regexp {(\d{6})(\d{6})(\d{6})(\d{7})} $first_line match sqd

      # Check if all elements were found

      if {$match} {
      # Construct the unique identifier
      set IMS_SMS_DAILY_unique_identifier [string concat $sqdmfgvendornbr $sqddistvendornbr $sqdcontractnbr $sqditemrefnbr]

      # Return the unique identifier
      return $unique_identifier
      echo IMS_SMS_DAILY = $IMS_SMS_DAILY_unique_identifier

      set filenames

      } else {
      # If no match was found, return an empty string
      return “”
      }

      set TRXID “trxID_Cat360Files_US”

      }

      I have added 3 attachments too of what I have done so far and the schema.

       

       

      • This topic was modified 2 months, 4 weeks ago by Rin.
      Attachments:
      You must be logged in to view attached files.
    Viewing 0 reply threads
    • Author
      Replies
      • #121621
        Jim Vilbrandt
        Participant

          Hi Rin,

          I would suggest using a directory parse TPS for this purpose. The “message” you receive in this script type is a list of files in the configured directory.

          Below you will find some pseudo code for this purpose.

          Best Regards, Jim
          <pre>
          # Get Input Path from NetConfig
          set conndata [netconfig get connection data $HciConnName]
          set ibdir [keylget conndata PROTOCOL.IBDIR]

          # List of files found
          set listing [msgget $mh]
          set newlist “”

          foreach entry $listing {
          # Check contents of each file
          set fileName [cconcat $ibdir “/” $entry]
          set fh [open $fileName]
          fconfigure $fh -translation binary
          set msg {}; set msg [read $fh]
          close $fh
          <add your logic here to determine which files should be processed>
          if {<keep>} {
          lappend newlist $entry
          } else {
          file delete [cconcat $ibdir “/” $entry]
          }
          }
          # Pass new list to engine
          msgset $mh $newlist
          lappend dispList “CONTINUE $mh”</pre>
           

          • #121624
            Rin
            Participant

              Thanks Jim.

              Now I need help with writing a TRIX_id tcl please using the commands keylget and keylset and USERDATA

              I want to extract 3 types files where the msgDriverControl /Protocol Driver may have either

              1. IMS_Daily or
              2. IMS_CVENDOR or
              3. IMS_TCHEADER
              4. All the others can be killed

              I have attached Metadata and Protocol Driver screenshots.

               

              ********************************

              Something like this

              proc IMSFiles { args } {
              global HciConnName
              keylget args MODE mode
              set ctx “” ; keylget args CONTEXT ctx
              set module “IMSFiles/$HciConnName/$ctx”
              set uargs {} ; keylget args ARGS uargs
              set debug 0
              catch {keylget uargs DEBUG debug}
              set dispList {}

              switch -exact — $mode {
              start {}

              run {

              set udata [msgmetaget $mh USERDATA]
              keylget args MSGID mh #Get Message
              echo “message is: |$msg|”
              set TRXID “”
              keylset udata IMS_Filename $msgDriverControlId
              msgmetaset $mh USERDATA $udata

              Attachments:
              You must be logged in to view attached files.
        Viewing 0 reply threads
        • You must be logged in to reply to this topic.