This is the first of a new series of technical tips. Today we are talking about how, in code (Java and Autoscript), the best way to process an MboSet. There are lots of ways to process them but some are better than other. (All code is shown in Java but can easily converted to Jython.)
Let’s look at this sample code. This is pretty standard/common way to process a MboSet:
Now this code will happily process the Asset table but it turns out this code is the slowest way to do it. The reason is the use of mboSet.count(). When you execute this, Maximo basically runs the SQL statement: SELECT COUNT(*) FROM ASSET. This happens every time the line of code is executed. So if there are 100,000 records in the ASSET table, then this code runs SELECT COUNT(*) FROM ASSET 100,000 times. If you have 500,000 records in ASSET then, it would have to be executed 500,000 times. You can see where this is not the fastest approach. A better approach would be to use a variable and execute the mboSet.count() just once. That could would look like this:
This is much better as no matter how many records there are in the ASSET table, we only execute the mboSet.count() once. However, it turns out that we don’t even need the mboSet.count() (and its SELECT COUNT(*) FROM ASSET). If your goal is it just process the records in the MboSet, then this is the best approach:
Here we have not only eliminated the MboSet.count(), but also the extra variables we used to process the MboSet.
Here is what the best code looks like in Jython:
Cheers and happy coding.
Let’s look at this sample code. This is pretty standard/common way to process a MboSet:
Now this code will happily process the Asset table but it turns out this code is the slowest way to do it. The reason is the use of mboSet.count(). When you execute this, Maximo basically runs the SQL statement: SELECT COUNT(*) FROM ASSET. This happens every time the line of code is executed. So if there are 100,000 records in the ASSET table, then this code runs SELECT COUNT(*) FROM ASSET 100,000 times. If you have 500,000 records in ASSET then, it would have to be executed 500,000 times. You can see where this is not the fastest approach. A better approach would be to use a variable and execute the mboSet.count() just once. That could would look like this:
This is much better as no matter how many records there are in the ASSET table, we only execute the mboSet.count() once. However, it turns out that we don’t even need the mboSet.count() (and its SELECT COUNT(*) FROM ASSET). If your goal is it just process the records in the MboSet, then this is the best approach:
Here we have not only eliminated the MboSet.count(), but also the extra variables we used to process the MboSet.
Here is what the best code looks like in Jython:
Cheers and happy coding.
No comments:
Post a Comment