1 Reply Latest reply on May 6, 2019 3:22 AM by Danny Fleer

    TPL Table Error Checking

    James Yant
      Share:|

      I'm looking to implement some form of error checking when attempting to access values from a table. I have a pattern that extracts a substring from a hostname as a key and attempts to find the corresponding value that matches it in a table. I'm needing a way to catch the cases where a key doesn't exist in the table. Is this possible with TPL?

        • 1. Re: TPL Table Error Checking
          Danny Fleer

          Do you use static tables defined at the top of the module, or do you use dynamic tables created at runtime using table functions?

           

          For static tables you can define a default value that will be returned if the key you've requested doesn't exist. This could be none or false for example. Please see documentation Static Tables - BMC Discovery 11.3 - BMC Documentation.

          Assuming that the default value is none the code could be something like this:

          myValue := myTable[myKey];
          if myValue = none then
              log.debug("Unable to find key %myKey% in table");
          else
              log.debug("Key %myKey% has value %myValue%");
          end if;
          

           

          For dynamic tables you can use an if clause to check if the key exists:

          if 'myKey' in myTable then
             myValue := myTable[myKey];
             log.debug("Key %myKey% has value %myValue%");
          else
              log.debug("Unable to find key %myKey% in table");
          end if;
          
          3 of 3 people found this helpful